Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Acceptance test with test containers #40

Merged
merged 6 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cli-build-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: workflow_call

jobs:
test:
name: Setup broker for CLI Integration Test
name: Run Generator tests
runs-on: ubuntu-latest
steps:
- name: Set up Go
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/core-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ jobs:

Plugin-Integration-Test:
needs: build
uses: ./.github/workflows/plugin-build-pipeline.yml
uses: ./.github/workflows/provider-build-pipeline.yml
secrets: inherit

Plugin-Acceptance-Test:
needs: build
uses: ./.github/workflows/provider-acceptance-test.yml
secrets: inherit

CLI-Integration-Test:
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/provider-acceptance-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Provider Acceptance Test

on: workflow_call


jobs:
test:
name: Run formal acceptance test
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.20"

- name: Check out code
uses: actions/checkout@v3

- name: Acceptance test
run: |
make testacc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Terraform Plugin Pipeline
name: Terraform Provider Pipeline

on: workflow_call


jobs:
test:
name: Setup broker for terraform plugin pipeline
name: Run Provider setup and tests
runs-on: ubuntu-latest
steps:
- name: Set up Go
Expand Down
45 changes: 41 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ require (
github.com/cloudflare/circl v1.3.3 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
Expand Down Expand Up @@ -70,9 +70,46 @@ require (
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.11.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.56.1 // indirect
google.golang.org/grpc v1.57.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)

require github.com/testcontainers/testcontainers-go v0.24.1

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/containerd/containerd v1.7.6 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v24.0.6+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/moby/patternmatcher v0.5.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc4 // indirect
github.com/opencontainers/runc v1.1.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/shirou/gopsutil/v3 v3.23.7 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
)
155 changes: 145 additions & 10 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions internal/broker/generated/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import (
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestDataSource(t *testing.T) {
func TestAccDataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Read testing
{
Config: providerConfig + `
Config: ProviderConfig + `
data "solacebroker_msg_vpn" "default" {
msg_vpn_name = "default"
}
Expand Down
72 changes: 63 additions & 9 deletions internal/broker/generated/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,21 @@
package generated

import (
"os"
"terraform-provider-solacebroker/internal/broker"
"testing"

"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
)

const (
providerConfig = `
provider "solacebroker" {
username = "admin"
password = "admin"
url = "http://localhost:8080"
}
`
"context"

"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
)

var ProviderConfig string

var (
// testAccProtoV6ProviderFactories are used to instantiate a provider during
// acceptance testing. The factory function will be invoked for every Terraform
Expand All @@ -44,6 +42,62 @@ var (
}
)

func init() {
// start docker test broker
ctx := context.Background()
req := testcontainers.ContainerRequest{
Image: "solace/solace-pubsub-standard:latest",
ExposedPorts: []string{"8080/tcp"},
Env: map[string]string{
"username_admin_globalaccesslevel": "admin",
"username_admin_password": "admin",
"system_scaling_maxconnectioncount": "100",
},
Mounts: testcontainers.ContainerMounts{
{
Source: testcontainers.GenericVolumeMountSource{
Name: "test-volume",
},
Target: "/var/lib/solace",
},
},
ShmSize: 1000000000,
WaitingFor: wait.ForHTTP("/").WithPort("8080/tcp"),
}
solaceC, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: req,
Started: true,
})
if err != nil {
panic(err)
}
endpoint, err := solaceC.Endpoint(ctx, "")
if err != nil {
panic(err)
}
ProviderConfig = `
provider "solacebroker" {
username = "admin"
password = "admin"
url = "http://` + endpoint + `"
}
`
const user = "admin"
const password = "admin"

if err = os.Setenv("SOLACEBROKER_URL", "http://" + endpoint); err != nil {
panic(err)
}

if err = os.Setenv("SOLACEBROKER_USERNAME", password); err != nil {
panic(err)
}

if err = os.Setenv("SOLACEBROKER_PASSWORD", password); err != nil {
panic(err)
}
}

func testAccPreCheck(t *testing.T) {
// You can add code here to run prior to any test case execution, for example assertions
// about the appropriate environment variables being set are common to see in a pre-check
Expand Down
4 changes: 2 additions & 2 deletions internal/broker/generated/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestAccResource(t *testing.T) {
Steps: []resource.TestStep{
// Create and Read testing
{
Config: providerConfig + `
Config: ProviderConfig + `
resource "solacebroker_msg_vpn" "test" {
msg_vpn_name = "test"
enabled = true
Expand All @@ -43,7 +43,7 @@ resource "solacebroker_msg_vpn" "test" {
},
// Update and Read testing
{
Config: providerConfig + `
Config: ProviderConfig + `
resource "solacebroker_msg_vpn" "test" {
msg_vpn_name = "test"
enabled = true
Expand Down