Skip to content

Commit

Permalink
fix readme in recording
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcturusZhang committed Jul 6, 2021
1 parent 958d3c3 commit d91547b
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions sdk/internal/recording/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ or indicate that the test IsFailed.

```go
type testState struct {
recording *testframework.Recording
recording *recording.Recording
client *TableServiceClient
context *testframework.TestContext
context *recording.TestContext
}
// a map to store our created test contexts
var clientsMap map[string]*testState = make(map[string]*testState)

// recordedTestSetup is called before each test execution by the test suite's BeforeTest method
func recordedTestSetup(t *testing.T, testName string, mode testframework.RecordMode) {
func recordedTestSetup(t *testing.T, testName string, mode recording.RecordMode) {
var accountName string
var suffix string
var cred *SharedKeyCredential
Expand All @@ -39,19 +39,19 @@ func recordedTestSetup(t *testing.T, testName string, mode testframework.RecordM
assert := assert.New(t)

// init the test framework
context := testframework.NewTestContext(func(msg string) { assert.FailNow(msg) }, func(msg string) { t.Log(msg) }, func() string { return testName })
//mode should be testframework.Playback. This will automatically record if no test recording is available and playback if it is.
recording, err := testframework.NewRecording(context, mode)
context := recording.NewTestContext(func(msg string) { assert.FailNow(msg) }, func(msg string) { t.Log(msg) }, func() string { return testName })
//mode should be recording.Playback. This will automatically record if no test recording is available and playback if it is.
recording, err := recording.NewRecording(context, mode)
assert.Nil(err)
```
After creating the TestContext, it must be passed to a new instance of `Recording` along with the current test mode.
`Recording` is the main component of the testframework package.
```go
//func recordedTestSetup(t *testing.T, testName string, mode testframework.RecordMode) {
//func recordedTestSetup(t *testing.T, testName string, mode recording.RecordMode) {
// <...>
recording, err := testframework.NewRecording(context, mode)
recording, err := recording.NewRecording(context, mode)
assert.Nil(err)
```
Expand All @@ -64,11 +64,11 @@ In the snippet below we are calling `GetRecordedVariable` to acquire details suc
client secret to configure the client.
```go
//func recordedTestSetup(t *testing.T, testName string, mode testframework.RecordMode) {
//func recordedTestSetup(t *testing.T, testName string, mode recording.RecordMode) {
// <...>
accountName, err := recording.GetRecordedVariable(storageAccountNameEnvVar, testframework.Default)
suffix := recording.GetOptionalRecordedVariable(storageEndpointSuffixEnvVar, DefaultStorageSuffix, testframework.Default)
secret, err := recording.GetRecordedVariable(storageAccountKeyEnvVar, testframework.Secret_Base64String)
accountName, err := recording.GetEnvVar(storageAccountNameEnvVar, recording.Default)
suffix := recording.GetOptionalEnvVar(storageEndpointSuffixEnvVar, DefaultStorageSuffix, recording.Default)
secret, err := recording.GetEnvVar(storageAccountKeyEnvVar, recording.Secret_Base64String)
cred, _ := NewSharedKeyCredential(accountName, secret)
uri := storageURI(accountName, suffix)
```
Expand All @@ -77,7 +77,7 @@ The last step is to instrument your client by replacing its transport with your
`Recording` satisfies the `azcore.Transport` interface.
```go
//func recordedTestSetup(t *testing.T, testName string, mode testframework.RecordMode) {
//func recordedTestSetup(t *testing.T, testName string, mode recording.RecordMode) {
// <...>
// Set our client's HTTPClient to our recording instance.
// Optionally, we can also configure MaxRetries to -1 to avoid the default retry behavior.
Expand Down Expand Up @@ -132,12 +132,12 @@ import (

type tableServiceClientLiveTests struct {
suite.Suite
mode testframework.RecordMode
mode recording.RecordMode
}

// Hookup to the testing framework
func TestServiceClient_Storage(t *testing.T) {
storage := tableServiceClientLiveTests{mode: testframework.Playback /* change to Record to re-record tests */}
storage := tableServiceClientLiveTests{mode: recording.Playback /* change to Record to re-record tests */}
suite.Run(t, &storage)
}

Expand Down

0 comments on commit d91547b

Please sign in to comment.