Skip to content

Commit

Permalink
chore: Rewrite Codefresh pipeline to GH workflow for acceptance tests (
Browse files Browse the repository at this point in the history
…#166)

## Motivation

Rewrite Codefresh pipeline in GitHub workflow for acceptance tests.
The tests are now a reusable workflow and we can call them against main
environment from n9 repository.
  • Loading branch information
nieomylnieja authored Feb 15, 2024
1 parent 194820b commit 1b63496
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 88 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/acc-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Acceptance tests
on:
workflow_call:
inputs:
clientId:
description: Client ID to use for authentication
required: true
type: string
oktaOrgUrl:
description: Okta organization URL
required: false
type: string
oktaAuthServer:
description: Okta authentication server identifier
required: false
type: string
project:
description: Project name to create the tested objects in
required: false
type: string
secrets:
clientSecret:
description: Client secret to use for authentication
required: true
jobs:
test:
name: Run acceptance tests
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: false
- name: Run acceptance tests
env:
TERRAFORM_NOBL9_CLIENT_ID: "${{ secrets.clientId }}"
TERRAFORM_NOBL9_CLIENT_SECRET: "${{ secrets.clientSecret }}"
TERRAFORM_NOBL9_OKTA_ORG_URL: "${{ inputs.oktaOrgUrl }}"
TERRAFORM_NOBL9_OKTA_AUTH_SERVER: "${{ inputs.oktaAuthServer }}"
TERRAFORM_NOBL9_PROJECT: "${{ inputs.project }}"
run: make test/acc
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ jobs:
passphrase: ${{ secrets.PASSPHRASE }}
- name: setup github
run: git config --global url."https://n9-machine-user:${{ secrets.GH_TOKEN }}@github.com".insteadOf "https://github.com"
- name: Run acceptance tests
uses: ./.github/workflows/acc-tests.yml
with:
clientId: ${{ vars.TERRAFORM_NOBL9_CLIENT_ID }}
clientSecret: ${{ secrets.TERRAFORM_NOBL9_CLIENT_SECRET }}
project: ${{ vars.TERRAFORM_NOBL9_PROJECT }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5.0.0
with:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Tests
name: Unit tests
on:
push:
branches:
Expand All @@ -18,4 +18,4 @@ jobs:
go-version-file: go.mod
cache: false
- name: Run unit tests
run: make test
run: make test/unit
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,18 @@ install: build
build:
go build -ldflags $(BUILD_FLAGS) -o $(BINARY)

.PHONY: test
.PHONY: test test/unit test/acc
## Run all tests.
test: test/unit test/acc

## Run Go unit tests.
test:
test/unit:
go test -i $(TEST) || exit 1
echo $(TEST) | xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4

.PHONY: testacc
## Run acceptance tests.
testacc:
cd nobl9 && TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
## Run Terraform acceptance tests.
test/acc:
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m nobl9/

.PHONY: release-dry-run
## Run Goreleaser in dry-run mode.
Expand Down
41 changes: 0 additions & 41 deletions codefresh.yml

This file was deleted.

1 change: 0 additions & 1 deletion nobl9/data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func TestAcc_Nobl9DataSource(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: ProviderFactory(),
Steps: []resource.TestStep{
{
Expand Down
8 changes: 4 additions & 4 deletions nobl9/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func Provider() *schema.Provider {
"ingest_url": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("NOBL9_URL", "https://app.nobl9.com/api"),
DefaultFunc: schema.EnvDefaultFunc("NOBL9_URL", nil),
Description: "Nobl9 API URL.",
},

Expand All @@ -36,7 +36,7 @@ func Provider() *schema.Provider {
"project": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("NOBL9_PROJECT", sdk.DefaultProject),
DefaultFunc: schema.EnvDefaultFunc("NOBL9_PROJECT", nil),
Description: "Nobl9 project used when importing resources.",
},

Expand All @@ -58,15 +58,15 @@ func Provider() *schema.Provider {
"okta_org_url": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("NOBL9_OKTA_URL", "https://accounts.nobl9.com"),
DefaultFunc: schema.EnvDefaultFunc("NOBL9_OKTA_URL", nil),
Description: "Authorization service URL.",
},

"okta_auth_server": {
Type: schema.TypeString,
Optional: true,
//cspell:ignore auseg9kiegWKEtJZC416
DefaultFunc: schema.EnvDefaultFunc("NOBL9_OKTA_AUTH", "auseg9kiegWKEtJZC416"),
DefaultFunc: schema.EnvDefaultFunc("NOBL9_OKTA_AUTH", nil),
Description: "Authorization service configuration.",
},
},
Expand Down
27 changes: 3 additions & 24 deletions nobl9/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ var (
//nolint:gochecknoinits
func init() {
testProject = os.Getenv("NOBL9_PROJECT")
if testProject == "" {
testProject = "default"
}
}

func ProviderFactory() map[string]func() (*schema.Provider, error) {
Expand All @@ -43,30 +46,6 @@ func TestProvider(t *testing.T) {
}
}

func testAccPreCheck(t *testing.T) {
if err := os.Getenv("NOBL9_URL"); err == "" {
t.Fatal("NOBL9_URL must be set for acceptance tests")
}
if err := os.Getenv("NOBL9_ORG"); err == "" {
t.Fatal("NOBL9_ORG must be set for acceptance tests")
}
if err := os.Getenv("NOBL9_PROJECT"); err == "" {
t.Fatal("NOBL9_PROJECT must be set for acceptance tests")
}
if err := os.Getenv("NOBL9_CLIENT_ID"); err == "" {
t.Fatal("NOBL9_CLIENT_ID must be set for acceptance tests")
}
if err := os.Getenv("NOBL9_CLIENT_SECRET"); err == "" {
t.Fatal("NOBL9_CLIENT_SECRET must be set for acceptance tests")
}
if err := os.Getenv("NOBL9_OKTA_URL"); err == "" {
t.Fatal("NOBL9_OKTA_URL must be set for acceptance tests")
}
if err := os.Getenv("NOBL9_OKTA_AUTH"); err == "" {
t.Fatal("NOBL9_OKTA_AUTH must be set for acceptance tests")
}
}

func CheckObjectCreated(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
Expand Down
1 change: 0 additions & 1 deletion nobl9/resource_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func TestAcc_Nobl9Agent(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: ProviderFactory(),
CheckDestroy: CheckDestroy("nobl9_agent", manifest.KindAgent),
Steps: []resource.TestStep{
Expand Down
1 change: 0 additions & 1 deletion nobl9/resource_alert_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func TestAcc_Nobl9AlertPolicy(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: ProviderFactory(),
CheckDestroy: destroyMultiple(
[]string{"nobl9_alert_policy", "nobl9_alert_method_webhook"},
Expand Down
1 change: 0 additions & 1 deletion nobl9/resource_alertmethod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func TestAcc_Nobl9AlertMethod(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: ProviderFactory(),
CheckDestroy: CheckDestroy("nobl9_alert_method_"+tc.resourceSuffix, manifest.KindAlertMethod),
Steps: []resource.TestStep{
Expand Down
1 change: 0 additions & 1 deletion nobl9/resource_direct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func TestAcc_Nobl9Direct(t *testing.T) {
t.Run(tc.directType, func(t *testing.T) {
testName := strings.ReplaceAll("test-"+tc.directType, "_", "")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: ProviderFactory(),
CheckDestroy: CheckDestroy("nobl9_direct_%s", manifest.KindDirect),
Steps: []resource.TestStep{
Expand Down
2 changes: 0 additions & 2 deletions nobl9/resource_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ func TestAcc_Nobl9Project(t *testing.T) {
name := "test-project"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: ProviderFactory(),
CheckDestroy: CheckDestroy("nobl9_project", manifest.KindProject),
Steps: []resource.TestStep{
Expand All @@ -33,7 +32,6 @@ func TestAcc_NewNobl9ProjectReference(t *testing.T) {
name := "test-project"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: ProviderFactory(),
CheckDestroy: resource.ComposeTestCheckFunc(
CheckDestroy("nobl9_agent", manifest.KindAgent),
Expand Down
1 change: 0 additions & 1 deletion nobl9/resource_role_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func TestAcc_Nobl9RoleBinding(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: ProviderFactory(),
CheckDestroy: CheckDestroy("nobl9_role_binding", manifest.KindRoleBinding),
Steps: []resource.TestStep{
Expand Down
1 change: 0 additions & 1 deletion nobl9/resource_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

func TestAcc_Nobl9Service(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: ProviderFactory(),
CheckDestroy: CheckDestroy("nobl9_service", manifest.KindService),
Steps: []resource.TestStep{
Expand Down
2 changes: 0 additions & 2 deletions nobl9/resource_slo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func TestAcc_Nobl9SLO(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: ProviderFactory(),
CheckDestroy: CheckDestroy("nobl9_slo", manifest.KindSLO),
Steps: []resource.TestStep{
Expand Down Expand Up @@ -98,7 +97,6 @@ func TestAcc_Nobl9SLOErrors(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: ProviderFactory(),
CheckDestroy: CheckDestroy("nobl9_slo.", manifest.KindSLO),
Steps: []resource.TestStep{
Expand Down

0 comments on commit 1b63496

Please sign in to comment.