Skip to content

Commit

Permalink
[Tables] update internal and improve code coverage (#16532)
Browse files Browse the repository at this point in the history
* update internal and improve code coverage

* slight improvement

* adding live coverage goal to coverage check

* batch tests are getting a 404 and no request from proxy

* at a place to discuss with Sean in the morning

* improving coverage on batching

* up cov to 0.78, undo changes to coverage tool

Co-authored-by: scbedd <45376673+scbedd@users.noreply.github.com>
  • Loading branch information
seankane-msft and scbedd committed Feb 9, 2022
1 parent 99f0c4f commit be0c05a
Show file tree
Hide file tree
Showing 18 changed files with 521 additions and 585 deletions.
2 changes: 1 addition & 1 deletion eng/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
{
"Name": "data",
"CoverageGoal": 0.62,
"CoverageGoal": 0.78,
"EnvironmentVariables": {
"TABLES_STORAGE_ACCOUNT_NAME": "fakeaccount",
"TABLES_PRIMARY_STORAGE_ACCOUNT_KEY": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==",
Expand Down
15 changes: 15 additions & 0 deletions sdk/data/aztables/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -468,6 +469,20 @@ func TestContinuationTokensFilters(t *testing.T) {
}
}

func TestClientConstructor(t *testing.T) {
// Test NewClient, which is not used by recording infra
cred, err := azidentity.NewDefaultAzureCredential(nil)
require.NoError(t, err)
client, err := NewClient("https://fakeaccount.table.core.windows.net/", cred, nil)
require.NoError(t, err)
require.NotNil(t, client.client)

// Test NewClientWithNoCredential, which is also not used
client2, err := NewClientWithNoCredential("https://fakeaccount.table.core.windows.net/", nil)
require.NoError(t, err)
require.NotNil(t, client2.client)
}

func TestAzurite(t *testing.T) {
// quick and dirty make sure azurite is running
req, err := http.NewRequest("POST", "http://localhost:10002", nil)
Expand Down
77 changes: 9 additions & 68 deletions sdk/data/aztables/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"fmt"
"hash/fnv"
"net/http"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -37,7 +36,7 @@ func TestMain(m *testing.M) {
os.Exit(1)
}

err := recording.AddURISanitizer("fakeaccount", account, nil)
err := recording.AddGeneralRegexSanitizer("fakeaccount", account, nil)
if err != nil {
panic(err)
}
Expand All @@ -64,47 +63,6 @@ var pathToPackage = "sdk/data/aztables/testdata"

const tableNamePrefix = "tableName"

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

func (r recordingPolicy) Host() string {
if r.options.UseHTTPS {
return "localhost:5001"
}
return "localhost:5000"
}

func (r recordingPolicy) Scheme() string {
if r.options.UseHTTPS {
return "https"
}
return "http"
}

func NewRecordingPolicy(t *testing.T, o *recording.RecordingOptions) policy.Policy {
if o == nil {
o = &recording.RecordingOptions{UseHTTPS: true}
}
p := &recordingPolicy{options: *o, t: t}
return p
}

func (p *recordingPolicy) Do(req *policy.Request) (resp *http.Response, err error) {
if recording.GetRecordMode() != "live" && !recording.IsLiveOnly(p.t) {
originalURLHost := req.Raw().URL.Host
req.Raw().URL.Scheme = p.Scheme()
req.Raw().URL.Host = p.Host()
req.Raw().Host = p.Host()

req.Raw().Header.Set(recording.UpstreamURIHeader, fmt.Sprintf("%v://%v", p.Scheme(), originalURLHost))
req.Raw().Header.Set(recording.ModeHeader, recording.GetRecordMode())
req.Raw().Header.Set(recording.IDHeader, recording.GetRecordingId(p.t))
}
return req.Next()
}

type FakeCredential struct {
accountName string
accountKey string
Expand All @@ -122,13 +80,11 @@ func NewFakeCredential(accountName, accountKey string) *FakeCredential {
}

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

options := &ClientOptions{ClientOptions: azcore.ClientOptions{
PerCallPolicies: []policy.Policy{p},
Transport: client,
Transport: client,
}}
if !strings.HasSuffix(serviceURL, "/") && tableName != "" {
serviceURL += "/"
Expand All @@ -139,13 +95,11 @@ func createClientForRecording(t *testing.T, tableName string, serviceURL string,
}

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

options := &ClientOptions{ClientOptions: azcore.ClientOptions{
PerCallPolicies: []policy.Policy{p},
Transport: client,
Transport: client,
}}
if !strings.HasSuffix(serviceURL, "/") && tableName != "" {
serviceURL += "/"
Expand All @@ -156,25 +110,21 @@ func createClientForRecordingWithNoCredential(t *testing.T, tableName string, se
}

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

options := &ClientOptions{ClientOptions: azcore.ClientOptions{
PerCallPolicies: []policy.Policy{p},
Transport: client,
Transport: client,
}}
return NewServiceClientWithSharedKey(serviceURL, &cred, options)
}

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

options := &ClientOptions{ClientOptions: azcore.ClientOptions{
PerCallPolicies: []policy.Policy{p},
Transport: client,
Transport: client,
}}
return NewServiceClientWithNoCredential(serviceURL, options)
}
Expand Down Expand Up @@ -226,15 +176,6 @@ func initServiceTest(t *testing.T, service string) (*ServiceClient, func()) {
}
}

// func getAADCredential(t *testing.T) (azcore.TokenCredential, error) {
// if recording.GetRecordMode() == "playback" {
// cred := NewFakeCredential("fakeaccount", "fakeAccountKey")
// return cred, nil
// }

// return azidentity.NewDefaultAzureCredential(nil)
// }

func getSharedKeyCredential(t *testing.T) (*SharedKeyCredential, error) {
if recording.GetRecordMode() == "playback" {
return NewSharedKeyCredential("accountName", "daaaaaaaaaabbbbbbbbbbcccccccccccccccccccdddddddddddddddddddeeeeeeeeeeefffffffffffggggg==")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Content-Type": "application/json",
"dataserviceversion": "3.0",
"User-Agent": "azsdk-go-internal/v0.5.1 azsdk-go-azcore/v0.21.0 (go1.17; Windows_NT)",
"x-ms-date": "Mon, 24 Jan 2022 20:59:16 GMT",
"x-ms-date": "Mon, 31 Jan 2022 20:47:30 GMT",
"x-ms-version": "2019-02-02"
},
"RequestBody": {
Expand All @@ -21,15 +21,15 @@
"StatusCode": 201,
"ResponseHeaders": {
"Content-Type": "application/json; odata=minimalmetadata",
"Date": "Mon, 24 Jan 2022 20:59:17 GMT",
"ETag": "W/\u0022datetime\u00272022-01-24T20%3A59%3A17.8403848Z\u0027\u0022",
"Location": "https://rosebudprim.table.cosmos.azure.com/Tables(\u0027tableName2210495615\u0027)",
"Date": "Mon, 31 Jan 2022 20:47:33 GMT",
"ETag": "W/\u0022datetime\u00272022-01-31T20%3A47%3A33.9284488Z\u0027\u0022",
"Location": "https://fakeaccount.table.cosmos.azure.com/Tables(\u0027tableName2210495615\u0027)",
"Transfer-Encoding": "chunked",
"x-ms-request-id": "2b5e07b7-0c58-4e90-a385-b30f3944a626"
"x-ms-request-id": "d65e51f9-0eb0-4d9c-b102-5ea7e7d5f6d6"
},
"ResponseBody": {
"TableName": "tableName2210495615",
"odata.metadata": "https://rosebudprim.table.cosmos.azure.com/$metadata#Tables/@Element"
"odata.metadata": "https://fakeaccount.table.cosmos.azure.com/$metadata#Tables/@Element"
}
},
{
Expand All @@ -45,7 +45,7 @@
"dataserviceversion": "3.0",
"prefer": "return-no-content",
"User-Agent": "azsdk-go-internal/v0.5.1 azsdk-go-azcore/v0.21.0 (go1.17; Windows_NT)",
"x-ms-date": "Mon, 24 Jan 2022 20:59:17 GMT",
"x-ms-date": "Mon, 31 Jan 2022 20:47:33 GMT",
"x-ms-version": "2019-02-02"
},
"RequestBody": {
Expand All @@ -61,11 +61,11 @@
},
"StatusCode": 204,
"ResponseHeaders": {
"Date": "Mon, 24 Jan 2022 20:59:17 GMT",
"ETag": "W/\u0022datetime\u00272022-01-24T20%3A59%3A18.2357512Z\u0027\u0022",
"Location": "https://rosebudprim.table.cosmos.azure.com/tableName2210495615(PartitionKey=\u0027partition\u0027,RowKey=\u00271\u0027)",
"Date": "Mon, 31 Jan 2022 20:47:33 GMT",
"ETag": "W/\u0022datetime\u00272022-01-31T20%3A47%3A34.3482888Z\u0027\u0022",
"Location": "https://fakeaccount.table.cosmos.azure.com/tableName2210495615(PartitionKey=\u0027partition\u0027,RowKey=\u00271\u0027)",
"Preference-Applied": "return-no-content",
"x-ms-request-id": "53118439-e393-4a4e-a11e-2d82a485ce9d"
"x-ms-request-id": "d5feea3b-2fc5-4192-88f1-71f487fe6680"
},
"ResponseBody": null
},
Expand All @@ -77,14 +77,14 @@
"Accept-Encoding": "gzip",
"Authorization": "Sanitized",
"User-Agent": "azsdk-go-internal/v0.5.1 azsdk-go-azcore/v0.21.0 (go1.17; Windows_NT)",
"x-ms-date": "Mon, 24 Jan 2022 20:59:17 GMT",
"x-ms-date": "Mon, 31 Jan 2022 20:47:33 GMT",
"x-ms-version": "2019-02-02"
},
"RequestBody": null,
"StatusCode": 204,
"ResponseHeaders": {
"Date": "Mon, 24 Jan 2022 20:59:17 GMT",
"x-ms-request-id": "ab3fc71f-cf2f-4a8e-9a25-ebcf5424005c"
"Date": "Mon, 31 Jan 2022 20:47:33 GMT",
"x-ms-request-id": "a7b24c83-529b-4129-8303-b4089c73b316"
},
"ResponseBody": null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Content-Type": "application/json",
"dataserviceversion": "3.0",
"User-Agent": "azsdk-go-internal/v0.5.1 azsdk-go-azcore/v0.21.0 (go1.17; Windows_NT)",
"x-ms-date": "Mon, 24 Jan 2022 20:59:16 GMT",
"x-ms-date": "Mon, 31 Jan 2022 20:47:29 GMT",
"x-ms-version": "2019-02-02"
},
"RequestBody": {
Expand All @@ -22,19 +22,19 @@
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Type": "application/json; odata=minimalmetadata; streaming=true; charset=utf-8",
"Date": "Mon, 24 Jan 2022 20:59:17 GMT",
"Location": "https://rosebudprim.table.core.windows.net/Tables(\u0027tableName1098819688\u0027)",
"Date": "Mon, 31 Jan 2022 20:47:30 GMT",
"Location": "https://fakeaccount.table.core.windows.net/Tables(\u0027tableName1098819688\u0027)",
"Server": [
"Windows-Azure-Table/1.0",
"Microsoft-HTTPAPI/2.0"
],
"Transfer-Encoding": "chunked",
"X-Content-Type-Options": "nosniff",
"x-ms-request-id": "f9916c3a-b002-0054-4765-11ec4e000000",
"x-ms-request-id": "d8d1d8f8-a002-0006-2ee3-16ac52000000",
"x-ms-version": "2019-02-02"
},
"ResponseBody": {
"odata.metadata": "https://rosebudprim.table.core.windows.net/$metadata#Tables/@Element",
"odata.metadata": "https://fakeaccount.table.core.windows.net/$metadata#Tables/@Element",
"TableName": "tableName1098819688"
}
},
Expand All @@ -51,7 +51,7 @@
"dataserviceversion": "3.0",
"prefer": "return-no-content",
"User-Agent": "azsdk-go-internal/v0.5.1 azsdk-go-azcore/v0.21.0 (go1.17; Windows_NT)",
"x-ms-date": "Mon, 24 Jan 2022 20:59:16 GMT",
"x-ms-date": "Mon, 31 Jan 2022 20:47:30 GMT",
"x-ms-version": "2019-02-02"
},
"RequestBody": {
Expand All @@ -69,17 +69,17 @@
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "0",
"DataServiceId": "https://rosebudprim.table.core.windows.net/tableName1098819688(PartitionKey=\u0027partition\u0027,RowKey=\u00271\u0027)",
"Date": "Mon, 24 Jan 2022 20:59:17 GMT",
"ETag": "W/\u0022datetime\u00272022-01-24T20%3A59%3A17.4554303Z\u0027\u0022",
"Location": "https://rosebudprim.table.core.windows.net/tableName1098819688(PartitionKey=\u0027partition\u0027,RowKey=\u00271\u0027)",
"DataServiceId": "https://fakeaccount.table.core.windows.net/tableName1098819688(PartitionKey=\u0027partition\u0027,RowKey=\u00271\u0027)",
"Date": "Mon, 31 Jan 2022 20:47:30 GMT",
"ETag": "W/\u0022datetime\u00272022-01-31T20%3A47%3A30.8897666Z\u0027\u0022",
"Location": "https://fakeaccount.table.core.windows.net/tableName1098819688(PartitionKey=\u0027partition\u0027,RowKey=\u00271\u0027)",
"Preference-Applied": "return-no-content",
"Server": [
"Windows-Azure-Table/1.0",
"Microsoft-HTTPAPI/2.0"
],
"X-Content-Type-Options": "nosniff",
"x-ms-request-id": "f9916c72-b002-0054-7b65-11ec4e000000",
"x-ms-request-id": "d8d1d907-a002-0006-38e3-16ac52000000",
"x-ms-version": "2019-02-02"
},
"ResponseBody": null
Expand All @@ -92,21 +92,21 @@
"Accept-Encoding": "gzip",
"Authorization": "Sanitized",
"User-Agent": "azsdk-go-internal/v0.5.1 azsdk-go-azcore/v0.21.0 (go1.17; Windows_NT)",
"x-ms-date": "Mon, 24 Jan 2022 20:59:16 GMT",
"x-ms-date": "Mon, 31 Jan 2022 20:47:30 GMT",
"x-ms-version": "2019-02-02"
},
"RequestBody": null,
"StatusCode": 204,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "0",
"Date": "Mon, 24 Jan 2022 20:59:17 GMT",
"Date": "Mon, 31 Jan 2022 20:47:30 GMT",
"Server": [
"Windows-Azure-Table/1.0",
"Microsoft-HTTPAPI/2.0"
],
"X-Content-Type-Options": "nosniff",
"x-ms-request-id": "f9916cb3-b002-0054-3865-11ec4e000000",
"x-ms-request-id": "d8d1d90b-a002-0006-3ce3-16ac52000000",
"x-ms-version": "2019-02-02"
},
"ResponseBody": null
Expand Down

0 comments on commit be0c05a

Please sign in to comment.