| 1 |
package tablesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/ |
| 2 |
|
| 3 |
import ( |
| 4 |
"contextscip-go gomod github.com/golang/go/src go1.13 context/" |
| 5 |
"fmtscip-go gomod github.com/golang/go/src go1.13 fmt/" |
| 6 |
"logscip-go gomod github.com/golang/go/src go1.13 log/" |
| 7 |
"testingscip-go gomod github.com/golang/go/src go1.13 testing/" |
| 8 |
|
| 9 |
"github.com/Azure/azure-sdk-for-go/profiles/latest/storage/mgmt/storagescip-go gomod github.com/Azure/azure-sdk-for-go v68.0.0 `github.com/Azure/azure-sdk-for-go/profiles/latest/storage/mgmt/storage`/" |
| 10 |
"github.com/tombuildsstuff/giovanni/storage/internal/authscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/" |
| 11 |
"github.com/tombuildsstuff/giovanni/testhelpersscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/" |
| 12 |
) |
| 13 |
|
| 14 |
func TestTablesLifecyclescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/TestTablesLifecycle().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 15 |
client, err := testhelpersscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/.Buildscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/Build().(t) |
| 16 |
if err != nil { |
| 17 |
t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().(err) |
| 18 |
} |
| 19 |
ctx := contextscip-go gomod github.com/golang/go/src go1.13 context/.TODOscip-go gomod github.com/golang/go/src go1.13 context/TODO().() |
| 20 |
resourceGroup := fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("acctestrg-%d", testhelpersscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/.RandomIntscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/RandomInt().()) |
| 21 |
accountName := fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("acctestsa%s", testhelpersscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/.RandomStringscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/RandomString().()) |
| 22 |
tableName := fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("table%d", testhelpersscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/.RandomIntscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/RandomInt().()) |
| 23 |
|
| •24 |
testData, err := client.BuildTestResourcesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/Client#BuildTestResources().(ctx, resourceGroup, accountName, storagescip-go gomod github.com/Azure/azure-sdk-for-go v68.0.0 `github.com/Azure/azure-sdk-for-go/profiles/latest/storage/mgmt/storage`/.Storagescip-go gomod github.com/Azure/azure-sdk-for-go v68.0.0 `github.com/Azure/azure-sdk-for-go/profiles/latest/storage/mgmt/storage`/Storage.) |
| 25 |
if err != nil { |
| 26 |
t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().(err) |
| 27 |
} |
| 28 |
defer client.DestroyTestResourcesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/Client#DestroyTestResources().(ctx, resourceGroup, accountName) |
| 29 |
|
| 30 |
storageAuth := authscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/.NewSharedKeyLiteTableAuthorizerscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/NewSharedKeyLiteTableAuthorizer().(accountName, testData.StorageAccountKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/TestResources#StorageAccountKey.) |
| 31 |
tablesClient := NewWithEnvironmentscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/NewWithEnvironment().(client.Environmentscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/Client#Environment.) |
| 32 |
tablesClient.Clientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/Client#Client. = client.PrepareWithAuthorizerscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/Client#PrepareWithAuthorizer().(tablesClient.Clientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/Client#Client., storageAuth) |
| 33 |
|
| 34 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("[DEBUG] Creating Table..") |
| 35 |
if _, err := tablesClient.Createscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/Client#Create().(ctx, accountName, tableName); err != nil { |
| 36 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Error creating Table %q: %s", tableName, err) |
| 37 |
} |
| 38 |
|
| 39 |
// first look it up directly and confirm it's there |
| 40 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("[DEBUG] Checking if Table exists..") |
| 41 |
if _, err := tablesClient.Existsscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/Client#Exists().(ctx, accountName, tableName); err != nil { |
| 42 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Error checking if Table %q exists: %s", tableName, err) |
| 43 |
} |
| 44 |
|
| 45 |
// then confirm it exists in the Query too |
| 46 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("[DEBUG] Querying for Tables..") |
| 47 |
result, err := tablesClient.Queryscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/Client#Query().(ctx, accountName, NoMetaDatascip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/NoMetaData.) |
| 48 |
if err != nil { |
| 49 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Error retrieving Tables: %s", err) |
| 50 |
} |
| 51 |
found := false |
| 52 |
for _, v := range result.Tablesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/GetResult#Tables. { |
| 53 |
logscip-go gomod github.com/golang/go/src go1.13 log/.Printfscip-go gomod github.com/golang/go/src go1.13 log/Printf().("[DEBUG] Table: %q", v.TableNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/GetResultItem#TableName.) |
| 54 |
|
| 55 |
if v.TableNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/GetResultItem#TableName. == tableName { |
| 56 |
found = true |
| 57 |
} |
| 58 |
} |
| 59 |
if !found { |
| 60 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("%q was not found in the Query response!", tableName) |
| 61 |
} |
| 62 |
|
| 63 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("[DEBUG] Setting ACL's for Table %q..", tableName) |
| 64 |
acls := []SignedIdentifierscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/SignedIdentifier#{ |
| 65 |
{ |
| 66 |
Idscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/SignedIdentifier#Id.: "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=", |
| 67 |
AccessPolicyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/SignedIdentifier#AccessPolicy.: AccessPolicyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/AccessPolicy#{ |
| 68 |
Permissionscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/AccessPolicy#Permission.: "raud", |
| 69 |
Startscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/AccessPolicy#Start.: "2020-11-26T08:49:37.0000000Z", |
| 70 |
Expiryscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/AccessPolicy#Expiry.: "2020-11-27T08:49:37.0000000Z", |
| 71 |
}, |
| 72 |
}, |
| 73 |
} |
| 74 |
if _, err := tablesClient.SetACLscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/Client#SetACL().(ctx, accountName, tableName, acls); err != nil { |
| 75 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Error setting ACLs: %s", err) |
| 76 |
} |
| 77 |
|
| 78 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("[DEBUG] Retrieving ACL's for Table %q..", tableName) |
| 79 |
retrievedACLs, err := tablesClient.GetACLscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/Client#GetACL().(ctx, accountName, tableName) |
| 80 |
if err != nil { |
| 81 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Error retrieving ACLs: %s", err) |
| 82 |
} |
| 83 |
|
| 84 |
if len(retrievedACLs.SignedIdentifiersscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/GetACLResult#SignedIdentifiers.) != len(acls) { |
| 85 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Expected %d but got %q ACLs", len(retrievedACLs.SignedIdentifiersscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/GetACLResult#SignedIdentifiers.), len(acls)) |
| 86 |
} |
| 87 |
|
| 88 |
for i, retrievedAcl := range retrievedACLs.SignedIdentifiersscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/GetACLResult#SignedIdentifiers. { |
| 89 |
expectedAcl := acls[i] |
| 90 |
|
| 91 |
if retrievedAcl.Idscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/SignedIdentifier#Id. != expectedAcl.Idscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/SignedIdentifier#Id. { |
| 92 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Expected ID to be %q but got %q", retrievedAcl.Idscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/SignedIdentifier#Id., expectedAcl.Idscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/SignedIdentifier#Id.) |
| 93 |
} |
| 94 |
|
| 95 |
if retrievedAcl.AccessPolicyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/SignedIdentifier#AccessPolicy..Startscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/AccessPolicy#Start. != expectedAcl.AccessPolicyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/SignedIdentifier#AccessPolicy..Startscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/AccessPolicy#Start. { |
| 96 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Expected Start to be %q but got %q", retrievedAcl.AccessPolicyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/SignedIdentifier#AccessPolicy..Startscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/AccessPolicy#Start., expectedAcl.AccessPolicyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/SignedIdentifier#AccessPolicy..Startscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/AccessPolicy#Start.) |
| 97 |
} |
| 98 |
|
| 99 |
if retrievedAcl.AccessPolicyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/SignedIdentifier#AccessPolicy..Expiryscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/AccessPolicy#Expiry. != expectedAcl.AccessPolicyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/SignedIdentifier#AccessPolicy..Expiryscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/AccessPolicy#Expiry. { |
| 100 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Expected Expiry to be %q but got %q", retrievedAcl.AccessPolicyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/SignedIdentifier#AccessPolicy..Expiryscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/AccessPolicy#Expiry., expectedAcl.AccessPolicyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/SignedIdentifier#AccessPolicy..Expiryscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/AccessPolicy#Expiry.) |
| 101 |
} |
| 102 |
|
| 103 |
if retrievedAcl.AccessPolicyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/SignedIdentifier#AccessPolicy..Permissionscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/AccessPolicy#Permission. != expectedAcl.AccessPolicyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/SignedIdentifier#AccessPolicy..Permissionscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/AccessPolicy#Permission. { |
| 104 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Expected Permission to be %q but got %q", retrievedAcl.AccessPolicyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/SignedIdentifier#AccessPolicy..Permissionscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/AccessPolicy#Permission., expectedAcl.AccessPolicyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/SignedIdentifier#AccessPolicy..Permissionscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/AccessPolicy#Permission.) |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("[DEBUG] Deleting Table %q..", tableName) |
| 109 |
if _, err := tablesClient.Deletescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-03-28/table/tables`/Client#Delete().(ctx, accountName, tableName); err != nil { |
| 110 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Error deleting %q: %s", tableName, err) |
| 111 |
} |
| 112 |
} |