Skip to content

Commit 400b513

Browse files
committed
fix(azure): correctness fixes across SQL/NoSQL, resource group, container apps, DNS
Parameter-order mismatch silently-swapping args between Context and ContextE twins: - GetMYSQLServerContext, GetMYSQLDBContext, ListMySQLDBContext - GetPostgreSQLServerContext, GetPostgreSQLDBContext - GetSQLServerContext, GetSQLDatabaseContext - GetSynapseWorkspaceContext, GetSynapseSQLPoolContext - GetDataFactoryContext Context wrappers now take (ctx, subscriptionID, resGroupName, ...) matching their ContextE twins. Deprecated non-context callers updated. Example tests under test/azure updated. GetResourceGroupContextE was using case-sensitive string comparison against the server-side RG name; Azure RG names are case-insensitive. Switched to strings.EqualFold and added a nil guard. Container Apps Exists helpers previously returned raw errors on 404 instead of (false, nil): - ManagedEnvironmentExistsContextE - ContainerAppExistsContextE - ContainerAppJobExistsContextE Now convert ResourceNotFoundErrorExists to (false, nil), matching the contract used by DataFactoryExistsContextE. CheckPublicDNSNameAvailabilityContext was silently returning false on error instead of failing the test. Now uses require.NoError.
1 parent 7e13d70 commit 400b513

13 files changed

Lines changed: 49 additions & 33 deletions

modules/azure/container_apps.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ func ManagedEnvironmentExistsContextE(ctx context.Context, environmentName strin
4040

4141
_, err = client.Get(ctx, resourceGroupName, environmentName, nil)
4242
if err != nil {
43+
if ResourceNotFoundErrorExists(err) {
44+
return false, nil
45+
}
46+
4347
return false, err
4448
}
4549

@@ -136,6 +140,10 @@ func ContainerAppExistsContextE(ctx context.Context, containerAppName string, re
136140

137141
_, err = client.Get(ctx, resourceGroupName, containerAppName, nil)
138142
if err != nil {
143+
if ResourceNotFoundErrorExists(err) {
144+
return false, nil
145+
}
146+
139147
return false, err
140148
}
141149

@@ -232,6 +240,10 @@ func ContainerAppJobExistsContextE(ctx context.Context, containerAppName string,
232240

233241
_, err = client.Get(ctx, resourceGroupName, containerAppName, nil)
234242
if err != nil {
243+
if ResourceNotFoundErrorExists(err) {
244+
return false, nil
245+
}
246+
235247
return false, err
236248
}
237249

modules/azure/datafactory.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func DataFactoryExistsE(dataFactoryName string, resourceGroupName string, subscr
5555
// GetDataFactoryContext returns the Data Factory object.
5656
// This function would fail the test if there is an error.
5757
// The ctx parameter supports cancellation and timeouts.
58-
func GetDataFactoryContext(t testing.TestingT, ctx context.Context, resGroupName string, factoryName string, subscriptionID string) *armdatafactory.Factory {
58+
func GetDataFactoryContext(t testing.TestingT, ctx context.Context, subscriptionID string, resGroupName string, factoryName string) *armdatafactory.Factory {
5959
t.Helper()
6060

6161
factory, err := GetDataFactoryContextE(ctx, subscriptionID, resGroupName, factoryName)
@@ -71,7 +71,7 @@ func GetDataFactoryContext(t testing.TestingT, ctx context.Context, resGroupName
7171
func GetDataFactory(t testing.TestingT, resGroupName string, factoryName string, subscriptionID string) *armdatafactory.Factory {
7272
t.Helper()
7373

74-
return GetDataFactoryContext(t, context.Background(), resGroupName, factoryName, subscriptionID) //nolint:staticcheck
74+
return GetDataFactoryContext(t, context.Background(), subscriptionID, resGroupName, factoryName) //nolint:staticcheck
7575
}
7676

7777
// GetDataFactoryContextE returns the Data Factory object.

modules/azure/mysql.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func GetMYSQLServerClientE(subscriptionID string) (*armmysql.ServersClient, erro
3030
// GetMYSQLServerContext is a helper function that gets the server.
3131
// This function would fail the test if there is an error.
3232
// The ctx parameter supports cancellation and timeouts.
33-
func GetMYSQLServerContext(t testing.TestingT, ctx context.Context, resGroupName string, serverName string, subscriptionID string) *armmysql.Server {
33+
func GetMYSQLServerContext(t testing.TestingT, ctx context.Context, subscriptionID string, resGroupName string, serverName string) *armmysql.Server {
3434
t.Helper()
3535

3636
mysqlServer, err := GetMYSQLServerContextE(t, ctx, subscriptionID, resGroupName, serverName)
@@ -46,7 +46,7 @@ func GetMYSQLServerContext(t testing.TestingT, ctx context.Context, resGroupName
4646
func GetMYSQLServer(t testing.TestingT, resGroupName string, serverName string, subscriptionID string) *armmysql.Server {
4747
t.Helper()
4848

49-
return GetMYSQLServerContext(t, context.Background(), resGroupName, serverName, subscriptionID) //nolint:staticcheck
49+
return GetMYSQLServerContext(t, context.Background(), subscriptionID, resGroupName, serverName) //nolint:staticcheck
5050
}
5151

5252
// GetMYSQLServerContextE is a helper function that gets the server.
@@ -99,7 +99,7 @@ func GetMYSQLDBClientE(subscriptionID string) (*armmysql.DatabasesClient, error)
9999
// GetMYSQLDBContext is a helper function that gets the database.
100100
// This function would fail the test if there is an error.
101101
// The ctx parameter supports cancellation and timeouts.
102-
func GetMYSQLDBContext(t testing.TestingT, ctx context.Context, resGroupName string, serverName string, dbName string, subscriptionID string) *armmysql.Database {
102+
func GetMYSQLDBContext(t testing.TestingT, ctx context.Context, subscriptionID string, resGroupName string, serverName string, dbName string) *armmysql.Database {
103103
t.Helper()
104104

105105
database, err := GetMYSQLDBContextE(t, ctx, subscriptionID, resGroupName, serverName, dbName)
@@ -115,7 +115,7 @@ func GetMYSQLDBContext(t testing.TestingT, ctx context.Context, resGroupName str
115115
func GetMYSQLDB(t testing.TestingT, resGroupName string, serverName string, dbName string, subscriptionID string) *armmysql.Database {
116116
t.Helper()
117117

118-
return GetMYSQLDBContext(t, context.Background(), resGroupName, serverName, dbName, subscriptionID) //nolint:staticcheck
118+
return GetMYSQLDBContext(t, context.Background(), subscriptionID, resGroupName, serverName, dbName) //nolint:staticcheck
119119
}
120120

121121
// GetMYSQLDBContextE is a helper function that gets the database.
@@ -150,7 +150,7 @@ func GetMYSQLDBE(t testing.TestingT, subscriptionID string, resGroupName string,
150150
// ListMySQLDBContext is a helper function that gets all databases per server.
151151
// This function would fail the test if there is an error.
152152
// The ctx parameter supports cancellation and timeouts.
153-
func ListMySQLDBContext(t testing.TestingT, ctx context.Context, resGroupName string, serverName string, subscriptionID string) []*armmysql.Database {
153+
func ListMySQLDBContext(t testing.TestingT, ctx context.Context, subscriptionID string, resGroupName string, serverName string) []*armmysql.Database {
154154
t.Helper()
155155

156156
dblist, err := ListMySQLDBContextE(t, ctx, subscriptionID, resGroupName, serverName)
@@ -166,7 +166,7 @@ func ListMySQLDBContext(t testing.TestingT, ctx context.Context, resGroupName st
166166
func ListMySQLDB(t testing.TestingT, resGroupName string, serverName string, subscriptionID string) []*armmysql.Database {
167167
t.Helper()
168168

169-
return ListMySQLDBContext(t, context.Background(), resGroupName, serverName, subscriptionID) //nolint:staticcheck
169+
return ListMySQLDBContext(t, context.Background(), subscriptionID, resGroupName, serverName) //nolint:staticcheck
170170
}
171171

172172
// ListMySQLDBContextE is a helper function that gets all databases per server.

modules/azure/postgresql.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func GetPostgreSQLServerClientE(subscriptionID string) (*armpostgresql.ServersCl
3030
// GetPostgreSQLServerContext is a helper function that gets the server.
3131
// This function would fail the test if there is an error.
3232
// The ctx parameter supports cancellation and timeouts.
33-
func GetPostgreSQLServerContext(t testing.TestingT, ctx context.Context, resGroupName string, serverName string, subscriptionID string) *armpostgresql.Server {
33+
func GetPostgreSQLServerContext(t testing.TestingT, ctx context.Context, subscriptionID string, resGroupName string, serverName string) *armpostgresql.Server {
3434
t.Helper()
3535

3636
postgresqlServer, err := GetPostgreSQLServerContextE(t, ctx, subscriptionID, resGroupName, serverName)
@@ -46,7 +46,7 @@ func GetPostgreSQLServerContext(t testing.TestingT, ctx context.Context, resGrou
4646
func GetPostgreSQLServer(t testing.TestingT, resGroupName string, serverName string, subscriptionID string) *armpostgresql.Server {
4747
t.Helper()
4848

49-
return GetPostgreSQLServerContext(t, context.Background(), resGroupName, serverName, subscriptionID) //nolint:staticcheck
49+
return GetPostgreSQLServerContext(t, context.Background(), subscriptionID, resGroupName, serverName) //nolint:staticcheck
5050
}
5151

5252
// GetPostgreSQLServerContextE is a helper function that gets the server.
@@ -99,7 +99,7 @@ func GetPostgreSQLDBClientE(subscriptionID string) (*armpostgresql.DatabasesClie
9999
// GetPostgreSQLDBContext is a helper function that gets the database.
100100
// This function would fail the test if there is an error.
101101
// The ctx parameter supports cancellation and timeouts.
102-
func GetPostgreSQLDBContext(t testing.TestingT, ctx context.Context, resGroupName string, serverName string, dbName string, subscriptionID string) *armpostgresql.Database {
102+
func GetPostgreSQLDBContext(t testing.TestingT, ctx context.Context, subscriptionID string, resGroupName string, serverName string, dbName string) *armpostgresql.Database {
103103
t.Helper()
104104

105105
database, err := GetPostgreSQLDBContextE(t, ctx, subscriptionID, resGroupName, serverName, dbName)
@@ -115,7 +115,7 @@ func GetPostgreSQLDBContext(t testing.TestingT, ctx context.Context, resGroupNam
115115
func GetPostgreSQLDB(t testing.TestingT, resGroupName string, serverName string, dbName string, subscriptionID string) *armpostgresql.Database {
116116
t.Helper()
117117

118-
return GetPostgreSQLDBContext(t, context.Background(), resGroupName, serverName, dbName, subscriptionID) //nolint:staticcheck
118+
return GetPostgreSQLDBContext(t, context.Background(), subscriptionID, resGroupName, serverName, dbName) //nolint:staticcheck
119119
}
120120

121121
// GetPostgreSQLDBContextE is a helper function that gets the database.

modules/azure/publicaddress.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ func CheckPublicDNSNameAvailabilityContext(t testing.TestingT, ctx context.Conte
118118
t.Helper()
119119

120120
available, err := CheckPublicDNSNameAvailabilityContextE(ctx, location, domainNameLabel, subscriptionID)
121-
if err != nil {
122-
return false
123-
}
121+
require.NoError(t, err)
124122

125123
return available
126124
}

modules/azure/resourcegroup.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"strings"
78

89
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
910
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
@@ -56,14 +57,19 @@ func ResourceGroupExistsE(resourceGroupName, subscriptionID string) (bool, error
5657
}
5758

5859
// GetResourceGroupContextE checks whether a resource group name matches the one retrieved from the subscription.
60+
// Azure resource group names are case-insensitive, so the comparison is performed with EqualFold.
5961
// The ctx parameter supports cancellation and timeouts.
6062
func GetResourceGroupContextE(ctx context.Context, resourceGroupName, subscriptionID string) (bool, error) {
6163
rg, err := GetAResourceGroupContextE(ctx, resourceGroupName, subscriptionID)
6264
if err != nil {
6365
return false, err
6466
}
6567

66-
return (resourceGroupName == *rg.Name), nil
68+
if rg == nil || rg.Name == nil {
69+
return false, nil
70+
}
71+
72+
return strings.EqualFold(resourceGroupName, *rg.Name), nil
6773
}
6874

6975
// GetResourceGroupE checks whether a resource group name matches the one retrieved from the subscription.

modules/azure/sql.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func GetSQLServerClient(subscriptionID string) (*armsql.ServersClient, error) {
2424
// GetSQLServerContext is a helper function that gets the sql server object.
2525
// This function would fail the test if there is an error.
2626
// The ctx parameter supports cancellation and timeouts.
27-
func GetSQLServerContext(t testing.TestingT, ctx context.Context, resGroupName string, serverName string, subscriptionID string) *armsql.Server {
27+
func GetSQLServerContext(t testing.TestingT, ctx context.Context, subscriptionID string, resGroupName string, serverName string) *armsql.Server {
2828
t.Helper()
2929

3030
sqlServer, err := GetSQLServerContextE(t, ctx, subscriptionID, resGroupName, serverName)
@@ -40,7 +40,7 @@ func GetSQLServerContext(t testing.TestingT, ctx context.Context, resGroupName s
4040
func GetSQLServer(t testing.TestingT, resGroupName string, serverName string, subscriptionID string) *armsql.Server {
4141
t.Helper()
4242

43-
return GetSQLServerContext(t, context.Background(), resGroupName, serverName, subscriptionID)
43+
return GetSQLServerContext(t, context.Background(), subscriptionID, resGroupName, serverName)
4444
}
4545

4646
// GetSQLServerContextE is a helper function that gets the sql server object.
@@ -147,7 +147,7 @@ func ListSQLServerDatabasesE(t testing.TestingT, resGroupName string, serverName
147147
// GetSQLDatabaseContext is a helper function that gets the sql db.
148148
// This function would fail the test if there is an error.
149149
// The ctx parameter supports cancellation and timeouts.
150-
func GetSQLDatabaseContext(t testing.TestingT, ctx context.Context, resGroupName string, serverName string, dbName string, subscriptionID string) *armsql.Database {
150+
func GetSQLDatabaseContext(t testing.TestingT, ctx context.Context, subscriptionID string, resGroupName string, serverName string, dbName string) *armsql.Database {
151151
t.Helper()
152152

153153
database, err := GetSQLDatabaseContextE(t, ctx, subscriptionID, resGroupName, serverName, dbName)
@@ -163,7 +163,7 @@ func GetSQLDatabaseContext(t testing.TestingT, ctx context.Context, resGroupName
163163
func GetSQLDatabase(t testing.TestingT, resGroupName string, serverName string, dbName string, subscriptionID string) *armsql.Database {
164164
t.Helper()
165165

166-
return GetSQLDatabaseContext(t, context.Background(), resGroupName, serverName, dbName, subscriptionID)
166+
return GetSQLDatabaseContext(t, context.Background(), subscriptionID, resGroupName, serverName, dbName)
167167
}
168168

169169
// GetSQLDatabaseContextE is a helper function that gets the sql db.

modules/azure/synapse.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
// GetSynapseWorkspaceContext retrieves the synapse workspace for the given subscription.
1212
// This function would fail the test if there is an error.
1313
// The ctx parameter supports cancellation and timeouts.
14-
func GetSynapseWorkspaceContext(t testing.TestingT, ctx context.Context, resGroupName string, workspaceName string, subscriptionID string) *armsynapse.Workspace {
14+
func GetSynapseWorkspaceContext(t testing.TestingT, ctx context.Context, subscriptionID string, resGroupName string, workspaceName string) *armsynapse.Workspace {
1515
t.Helper()
1616

1717
workspace, err := GetSynapseWorkspaceContextE(ctx, subscriptionID, resGroupName, workspaceName)
@@ -48,7 +48,7 @@ func GetSynapseWorkspaceWithClient(ctx context.Context, client *armsynapse.Works
4848
func GetSynapseWorkspace(t testing.TestingT, resGroupName string, workspaceName string, subscriptionID string) *armsynapse.Workspace {
4949
t.Helper()
5050

51-
return GetSynapseWorkspaceContext(t, context.Background(), resGroupName, workspaceName, subscriptionID)
51+
return GetSynapseWorkspaceContext(t, context.Background(), subscriptionID, resGroupName, workspaceName)
5252
}
5353

5454
// GetSynapseWorkspaceE retrieves the synapse workspace for the given subscription.
@@ -61,7 +61,7 @@ func GetSynapseWorkspaceE(t testing.TestingT, subscriptionID string, resGroupNam
6161
// GetSynapseSQLPoolContext retrieves the synapse SQL pool for the given subscription.
6262
// This function would fail the test if there is an error.
6363
// The ctx parameter supports cancellation and timeouts.
64-
func GetSynapseSQLPoolContext(t testing.TestingT, ctx context.Context, resGroupName string, workspaceName string, sqlPoolName string, subscriptionID string) *armsynapse.SQLPool {
64+
func GetSynapseSQLPoolContext(t testing.TestingT, ctx context.Context, subscriptionID string, resGroupName string, workspaceName string, sqlPoolName string) *armsynapse.SQLPool {
6565
t.Helper()
6666

6767
sqlPool, err := GetSynapseSQLPoolContextE(ctx, subscriptionID, resGroupName, workspaceName, sqlPoolName)
@@ -98,7 +98,7 @@ func GetSynapseSQLPoolWithClient(ctx context.Context, client *armsynapse.SQLPool
9898
func GetSynapseSQLPool(t testing.TestingT, resGroupName string, workspaceName string, sqlPoolName string, subscriptionID string) *armsynapse.SQLPool {
9999
t.Helper()
100100

101-
return GetSynapseSQLPoolContext(t, context.Background(), resGroupName, workspaceName, sqlPoolName, subscriptionID)
101+
return GetSynapseSQLPoolContext(t, context.Background(), subscriptionID, resGroupName, workspaceName, sqlPoolName)
102102
}
103103

104104
// GetSynapseSQLPoolE retrieves the synapse SQL pool for the given subscription.
@@ -115,7 +115,7 @@ func GetSynapseSQLPoolE(subscriptionID string, resGroupName string, workspaceNam
115115
func GetSynapseSqlPool(t testing.TestingT, resGroupName string, workspaceName string, sqlPoolName string, subscriptionID string) *armsynapse.SQLPool {
116116
t.Helper()
117117

118-
return GetSynapseSQLPoolContext(t, context.Background(), resGroupName, workspaceName, sqlPoolName, subscriptionID)
118+
return GetSynapseSQLPoolContext(t, context.Background(), subscriptionID, resGroupName, workspaceName, sqlPoolName)
119119
}
120120

121121
// GetSynapseSqlPoolE retrieves the synapse SQL pool for the given subscription.

test/azure/terraform_azure_datafactory_example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestTerraformAzureDataFactoryExample(t *testing.T) {
4545
assert.True(t, actualDataFactoryExits)
4646

4747
// Get data factory details and assert them against the terraform output
48-
actualDataFactory := azure.GetDataFactoryContext(t, t.Context(), expectedResourceGroupName, expectedDataFactoryName, "")
48+
actualDataFactory := azure.GetDataFactoryContext(t, t.Context(), "", expectedResourceGroupName, expectedDataFactoryName)
4949
assert.Equal(t, expectedDataFactoryName, *actualDataFactory.Name)
5050
assert.Equal(t, expectedDataFactoryProvisioningState, *actualDataFactory.Properties.ProvisioningState)
5151
}

test/azure/terraform_azure_mysqldb_example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ func TestTerraformAzureMySQLDBExample(t *testing.T) {
5252
expectedMYSQLDBName := terraform.OutputContext(t, t.Context(), terraformOptions, "mysql_database_name")
5353

5454
// website::tag::4:: Get mySQL server details and assert them against the terraform output
55-
actualMYSQLServer := azure.GetMYSQLServerContext(t, t.Context(), expectedResourceGroupName, expectedMYSQLServerName, "")
55+
actualMYSQLServer := azure.GetMYSQLServerContext(t, t.Context(), "", expectedResourceGroupName, expectedMYSQLServerName)
5656

5757
assert.Equal(t, expectedServerSkuName, *actualMYSQLServer.SKU.Name)
5858
assert.Equal(t, expectedServerStoragemMb, strconv.Itoa(int(*actualMYSQLServer.Properties.StorageProfile.StorageMB)))
5959

6060
assert.Equal(t, armmysql.ServerStateReady, *actualMYSQLServer.Properties.UserVisibleState)
6161

6262
// website::tag::5:: Get mySQL server DB details and assert them against the terraform output
63-
actualDatabase := azure.GetMYSQLDBContext(t, t.Context(), expectedResourceGroupName, expectedMYSQLServerName, expectedMYSQLDBName, "")
63+
actualDatabase := azure.GetMYSQLDBContext(t, t.Context(), "", expectedResourceGroupName, expectedMYSQLServerName, expectedMYSQLDBName)
6464

6565
assert.Equal(t, expectedDatabaseCharSet, *actualDatabase.Properties.Charset)
6666
assert.Equal(t, expectedDatabaseCollation, *actualDatabase.Properties.Collation)

0 commit comments

Comments
 (0)