Skip to content

Commit

Permalink
test: refactored tests, added specific names
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-s committed Jul 30, 2024
1 parent 212e369 commit 77110f9
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 33 deletions.
7 changes: 4 additions & 3 deletions tests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"context"
"errors"
"fmt"
"github.com/google/uuid"
openapi_chaos_client "github.com/qernal/openapi-chaos-go-client"
"golang.org/x/oauth2/clientcredentials"
"math/rand"
"os"
"path/filepath"
"strings"

"github.com/google/uuid"
openapi_chaos_client "github.com/qernal/openapi-chaos-go-client"
"golang.org/x/oauth2/clientcredentials"
)

var (
Expand Down
1 change: 0 additions & 1 deletion tests/modules/environment_secret/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ output "secret_name" {
output "secret_value" {
value = qernal_secret_environment.example.value
}

13 changes: 9 additions & 4 deletions tests/modules/environment_secret/vars.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
variable "project_id" {
type = string
}

variable "project_id" {}
variable "secret_name" {
type = string
}

variable "secret_name" {}

variable "secret_value" {}
variable "secret_value" {
type = string
}
7 changes: 0 additions & 7 deletions tests/modules/org_datasource/main.tf

This file was deleted.

3 changes: 0 additions & 3 deletions tests/modules/org_datasource/vars.tf

This file was deleted.

11 changes: 11 additions & 0 deletions tests/modules/org_datasource_by_name/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
data "qernal_organisation" "org" {
name = var.org_name
}

output "organisation_id" {
value = data.qernal_organisation.org.id
}

output "organisation_name" {
value = data.qernal_organisation.org.name
}
3 changes: 3 additions & 0 deletions tests/modules/org_datasource_by_name/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "org_name" {
type = string
}
7 changes: 0 additions & 7 deletions tests/modules/project_datasource/main.tf

This file was deleted.

1 change: 0 additions & 1 deletion tests/modules/project_datasource/vars.tf

This file was deleted.

11 changes: 11 additions & 0 deletions tests/modules/project_datasource_by_name/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
data "qernal_project" "project" {
name = var.project_name
}

output "project_name" {
value = data.qernal_project.project.name
}

output "project_id" {
value = data.qernal_project.project.id
}
3 changes: 3 additions & 0 deletions tests/modules/project_datasource_by_name/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "project_id" {
type = string
}
8 changes: 5 additions & 3 deletions tests/qernal_organisation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ func TestValidOrg(t *testing.T) {
func TestOrganisationDataSource(t *testing.T) {
t.Parallel()

orgId, _, err := createOrg()
orgId, orgName, err := createOrg()
if err != nil {
t.Fatal("Failed to create org")
}

moduleName := "./modules/org_datasource"
moduleName := "./modules/org_datasource_by_name"

// Copy provider.tf
defer os.Remove(fmt.Sprintf("%s/provider.tf", moduleName))
Expand All @@ -72,7 +72,7 @@ func TestOrganisationDataSource(t *testing.T) {
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
TerraformDir: moduleName,
Vars: map[string]interface{}{
"org_id": orgId,
"org_name": orgName,
},
})

Expand All @@ -85,4 +85,6 @@ func TestOrganisationDataSource(t *testing.T) {
tfOrgID := terraform.Output(t, terraformOptions, "organisation_id")
assert.Equal(t, orgId, tfOrgID)

tfOrgName := terraform.Output(t, terraformOptions, "organisation_name")
assert.Equal(t, orgName, tfOrgName)
}
9 changes: 5 additions & 4 deletions tests/qernal_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func TestValidProject(t *testing.T) {
}

func TestProjectDataSource(t *testing.T) {

t.Parallel()

orgId, _, err := createOrg()
Expand All @@ -69,7 +68,7 @@ func TestProjectDataSource(t *testing.T) {
t.Fatal("Failed to create test org")
}
// define a project name and validate it in the response
moduleName := "./modules/project_datasource/"
moduleName := "./modules/project_datasource_by_name"

// copy provider.tf
defer os.Remove(fmt.Sprintf("%s/provider.tf", moduleName))
Expand All @@ -85,14 +84,16 @@ func TestProjectDataSource(t *testing.T) {
},
})

defer deleteProj(projectId)
defer deleteOrg(orgId)

defer deleteProj(projectId)
defer terraform.Destroy(t, terraformOptions)

terraform.InitAndApply(t, terraformOptions)

// validate output
tfProjectName := terraform.Output(t, terraformOptions, "project_name")
assert.Equal(t, projectName, tfProjectName)

tfProjectId := terraform.Output(t, terraformOptions, "project_id")
assert.Equal(t, projectId, tfProjectId)
}

0 comments on commit 77110f9

Please sign in to comment.