Extract constants instead of duplicating literals

This commit is contained in:
Pijus Kamandulis
2025-05-14 20:01:46 +03:00
parent 7e0c10479b
commit e20a6ca7cd
9 changed files with 87 additions and 72 deletions

View File

@@ -19,7 +19,7 @@ func Test_Authentication(t *testing.T) {
t.Run("Should get 200 when correct account key is used", func(t *testing.T) {
ts.DataStore.DeleteDatabase(testDatabaseName)
client, err := azcosmos.NewClientFromConnectionString(
fmt.Sprintf("AccountEndpoint=%s;AccountKey=%s", ts.URL, config.DefaultAccountKey),
formatConnectionString(ts.URL, config.DefaultAccountKey),
&azcosmos.ClientOptions{},
)
assert.Nil(t, err)
@@ -35,7 +35,7 @@ func Test_Authentication(t *testing.T) {
t.Run("Should get 401 when wrong account key is used", func(t *testing.T) {
ts.DataStore.DeleteDatabase(testDatabaseName)
client, err := azcosmos.NewClientFromConnectionString(
fmt.Sprintf("AccountEndpoint=%s;AccountKey=%s", ts.URL, "AAAA"),
formatConnectionString(ts.URL, "AAAA"),
&azcosmos.ClientOptions{},
)
assert.Nil(t, err)
@@ -72,7 +72,7 @@ func Test_Authentication_Disabled(t *testing.T) {
t.Run("Should get 200 when wrong account key is used, but authentication is dissabled", func(t *testing.T) {
ts.DataStore.DeleteDatabase(testDatabaseName)
client, err := azcosmos.NewClientFromConnectionString(
fmt.Sprintf("AccountEndpoint=%s;AccountKey=%s", ts.URL, "AAAA"),
formatConnectionString(ts.URL, "AAAA"),
&azcosmos.ClientOptions{},
)
assert.Nil(t, err)
@@ -85,3 +85,7 @@ func Test_Authentication_Disabled(t *testing.T) {
assert.Equal(t, createResponse.DatabaseProperties.ID, testDatabaseName)
})
}
func formatConnectionString(endpoint, key string) string {
return fmt.Sprintf("AccountEndpoint=%s;AccountKey=%s", endpoint, key)
}