Skip to content

Commit

Permalink
linting - new/updated linter violations (hashicorp#28505)
Browse files Browse the repository at this point in the history
* linting errors in tests

* fix testing linting

* fixup retryError returns - shouldn't silently return/succeed

* fixup flatten error return - should not silently return and skip rest of Read
  • Loading branch information
jackofallops authored and NotTheEvilOne committed Jan 20, 2025
1 parent 746b30c commit f492ebe
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 41 deletions.
27 changes: 8 additions & 19 deletions internal/provider/framework/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ func Test_getOidcToken(t *testing.T) {

if result == nil {
t.Fatalf("getOidcToken returned nil result without an error")
}

if *result != expectedString {
} else if *result != expectedString {
t.Fatalf("getOidcToken did not return expected string (%s), got %+v", expectedString, *result)
}
}
Expand All @@ -43,9 +41,7 @@ func Test_getOidcTokenFromFile(t *testing.T) {

if result == nil {
t.Fatalf("getOidcToken returned nil result without an error")
}

if *result != expectedString {
} else if *result != expectedString {
t.Fatalf("getOidcToken did not return expected string `%s`, got `%s`", expectedString, *result)
}
}
Expand Down Expand Up @@ -117,8 +113,7 @@ func Test_getClientSecret(t *testing.T) {
}
if result == nil {
t.Fatalf("getClientSecret returned nil result without an error")
}
if *result != expectedString {
} else if *result != expectedString {
t.Fatalf("getCLientSecret did not return expected string `%s`, got `%s`", expectedString, *result)
}
}
Expand Down Expand Up @@ -152,8 +147,7 @@ func Test_getClientSecretFromFile(t *testing.T) {
}
if result == nil {
t.Fatalf("getClientSecretFromFile returned nil result without an error")
}
if *result != expectedString {
} else if *result != expectedString {
t.Fatalf("getClientSecret did not return expected string `%s`, got `%s`", expectedString, *result)
}
}
Expand Down Expand Up @@ -185,8 +179,7 @@ func Test_getClientID(t *testing.T) {
}
if result == nil {
t.Fatalf("getClientID returned nil result without an error")
}
if *result != expectedString {
} else if *result != expectedString {
t.Fatalf("getClientID did not return expected string `%s`, got `%s`", expectedString, *result)
}
}
Expand Down Expand Up @@ -218,8 +211,7 @@ func Test_getClientIDFromFile(t *testing.T) {
}
if result == nil {
t.Fatalf("getClientID returned nil result without an error")
}
if *result != expectedString {
} else if *result != expectedString {
t.Fatalf("getClientID did not return expected string `%s`, got `%s`", expectedString, *result)
}
}
Expand All @@ -238,8 +230,7 @@ func Test_getClientIDAKSWorkload(t *testing.T) {
}
if result == nil {
t.Fatalf("getClientID returned nil result without an error")
}
if *result != expectedString {
} else if *result != expectedString {
t.Fatalf("getClientID did not return expected string `%s`, got `%s`", expectedString, *result)
}
}
Expand Down Expand Up @@ -270,9 +261,7 @@ func Test_decodeCertificate(t *testing.T) {
if err != nil {
t.Fatalf("decodeCertificate returned unexpected error %v", err)
}
if result == nil {
t.Fatalf("decodeCertificate returned nil result without an error")
}

if string(result) != expected {
t.Fatalf("decodeCertificate did not return expected result `%s`, got `%s`", expected, result)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/sdk/resource_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ func TestParseStructTags_WithValue(t *testing.T) {

if actual == nil {
t.Fatalf("expected actual to have a value but got nil")
}
if !reflect.DeepEqual(*data.expected, *actual) {
} else if !reflect.DeepEqual(*data.expected, *actual) {
t.Fatalf("expected [%+v] and actual [%+v] didn't match", *data.expected, *actual)
}
}
Expand Down
10 changes: 5 additions & 5 deletions internal/services/datafactory/data_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ func TestDataFactoryDeserializePipelineActivities(t *testing.T) {
t.Fatal(err)
}

if items == nil && !tc.ExpectErr {
t.Fatal("Expected items got nil")
}

if len(*items) != tc.ExpectActivityCount {
if items == nil {
if !tc.ExpectErr {
t.Fatal("Expected items got nil")
}
} else if len(*items) != tc.ExpectActivityCount {
t.Fatal("Failed to deserialise pipeline")
}
}
Expand Down
28 changes: 14 additions & 14 deletions internal/services/mssql/mssql_database_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,9 @@ func resourceMsSqlDatabaseCreate(d *pluginsdk.ResourceData, meta interface{}) er
state = transparentdataencryptions.TransparentDataEncryptionStateEnabled
}

tde, err := transparentEncryptionClient.Get(ctx, id)
if err != nil {
return fmt.Errorf("while retrieving Transparent Data Encryption state for %s: %+v", id, err)
tde, retryErr := transparentEncryptionClient.Get(ctx, id)
if retryErr != nil {
return fmt.Errorf("while retrieving Transparent Data Encryption state for %s: %+v", id, retryErr)
}

currentState := transparentdataencryptions.TransparentDataEncryptionStateDisabled
Expand All @@ -523,21 +523,21 @@ func resourceMsSqlDatabaseCreate(d *pluginsdk.ResourceData, meta interface{}) er

// Submit TDE state only when state is being changed, otherwise it can cause unwanted detection of state changes from the cloud side
if !strings.EqualFold(string(currentState), string(state)) {
input := transparentdataencryptions.LogicalDatabaseTransparentDataEncryption{
tdePayload := transparentdataencryptions.LogicalDatabaseTransparentDataEncryption{
Properties: &transparentdataencryptions.TransparentDataEncryptionProperties{
State: state,
},
}

if err := transparentEncryptionClient.CreateOrUpdateThenPoll(ctx, id, input); err != nil {
if err := transparentEncryptionClient.CreateOrUpdateThenPoll(ctx, id, tdePayload); err != nil {
return fmt.Errorf("while enabling Transparent Data Encryption for %q: %+v", id.String(), err)
}

// NOTE: Internal x-ref, this is another case of hashicorp/go-azure-sdk#307 so this can be removed once that's fixed
if err = pluginsdk.Retry(d.Timeout(pluginsdk.TimeoutCreate), func() *pluginsdk.RetryError {
c, err := client.Get(ctx, id, databases.DefaultGetOperationOptions())
if err != nil {
return pluginsdk.NonRetryableError(fmt.Errorf("while polling %s for status: %+v", id.String(), err))
if retryErr = pluginsdk.Retry(d.Timeout(pluginsdk.TimeoutCreate), func() *pluginsdk.RetryError {
c, err2 := client.Get(ctx, id, databases.DefaultGetOperationOptions())
if err2 != nil {
return pluginsdk.NonRetryableError(fmt.Errorf("while polling %s for status: %+v", id.String(), err2))
}
if c.Model != nil && c.Model.Properties != nil && c.Model.Properties.Status != nil {
if c.Model.Properties.Status == pointer.To(databases.DatabaseStatusScaling) {
Expand All @@ -548,8 +548,8 @@ func resourceMsSqlDatabaseCreate(d *pluginsdk.ResourceData, meta interface{}) er
}

return nil
}); err != nil {
return nil
}); retryErr != nil {
return retryErr
}
} else {
log.Print("[DEBUG] Skipping re-writing of Transparent Data Encryption, since encryption state is not changing ...")
Expand Down Expand Up @@ -597,7 +597,7 @@ func resourceMsSqlDatabaseCreate(d *pluginsdk.ResourceData, meta interface{}) er

return nil
}); err != nil {
return nil
return err
}

longTermRetentionPolicyProps := helper.ExpandLongTermRetentionPolicy(d.Get("long_term_retention_policy").([]interface{}))
Expand Down Expand Up @@ -1001,7 +1001,7 @@ func resourceMsSqlDatabaseUpdate(d *pluginsdk.ResourceData, meta interface{}) er
}
return nil
}); err != nil {
return nil
return err
}
}
}
Expand Down Expand Up @@ -1050,7 +1050,7 @@ func resourceMsSqlDatabaseUpdate(d *pluginsdk.ResourceData, meta interface{}) er

return nil
}); err != nil {
return nil
return err
}

if d.HasChange("long_term_retention_policy") {
Expand Down
2 changes: 1 addition & 1 deletion internal/services/network/private_endpoint_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ func resourcePrivateEndpointRead(d *pluginsdk.ResourceData, meta interface{}) er
for _, dnsZoneId := range *privateDnsZoneIds {
flattened, err := retrieveAndFlattenPrivateDnsZone(ctx, dnsClient, dnsZoneId)
if err != nil {
return nil
return fmt.Errorf("reading %s for %s: %+v", dnsZoneId, id, err)
}

// an exceptional case but no harm in handling
Expand Down

0 comments on commit f492ebe

Please sign in to comment.