Skip to content

Commit

Permalink
Further fixes to test
Browse files Browse the repository at this point in the history
  • Loading branch information
julienduchesne committed Mar 2, 2024
1 parent cb26648 commit 1716fe8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cloud_test
import (
"context"
"fmt"
"strings"
"testing"

"github.com/grafana/grafana-com-public-clients/go/gcom"
Expand Down Expand Up @@ -87,24 +86,14 @@ func testAccGrafanaAuthCheckServiceAccounts(stack *gcom.FormattedApiInstance, ex
return fmt.Errorf("failed to get service accounts: %w", err)
}

var foundSAs []string
for _, sa := range response.Payload.ServiceAccounts {
if !strings.HasPrefix(sa.Name, "test-api-key-") {
foundSAs = append(foundSAs, sa.Name)
if sa.Tokens == 0 {
return fmt.Errorf("expected to find at least one token for service account %s", sa.Name)
}
}
}

if len(foundSAs) != len(expectedSAs) {
return fmt.Errorf("expected %d keys, got %d", len(expectedSAs), len(foundSAs))
}
for _, expectedSA := range expectedSAs {
found := false
for _, foundSA := range foundSAs {
if expectedSA == foundSA {
for _, sa := range response.Payload.ServiceAccounts {
if sa.Name == expectedSA {
found = true
if sa.Tokens == 0 {
return fmt.Errorf("expected to find at least one token for service account %s", sa.Name)
}
break
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ func stackServiceAccountTokenCreate(ctx context.Context, d *schema.ResourceData,
}
defer cleanup()

serviceAccountID, err := strconv.ParseInt(d.Get("service_account_id").(string), 10, 64)
split, err := resourceStackServiceAccountID.Split(d.Get("service_account_id").(string))
if err != nil {
return diag.FromErr(err)
}
serviceAccountID := split[1].(int64)

name := d.Get("name").(string)
ttl := d.Get("seconds_to_live").(int)
Expand Down Expand Up @@ -121,10 +122,11 @@ func stackServiceAccountTokenRead(ctx context.Context, d *schema.ResourceData, c
}

func stackServiceAccountTokenReadWithClient(c *goapi.GrafanaHTTPAPI, d *schema.ResourceData) diag.Diagnostics {
serviceAccountID, err := strconv.ParseInt(d.Get("service_account_id").(string), 10, 64)
split, err := resourceStackServiceAccountID.Split(d.Get("service_account_id").(string))
if err != nil {
return diag.FromErr(err)
}
serviceAccountID := split[1].(int64)

response, err := c.ServiceAccounts.ListTokens(serviceAccountID)
if err != nil {
Expand Down Expand Up @@ -167,10 +169,11 @@ func stackServiceAccountTokenDelete(ctx context.Context, d *schema.ResourceData,
}
defer cleanup()

serviceAccountID, err := strconv.ParseInt(d.Get("service_account_id").(string), 10, 64)
split, err := resourceStackServiceAccountID.Split(d.Get("service_account_id").(string))
if err != nil {
return diag.FromErr(err)
}
serviceAccountID := split[1].(int64)

id, err := strconv.ParseInt(d.Id(), 10, 32)
if err != nil {
Expand Down

0 comments on commit 1716fe8

Please sign in to comment.