Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions sdk/data/aztables/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ var pathToPackage = "sdk/data/aztables"

type recordingPolicy struct {
options recording.RecordingOptions
t *testing.T
}

func NewRecordingPolicy(o *recording.RecordingOptions) policy.Policy {
func NewRecordingPolicy(t *testing.T, o *recording.RecordingOptions) policy.Policy {
if o == nil {
o = &recording.RecordingOptions{}
}
p := &recordingPolicy{options: *o}
p := &recordingPolicy{options: *o, t: t}
p.options.Init()
return p
}
Expand All @@ -42,7 +43,7 @@ func (p *recordingPolicy) Do(req *policy.Request) (resp *http.Response, err erro

req.Raw().Header.Set(recording.UpstreamUriHeader, fmt.Sprintf("%v://%v", p.options.Scheme, originalURLHost))
req.Raw().Header.Set(recording.ModeHeader, recording.GetRecordMode())
req.Raw().Header.Set(recording.IdHeader, recording.GetRecordingId())
req.Raw().Header.Set(recording.IdHeader, recording.GetRecordingId(p.t))

return req.Next()
}
Expand Down Expand Up @@ -78,8 +79,8 @@ func (f *FakeCredential) NewAuthenticationPolicy(options runtime.AuthenticationO
}

func createClientForRecording(t *testing.T, tableName string, serviceURL string, cred azcore.Credential) (*Client, error) {
p := NewRecordingPolicy(&recording.RecordingOptions{UseHTTPS: true})
client, err := recording.GetHTTPClient()
p := NewRecordingPolicy(t, &recording.RecordingOptions{UseHTTPS: true})
client, err := recording.GetHTTPClient(t)
require.NoError(t, err)

options := &ClientOptions{
Expand All @@ -95,8 +96,8 @@ func createClientForRecording(t *testing.T, tableName string, serviceURL string,
}

func createServiceClientForRecording(t *testing.T, serviceURL string, cred azcore.Credential) (*ServiceClient, error) {
p := NewRecordingPolicy(&recording.RecordingOptions{UseHTTPS: true})
client, err := recording.GetHTTPClient()
p := NewRecordingPolicy(t, &recording.RecordingOptions{UseHTTPS: true})
client, err := recording.GetHTTPClient(t)
require.NoError(t, err)

options := &ClientOptions{
Expand Down Expand Up @@ -154,7 +155,7 @@ func initServiceTest(t *testing.T, service string) (*ServiceClient, func()) {
}

func getAADCredential(t *testing.T) (azcore.Credential, error) { //nolint
if recording.InPlayback() {
if recording.GetRecordMode() == "playback" {
return NewFakeCredential("fakestorageaccount", "fakeAccountKey"), nil
}

Expand All @@ -167,7 +168,7 @@ func getAADCredential(t *testing.T) (azcore.Credential, error) { //nolint
}

func getSharedKeyCredential(t *testing.T) (azcore.Credential, error) {
if recording.InPlayback() {
if recording.GetRecordMode() == "playback" {
return NewFakeCredential("fakestorageaccount", "fakeAccountKey"), nil
}

Expand All @@ -186,7 +187,7 @@ func createStorageClient(t *testing.T) (*Client, error) {
accountName := recording.GetEnvVariable(t, "TABLES_STORAGE_ACCOUNT_NAME", "fakestorageaccount")
accountKey := recording.GetEnvVariable(t, "TABLES_PRIMARY_STORAGE_ACCOUNT_KEY", "fakestorageaccountkey")

if recording.InPlayback() {
if recording.GetRecordMode() == "playback" {
cred, err = getSharedKeyCredential(t)
require.NoError(t, err)
} else {
Expand All @@ -205,7 +206,7 @@ func createStorageClient(t *testing.T) (*Client, error) {
func createCosmosClient(t *testing.T) (*Client, error) {
var cred azcore.Credential
accountName := recording.GetEnvVariable(t, "TABLES_COSMOS_ACCOUNT_NAME", "fakestorageaccount")
if recording.InPlayback() {
if recording.GetRecordMode() == "playback" {
accountName = "fakestorageaccount"
}

Expand All @@ -226,7 +227,7 @@ func createStorageServiceClient(t *testing.T) (*ServiceClient, error) {
accountName := recording.GetEnvVariable(t, "TABLES_STORAGE_ACCOUNT_NAME", "fakestorageaccount")
accountKey := recording.GetEnvVariable(t, "TABLES_PRIMARY_STORAGE_ACCOUNT_KEY", "fakestorageaccountkey")

if recording.InPlayback() {
if recording.GetRecordMode() == "playback" {
cred, err = getSharedKeyCredential(t)
require.NoError(t, err)
} else {
Expand All @@ -242,7 +243,7 @@ func createStorageServiceClient(t *testing.T) (*ServiceClient, error) {
func createCosmosServiceClient(t *testing.T) (*ServiceClient, error) {
var cred azcore.Credential
accountName := recording.GetEnvVariable(t, "TABLES_COSMOS_ACCOUNT_NAME", "fakestorageaccount")
if recording.InPlayback() {
if recording.GetRecordMode() == "playback" {
accountName = "fakestorageaccount"
}

Expand Down
1 change: 0 additions & 1 deletion sdk/internal/recording/recording.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,6 @@ func GetRecordMode() string {
return recordMode
}


func getRootCas(t *testing.T) (*x509.CertPool, error) {
localFile, ok := os.LookupEnv("PROXY_CERT")

Expand Down