Skip to content

Commit

Permalink
Starting work on acceptance tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tzrlk committed Aug 4, 2024
1 parent 8b13c7c commit f82c54d
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 17 deletions.
20 changes: 12 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ go 1.22
toolchain go1.22.5

require (
github.com/brianvoe/gofakeit/v7 v7.0.4
github.com/golangci/golangci-lint v1.59.1
github.com/hashicorp/terraform-plugin-docs v0.19.4
github.com/hashicorp/terraform-plugin-framework v1.10.0
github.com/hashicorp/terraform-plugin-framework-timetypes v0.4.0
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0
github.com/hashicorp/terraform-plugin-go v0.23.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/oapi-codegen/oapi-codegen/v2 v2.3.0
github.com/oapi-codegen/runtime v1.1.1
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
)

require (
github.com/brianvoe/gofakeit/v7 v7.0.4
github.com/golangci/golangci-lint v1.59.1
github.com/hashicorp/terraform-plugin-docs v0.19.4
github.com/hashicorp/terraform-plugin-testing v1.9.0
github.com/oapi-codegen/oapi-codegen/v2 v2.3.0
github.com/onsi/gomega v1.33.1
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
)

require (
Expand Down Expand Up @@ -235,12 +239,12 @@ require (
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp/typeparams v0.0.0-20240314144324-c7f7c6466f7f // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.22.0 // indirect
golang.org/x/tools v0.23.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.34.0 // indirect
Expand Down
17 changes: 9 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ github.com/hashicorp/terraform-plugin-go v0.23.0 h1:AALVuU1gD1kPb48aPQUjug9Ir/12
github.com/hashicorp/terraform-plugin-go v0.23.0/go.mod h1:1E3Cr9h2vMlahWMbsSEcNrOCxovCZhOOIXjFHbjc/lQ=
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow=
github.com/hashicorp/terraform-plugin-testing v1.9.0/go.mod h1:fhhVx/8+XNJZTD5o3b4stfZ6+q7z9+lIWigIYdT6/44=
github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI=
github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM=
github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ=
Expand Down Expand Up @@ -772,8 +773,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc h1:ao2WRsKSzW6KuUY9IWPwWahcHCgR0s52IfwutMfEbdM=
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/exp/typeparams v0.0.0-20220428152302-39d4317da171/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
golang.org/x/exp/typeparams v0.0.0-20230203172020-98cc5a0785f9/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
golang.org/x/exp/typeparams v0.0.0-20240314144324-c7f7c6466f7f h1:phY1HzDcf18Aq9A8KkmRtY9WvOFIxN8wgfvy6Zm1DV8=
Expand Down Expand Up @@ -806,8 +807,8 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91
golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI=
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -846,8 +847,8 @@ golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -1011,8 +1012,8 @@ golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA=
golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k=
golang.org/x/tools v0.5.0/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
23 changes: 22 additions & 1 deletion internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net/http"
"os"
"terraform-provider-idmc/internal/idmc/common"
"terraform-provider-idmc/internal/utils"
"testing"
Expand All @@ -21,7 +22,7 @@ import (
// acceptance testing. The factory function will be invoked for every Terraform
// CLI command executed to create a provider server to which the CLI can
// reattach.
var _ = map[string]func() (tfprotov6.ProviderServer, error){
var testAccProviders = map[string]func() (tfprotov6.ProviderServer, error){
"idmc": providerserver.NewProtocol6WithError(New("test")()),
}

Expand Down Expand Up @@ -85,3 +86,23 @@ func TestDoLogin(t *testing.T) {
Expect(sessionId).To(Equal(fakeSessionId))

}


func testAccPreCheck(t *testing.T) func() {
return func() {
requireEnv(t, "TF_AUTH_HOST", "TF_AUTH_USER", "TF_AUTH_PASS")
}
}

func requireEnv(t *testing.T, keys ...string) {
failed := false
for _, key := range keys {
if val := os.Getenv(key); val == "" {
t.Log("Missing environment variable: " + key)
failed = true
}
}
if failed {
t.FailNow()
}
}
52 changes: 52 additions & 0 deletions internal/provider/runtime_environment_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package provider

import (
"github.com/hashicorp/terraform-plugin-testing/config"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"testing"

. "github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestAccRuntimeEnvironment(t *testing.T) {
envName := acctest.RandomWithPrefix("test_env_")
ParallelTest(t, TestCase{

Check failure on line 13 in internal/provider/runtime_environment_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: ParallelTest (typecheck)
ProtoV6ProviderFactories: testAccProviders,
PreCheck: testAccPreCheck(t),
Steps: []TestStep{

Check failure on line 16 in internal/provider/runtime_environment_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: TestStep (typecheck)
{ // Create
ConfigFile: config.StaticFile("examples/resources/idmc_runtime_environment/resource.tf"),
ConfigVariables: map[string]config.Variable{
"name": config.StringVariable(envName),
"shared": config.BoolVariable(false),
},
Check: ComposeAggregateTestCheckFunc(

Check failure on line 23 in internal/provider/runtime_environment_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: ComposeAggregateTestCheckFunc (typecheck)
TestCheckResourceAttr("idmc_runtime_environment.example", "name", envName),

Check failure on line 24 in internal/provider/runtime_environment_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: TestCheckResourceAttr (typecheck)
TestCheckResourceAttr("idmc_runtime_environment.example", "shared", "false"),

Check failure on line 25 in internal/provider/runtime_environment_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: TestCheckResourceAttr (typecheck)
),
},
{ // Change name
ConfigFile: config.StaticFile("examples/resources/idmc_runtime_environment/resource.tf"),
ConfigVariables: map[string]config.Variable{
"name": config.StringVariable(envName + "_changed"),
"shared": config.BoolVariable(false),
},
Check: ComposeAggregateTestCheckFunc(

Check failure on line 34 in internal/provider/runtime_environment_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: ComposeAggregateTestCheckFunc (typecheck)
TestCheckResourceAttr("idmc_runtime_environment.example", "name", envName + "_changed"),

Check failure on line 35 in internal/provider/runtime_environment_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: TestCheckResourceAttr (typecheck)
TestCheckResourceAttr("idmc_runtime_environment.example", "shared", "false"),

Check failure on line 36 in internal/provider/runtime_environment_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: TestCheckResourceAttr (typecheck)
),
},
{ // Change shared
ConfigFile: config.StaticFile("examples/resources/idmc_runtime_environment/resource.tf"),
ConfigVariables: map[string]config.Variable{
"name": config.StringVariable(envName + "_changed"),
"shared": config.BoolVariable(true),
},
Check: ComposeAggregateTestCheckFunc(

Check failure on line 45 in internal/provider/runtime_environment_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: ComposeAggregateTestCheckFunc (typecheck)
TestCheckResourceAttr("idmc_runtime_environment.example", "name", envName),

Check failure on line 46 in internal/provider/runtime_environment_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: TestCheckResourceAttr (typecheck)
TestCheckResourceAttr("idmc_runtime_environment.example", "shared", "true"),
),
},
},
})
}

0 comments on commit f82c54d

Please sign in to comment.