-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: tests and examples added for service accounts
- Loading branch information
Showing
17 changed files
with
257 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,9 @@ jobs: | |
CDK_BASE_URL: http://localhost:8080 | ||
CDK_ADMIN_EMAIL: [email protected] | ||
CDK_ADMIN_PASSWORD: testP4ss! | ||
CDK_GATEWAY_BASE_URL: http://localhost:8888 | ||
CDK_GATEWAY_USER: admin | ||
CDK_GATEWAY_PASSWORD: conduktor | ||
TF_LOG_PROVIDER_CONDUKTOR: DEBUG | ||
timeout-minutes: 15 | ||
run: | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
examples/resources/conduktor_gateway_service_account_v2/complex.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
resource "conduktor_gateway_service_account_v2" "example" { | ||
name = "complex-service-account" | ||
# vcluster = "vcluster1" | ||
spec { | ||
type = "EXTERNAL" | ||
external_names = ["externalName"] | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
examples/resources/conduktor_gateway_service_account_v2/simple.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
resource "conduktor_gateway_service_account_v2" "example" { | ||
name = "simple-service-account" | ||
spec { | ||
type = "LOCAL" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...rnal/mapper/gateway_service_account_v2/gateway_service_account_v2_resource_mapper_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package gateway_service_account_v2 | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
ctlresource "github.com/conduktor/ctl/resource" | ||
"github.com/conduktor/terraform-provider-conduktor/internal/model" | ||
"github.com/conduktor/terraform-provider-conduktor/internal/test" | ||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGatewayServiceAccountV2ModelMapping(t *testing.T) { | ||
|
||
ctx := context.Background() | ||
|
||
jsonServiceAccountV2Resource := []byte(test.TestAccTestdata(t, "gateway_service_account_v2_api.json")) | ||
|
||
ctlResource := ctlresource.Resource{} | ||
err := ctlResource.UnmarshalJSON(jsonServiceAccountV2Resource) | ||
if err != nil { | ||
t.Fatal(err) | ||
return | ||
} | ||
assert.Equal(t, "GatewayServiceAccount", ctlResource.Kind) | ||
assert.Equal(t, "gateway/v2", ctlResource.Version) | ||
assert.Equal(t, "user1", ctlResource.Name) | ||
assert.Equal(t, map[string]interface{}{"name": "user1", "vCluster": "vcluster1"}, ctlResource.Metadata) | ||
assert.Equal(t, jsonServiceAccountV2Resource, ctlResource.Json) | ||
|
||
// convert into internal model | ||
internal, err := model.NewGatewayServiceAccountResourceFromClientResource(ctlResource) | ||
if err != nil { | ||
t.Fatal(err) | ||
return | ||
} | ||
assert.Equal(t, "GatewayServiceAccount", internal.Kind) | ||
assert.Equal(t, "gateway/v2", internal.ApiVersion) | ||
assert.Equal(t, "user1", internal.Metadata.Name) | ||
assert.Equal(t, "EXTERNAL", internal.Spec.Type) | ||
assert.Equal(t, []string{"externalName"}, internal.Spec.ExternalNames) | ||
|
||
// convert to terraform model | ||
tfModel, err := InternalModelToTerraform(ctx, &internal) | ||
if err != nil { | ||
t.Fatal(err) | ||
return | ||
} | ||
assert.Equal(t, types.StringValue("user1"), tfModel.Name) | ||
assert.Equal(t, types.StringValue("EXTERNAL"), tfModel.Spec.SpecType) | ||
// do not test ExternalNames as it's a pain to parse SetValue | ||
|
||
// convert back to internal model | ||
internal2, err := TFToInternalModel(ctx, &tfModel) | ||
if err != nil { | ||
t.Fatal(err) | ||
return | ||
} | ||
assert.Equal(t, "GatewayServiceAccount", internal2.Kind) | ||
assert.Equal(t, "gateway/v2", internal2.ApiVersion) | ||
assert.Equal(t, "user1", internal2.Metadata.Name) | ||
assert.Equal(t, "vcluster1", internal2.Metadata.VCluster) | ||
assert.Equal(t, "EXTERNAL", internal2.Spec.Type) | ||
assert.Equal(t, []string{"externalName"}, internal2.Spec.ExternalNames) | ||
|
||
// convert back to ctl model | ||
ctlResource2, err := internal2.ToClientResource() | ||
if err != nil { | ||
t.Fatal(err) | ||
return | ||
} | ||
// compare without json | ||
if !cmp.Equal(ctlResource, ctlResource2, cmpopts.IgnoreFields(ctlresource.Resource{}, "Json")) { | ||
t.Errorf("expected %+v, got %+v", ctlResource, ctlResource2) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
internal/provider/gateway_service_account_v2_resource_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package provider | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/conduktor/terraform-provider-conduktor/internal/test" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestAccGatewayServiceAccountV2Resource(t *testing.T) { | ||
test.CheckEnterpriseEnabled(t) | ||
resourceRef := "conduktor_gateway_service_account_v2.test" | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { test.TestAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Create and Read testing | ||
{ | ||
Config: providerConfig + test.TestAccTestdata(t, "gateway_service_account_v2_resource_create.tf"), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr(resourceRef, "name", "user1"), | ||
resource.TestCheckResourceAttr(resourceRef, "vcluster", "passthrough"), | ||
resource.TestCheckResourceAttr(resourceRef, "spec.type", "EXTERNAL"), | ||
resource.TestCheckResourceAttr(resourceRef, "spec.external_names.#", "1"), | ||
resource.TestCheckResourceAttr(resourceRef, "spec.external_names.0", "externalName"), | ||
), | ||
}, | ||
// Importing matches the state of the previous step. | ||
{ | ||
ResourceName: resourceRef, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateId: "user1", | ||
ImportStateVerifyIdentifierAttribute: "name", | ||
}, | ||
// Update and Read testing | ||
{ | ||
Config: providerConfig + test.TestAccTestdata(t, "gateway_service_account_v2_resource_update.tf"), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr(resourceRef, "name", "user1"), | ||
resource.TestCheckResourceAttr(resourceRef, "vcluster", "passthrough"), | ||
resource.TestCheckResourceAttr(resourceRef, "spec.type", "EXTERNAL"), | ||
resource.TestCheckResourceAttr(resourceRef, "spec.external_names.#", "1"), | ||
resource.TestCheckResourceAttr(resourceRef, "spec.external_names.0", "newExternalName"), | ||
), | ||
}, | ||
// Delete testing automatically occurs in TestCase | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccGatewayServiceAccountV2Minimal(t *testing.T) { | ||
test.CheckEnterpriseEnabled(t) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { test.TestAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Create and Read from minimal example | ||
{ | ||
Config: providerConfig + test.TestAccTestdata(t, "gateway_service_account_v2_resource_minimal.tf"), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.minimal", "name", "minimal"), | ||
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.minimal", "vcluster", "passthrough"), | ||
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.minimal", "spec.type", "LOCAL"), | ||
), | ||
}, | ||
// Delete testing automatically occurs in TestCase | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccGatewayServiceAccountV2ExampleResource(t *testing.T) { | ||
test.CheckEnterpriseEnabled(t) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { test.TestAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
|
||
Steps: []resource.TestStep{ | ||
// Create and Read from simple example | ||
{ | ||
Config: providerConfig + test.TestAccExample(t, "resources", "conduktor_gateway_service_account_v2", "simple.tf"), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.example", "name", "simple-service-account"), | ||
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.example", "vcluster", "passthrough"), | ||
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.example", "spec.type", "LOCAL"), | ||
), | ||
}, | ||
// Create and Read from complex example | ||
{ | ||
Config: providerConfig + test.TestAccExample(t, "resources", "conduktor_gateway_service_account_v2", "complex.tf"), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.example", "name", "complex-service-account"), | ||
// TODO: Add vcluster tests - Needs gateway_vclusters to be deployed by terraform | ||
// resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.example", "vcluster", "vcluster1"), | ||
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.example", "spec.type", "EXTERNAL"), | ||
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.example", "spec.external_names.#", "1"), | ||
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.example", "spec.external_names.0", "externalName"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
4 changes: 2 additions & 2 deletions
4
...nal/schema/resource_gateway_service_account_v2/gateway_service_account_v2_resource_gen.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"kind": "GatewayServiceAccount", | ||
"apiVersion": "gateway/v2", | ||
"metadata": { | ||
"name": "user1", | ||
"vCluster": "vcluster1" | ||
}, | ||
"spec": { | ||
"type": "EXTERNAL", | ||
"externalNames": [ | ||
"externalName" | ||
] | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
internal/testdata/gateway_service_account_v2_resource_create.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
resource "conduktor_gateway_service_account_v2" "test" { | ||
name = "user1" | ||
spec { | ||
type = "EXTERNAL" | ||
external_names = ["externalName"] | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
internal/testdata/gateway_service_account_v2_resource_minimal.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
resource "conduktor_gateway_service_account_v2" "minimal" { | ||
name = "minimal" | ||
spec { | ||
type = "LOCAL" | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
internal/testdata/gateway_service_account_v2_resource_update.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
resource "conduktor_gateway_service_account_v2" "test" { | ||
name = "user1" | ||
spec { | ||
type = "EXTERNAL" | ||
external_names = ["newExternalName"] | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters