Skip to content

Commit

Permalink
test(swo_apitoken): Fix acceptance test for apitoken resource (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
grepory authored Aug 29, 2024
1 parent 71bfc0d commit 8d5eb94
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ default: testacc
# Run acceptance tests
.PHONY: testacc
testacc:
TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120m
TF_LOG=info TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120m
11 changes: 6 additions & 5 deletions internal/provider/api_token_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ func TestAccApiTokenResource(t *testing.T) {
},
// ImportState testing
{
ResourceName: "swo_apitoken.test",
ImportState: true,
ImportStateVerify: true,
ResourceName: "swo_apitoken.test",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"token"},
},
// Update and Read testing
{
Expand All @@ -41,9 +42,9 @@ func TestAccApiTokenResource(t *testing.T) {

func testAccApiTokenResourceConfig(name string) string {
return providerConfig() + fmt.Sprintf(`
resource "swo_apitoken" "test_uri" {
resource "swo_apitoken" "test" {
name = %[1]q
access_level = "READ"
access_level = "API_FULL"
type = "public-api"
enabled = true
attributes = [
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/api_token_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func (r *apiTokenResource) Schema(ctx context.Context, req resource.SchemaReques
validators.SingleOption(
swoClient.TokenAccessLevelFull,
swoClient.TokenAccessLevelRead,
swoClient.TokenAccessLevelRecord),
swoClient.TokenAccessLevelRecord,
"API_FULL"),
},
},
"attributes": schema.SetNestedAttribute{
Expand Down
14 changes: 12 additions & 2 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provider

import (
"fmt"
"log"
"os"
"testing"

Expand All @@ -10,12 +11,21 @@ import (
)

func providerConfig() string {
apiToken := os.Getenv("SWO_API_TOKEN")
if apiToken == "" {
log.Fatal("SWO_API_TOKEN must be set for acceptance tests")
}

baseURL := os.Getenv("SWO_BASE_URL")
if baseURL == "" {
log.Fatal("SWO_BASE_URL must be set for acceptance tests")
}

return fmt.Sprintf(`provider "swo" {
api_token = "%s"
request_timeout = 10
base_url = "%s"
debug_mode = true
}`, os.Getenv("SWO_API_TOKEN"), os.Getenv("SWO_BASE_URL"))
}`, apiToken, baseURL)
}

// testAccProtoV6ProviderFactories are used to instantiate a provider during
Expand Down

0 comments on commit 8d5eb94

Please sign in to comment.