diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43ec70a..acddf60 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,31 @@ jobs: - name: Build uses: ./.github/actions/ci/build + acc_test: + name: Acceptance Tests + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + - name: Setup Repo + uses: ./.github/actions/ci/setup + - name: Install Descope CLI + uses: descope/descopecli/.github/actions/install@v0.8.10 + - name: Run Acceptance Tests + shell: bash + env: + DESCOPE_PROJECT_ID: ${{ secrets.DESCOPE_PROJECT_ID }} + DESCOPE_MANAGEMENT_KEY: ${{ secrets.DESCOPE_MANAGEMENT_KEY }} + DESCOPE_BASE_URL: https://api.descope.com + TF_ACC: 1 + run: | + echo "Running acceptance tests" + set +e + go test -v ./... + result=$? + descope project list | grep '"name":"testacc-.*' | sed -e 's/.*"id":"\([^"]*\)".*/\1/' | xargs -I {} descope project delete {} --force + exit $result + lint: name: Run Linter runs-on: ubuntu-latest diff --git a/internal/models/project.go b/internal/models/project.go index a8c0061..7b02bcb 100644 --- a/internal/models/project.go +++ b/internal/models/project.go @@ -24,7 +24,7 @@ import ( var ProjectAttributes = map[string]schema.Attribute{ "id": stringattr.Identifier(), "name": stringattr.Required(), - "environment": stringattr.Optional(stringvalidator.OneOf("production")), + "environment": stringattr.Optional(stringvalidator.OneOf("", "production")), "project_settings": objectattr.Optional(settings.SettingsAttributes), "authentication": objectattr.Optional(authentication.AuthenticationAttributes), "authorization": objectattr.Optional(authorization.AuthorizationAttributes, authorization.AuthorizationValidator), diff --git a/internal/models/project_test.go b/internal/models/project_test.go index fbe7600..30471c5 100644 --- a/internal/models/project_test.go +++ b/internal/models/project_test.go @@ -23,8 +23,8 @@ func TestProject(t *testing.T) { `), Check: p.Check(map[string]any{ "id": testacc.AttributeIsSet, - "environment": "production", "name": p.Name, + "environment": "production", }), }, resource.TestStep{ diff --git a/tools/testacc/project.go b/tools/testacc/project.go index e8291be..fe313e6 100644 --- a/tools/testacc/project.go +++ b/tools/testacc/project.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" "testing" + "time" "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -11,11 +12,17 @@ import ( ) func Project(t *testing.T) *ProjectResource { + test := strings.TrimPrefix(t.Name(), "Test") + + time := time.Now().Format("01021504") // MMddHHmm + uuid, err := uuid.GenerateUUID() require.NoError(t, err) + suffix := uuid[len(uuid)-8:] + return &ProjectResource{ - Resource: Resource{Type: "descope_project", Name: "test"}, - Name: fmt.Sprintf("testacc-%s-%s", t.Name(), strings.ReplaceAll(uuid, "-", "")), + Resource: Resource{Type: "descope_project", Name: "testproj"}, + Name: fmt.Sprintf("testacc-%s-%s-%s", test, time, suffix), } }