Dump controller logs after acceptance tests (#335)
* Dump logs * Incrase log verbosity * Fix lint * Add `LogConsumer` * Revert "Add `LogConsumer`" This reverts commit eba91831e11fd8b38343d14363fe553a3591377b. * Tidying * Minor tidying * Conditional guard * Minor * Fix * Fix * Dump logs in CI
This commit is contained in:
2
.github/workflows/acctest.yml
vendored
2
.github/workflows/acctest.yml
vendored
@@ -35,4 +35,4 @@ jobs:
|
||||
|
||||
- name: TF acceptance tests
|
||||
timeout-minutes: 20
|
||||
run: make testacc UNIFI_VERSION=${{ matrix.unifi_version }}
|
||||
run: make testacc UNIFI_STDOUT=true UNIFI_VERSION=${{ matrix.unifi_version }}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
@@ -14,7 +15,8 @@ import (
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
||||
"github.com/hashicorp/terraform-plugin-testing/terraform"
|
||||
"github.com/paultyng/go-unifi/unifi"
|
||||
tc "github.com/testcontainers/testcontainers-go/modules/compose"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/compose"
|
||||
)
|
||||
|
||||
var providerFactories = map[string]func() (*schema.Provider, error){
|
||||
@@ -35,7 +37,7 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func runAcceptanceTests(m *testing.M) int {
|
||||
compose, err := tc.NewDockerCompose("../../docker-compose.yaml")
|
||||
dc, err := compose.NewDockerCompose("../../docker-compose.yaml")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -43,21 +45,39 @@ func runAcceptanceTests(m *testing.M) int {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
if err = compose.WithOsEnv().Up(ctx, tc.Wait(true)); err != nil {
|
||||
if err = dc.WithOsEnv().Up(ctx, compose.Wait(true)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := compose.Down(context.Background(), tc.RemoveOrphans(true), tc.RemoveImagesLocal); err != nil {
|
||||
if err := dc.Down(context.Background(), compose.RemoveOrphans(true), compose.RemoveImagesLocal); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
container, err := compose.ServiceContainer(ctx, "unifi")
|
||||
container, err := dc.ServiceContainer(ctx, "unifi")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Dump the container logs on exit.
|
||||
//
|
||||
// TODO: Use https://pkg.go.dev/github.com/testcontainers/testcontainers-go#LogConsumer instead.
|
||||
defer func() {
|
||||
if os.Getenv("UNIFI_STDOUT") == "" {
|
||||
return
|
||||
}
|
||||
|
||||
stream, err := container.Logs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
buffer := new(bytes.Buffer)
|
||||
buffer.ReadFrom(stream)
|
||||
testcontainers.Logger.Printf("%s", buffer)
|
||||
}()
|
||||
|
||||
endpoint, err := container.PortEndpoint(ctx, "8443/tcp", "https")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
Reference in New Issue
Block a user