Skip to content

Commit

Permalink
feat(ci): Run acceptance tests (#23)
Browse files Browse the repository at this point in the history
* fix: run acc tests in ci

* move to dedicated job

* fix

* Update tests

* Run cleanup after tests

---------

Co-authored-by: Gil Shapira <gshapira@gmail.com>
  • Loading branch information
omercnet and shilgapira authored Oct 6, 2024
1 parent 7aaafc9 commit ef00ce9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/models/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion internal/models/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
11 changes: 9 additions & 2 deletions tools/testacc/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,25 @@ import (
"fmt"
"strings"
"testing"
"time"

"github.com/hashicorp/go-uuid"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/stretchr/testify/require"
)

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),
}
}

Expand Down

0 comments on commit ef00ce9

Please sign in to comment.