Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(swo_apitoken): Fix acceptance test for apitoken resource #84

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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