| 1 |
package entitiesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/ |
| 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 |
"testingscip-go gomod github.com/golang/go/src go1.13 testing/" |
| 7 |
|
| 8 |
"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`/" |
| 9 |
"github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/tablesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/tables`/" |
| 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 TestEntitiesLifecyclescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/TestEntitiesLifecycle().(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 := tablesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/tables`/.NewWithEnvironmentscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/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/2017-07-29/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/2017-07-29/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/2017-07-29/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 |
defer tablesClient.Deletescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/tables`/Client#Delete().(ctx, accountName, tableName) |
| 39 |
|
| 40 |
entitiesClient := NewWithEnvironmentscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/NewWithEnvironment().(client.Environmentscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/Client#Environment.) |
| 41 |
entitiesClient.Clientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/Client#Client. = client.PrepareWithAuthorizerscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/Client#PrepareWithAuthorizer().(entitiesClient.Clientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/Client#Client., storageAuth) |
| 42 |
|
| 43 |
partitionKey := "hello" |
| 44 |
rowKey := "there" |
| 45 |
|
| 46 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("[DEBUG] Inserting..") |
| 47 |
insertInput := InsertEntityInputscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/InsertEntityInput#{ |
| 48 |
MetaDataLevelscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/InsertEntityInput#MetaDataLevel.: NoMetaDatascip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/NoMetaData., |
| 49 |
PartitionKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/InsertEntityInput#PartitionKey.: partitionKey, |
| 50 |
RowKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/InsertEntityInput#RowKey.: rowKey, |
| 51 |
Entityscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/InsertEntityInput#Entity.: map[string]interface{}{ |
| 52 |
"hello": "world", |
| 53 |
}, |
| 54 |
} |
| 55 |
if _, err := entitiesClient.Insertscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/Client#Insert().(ctx, accountName, tableName, insertInput); err != nil { |
| 56 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("Error retrieving: %s", err) |
| 57 |
} |
| 58 |
|
| 59 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("[DEBUG] Insert or Merging..") |
| 60 |
insertOrMergeInput := InsertOrMergeEntityInputscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/InsertOrMergeEntityInput#{ |
| 61 |
PartitionKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/InsertOrMergeEntityInput#PartitionKey.: partitionKey, |
| 62 |
RowKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/InsertOrMergeEntityInput#RowKey.: rowKey, |
| 63 |
Entityscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/InsertOrMergeEntityInput#Entity.: map[string]interface{}{ |
| 64 |
"hello": "ther88e", |
| 65 |
}, |
| 66 |
} |
| 67 |
if _, err := entitiesClient.InsertOrMergescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/Client#InsertOrMerge().(ctx, accountName, tableName, insertOrMergeInput); err != nil { |
| 68 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("Error insert/merging: %s", err) |
| 69 |
} |
| 70 |
|
| 71 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("[DEBUG] Insert or Replacing..") |
| 72 |
insertOrReplaceInput := InsertOrReplaceEntityInputscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/InsertOrReplaceEntityInput#{ |
| 73 |
PartitionKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/InsertOrReplaceEntityInput#PartitionKey.: partitionKey, |
| 74 |
RowKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/InsertOrReplaceEntityInput#RowKey.: rowKey, |
| 75 |
Entityscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/InsertOrReplaceEntityInput#Entity.: map[string]interface{}{ |
| 76 |
"hello": "pandas", |
| 77 |
}, |
| 78 |
} |
| 79 |
if _, err := entitiesClient.InsertOrReplacescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/Client#InsertOrReplace().(ctx, accountName, tableName, insertOrReplaceInput); err != nil { |
| 80 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("Error inserting/replacing: %s", err) |
| 81 |
} |
| 82 |
|
| 83 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("[DEBUG] Querying..") |
| 84 |
queryInput := QueryEntitiesInputscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/QueryEntitiesInput#{ |
| 85 |
MetaDataLevelscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/QueryEntitiesInput#MetaDataLevel.: NoMetaDatascip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/NoMetaData., |
| 86 |
} |
| 87 |
results, err := entitiesClient.Queryscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/Client#Query().(ctx, accountName, tableName, queryInput) |
| 88 |
if err != nil { |
| 89 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("Error querying: %s", err) |
| 90 |
} |
| 91 |
|
| 92 |
if len(results.Entitiesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/QueryEntitiesResult#Entities.) != 1 { |
| 93 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Expected 1 item but got %d", len(results.Entitiesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/QueryEntitiesResult#Entities.)) |
| 94 |
} |
| 95 |
|
| 96 |
for _, v := range results.Entitiesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/QueryEntitiesResult#Entities. { |
| 97 |
thisPartitionKey := v["PartitionKey"].(string) |
| 98 |
thisRowKey := v["RowKey"].(string) |
| 99 |
if partitionKey != thisPartitionKey { |
| 100 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Expected Partition Key to be %q but got %q", partitionKey, thisPartitionKey) |
| 101 |
} |
| 102 |
if rowKey != thisRowKey { |
| 103 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Expected Partition Key to be %q but got %q", rowKey, thisRowKey) |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("[DEBUG] Retrieving..") |
| 108 |
getInput := GetEntityInputscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/GetEntityInput#{ |
| 109 |
MetaDataLevelscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/GetEntityInput#MetaDataLevel.: MinimalMetaDatascip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/MinimalMetaData., |
| 110 |
PartitionKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/GetEntityInput#PartitionKey.: partitionKey, |
| 111 |
RowKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/GetEntityInput#RowKey.: rowKey, |
| 112 |
} |
| 113 |
getResults, err := entitiesClient.Getscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/Client#Get().(ctx, accountName, tableName, getInput) |
| 114 |
if err != nil { |
| 115 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("Error querying: %s", err) |
| 116 |
} |
| 117 |
|
| 118 |
partitionKey2 := getResults.Entityscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/GetEntityResult#Entity.["PartitionKey"].(string) |
| 119 |
rowKey2 := getResults.Entityscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/GetEntityResult#Entity.["RowKey"].(string) |
| 120 |
if partitionKey2 != partitionKey { |
| 121 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Expected Partition Key to be %q but got %q", partitionKey, partitionKey2) |
| 122 |
} |
| 123 |
if rowKey2 != rowKey { |
| 124 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Expected Row Key to be %q but got %q", rowKey, rowKey2) |
| 125 |
} |
| 126 |
|
| 127 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("[DEBUG] Deleting..") |
| 128 |
deleteInput := DeleteEntityInputscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/DeleteEntityInput#{ |
| 129 |
PartitionKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/DeleteEntityInput#PartitionKey.: partitionKey, |
| 130 |
RowKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/DeleteEntityInput#RowKey.: rowKey, |
| 131 |
} |
| 132 |
if _, err := entitiesClient.Deletescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/entities`/Client#Delete().(ctx, accountName, tableName, deleteInput); err != nil { |
| 133 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("Error deleting: %s", err) |
| 134 |
} |
| 135 |
} |