From 3a7c52e175a1c794a95ea7c8aeb9186e3308de14 Mon Sep 17 00:00:00 2001 From: Chris Weyl Date: Thu, 3 Feb 2022 14:16:47 -0600 Subject: [PATCH] Add tests for `gitlabci_runner_token` resource ...not comprehensive, but a start. --- .../resource_gitlabci_runner_token_test.go | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 internal/provider/resource_gitlabci_runner_token_test.go diff --git a/internal/provider/resource_gitlabci_runner_token_test.go b/internal/provider/resource_gitlabci_runner_token_test.go new file mode 100644 index 0000000..45cc5d4 --- /dev/null +++ b/internal/provider/resource_gitlabci_runner_token_test.go @@ -0,0 +1,39 @@ +package provider + +import ( + "fmt" + "os" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccResourceRunnerToken(t *testing.T) { + + token := os.Getenv("RUNNER_REGISTRATION_TOKEN") + if token == "" { + t.Skip("$RUNNER_REGISTRATION_TOKEN not set; skipping registration tests") + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: providerFactories, + Steps: []resource.TestStep{ + { + Config: fmt.Sprintf(testAccResourceRunnerToken, token), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("gitlabci_runner_token.foo", "token"), + resource.TestCheckResourceAttrSet("gitlabci_runner_token.foo", "runner_id"), + resource.TestMatchResourceAttr("gitlabci_runner_token.foo", "runner_id", regexp.MustCompile(`^\d+$`)), + ), + }, + }, + }) +} + +const testAccResourceRunnerToken = ` +resource "gitlabci_runner_token" "foo" { + registration_token = "%s" +} +`