Skip to content

Commit

Permalink
Adding integration testing foundation
Browse files Browse the repository at this point in the history
# Conflicts:
#	examples/examples_test.go

Add health check and update checked-in examples version

Increase read timeout

Clean up and add testcontainer

# Conflicts:
#	go.work.sum

# Conflicts:
#	examples/go.mod

# Conflicts:
#	examples/examples_nodejs_test.go
#	examples/examples_test.go
#	examples/go.mod
#	examples/go.sum

gomodtidy

# Conflicts:
#	examples/go.mod
#	examples/go.sum

Update compose from docs

In some cases the project name "talos" conflicts with the provider name

Add configuration for integration tests

Update @types/node to 20

upgrade go deps

# Conflicts:
#	examples/go.mod
#	examples/go.sum

gomodtidy after rebase

# Conflicts:
#	examples/go.sum

Remove check for project id

gomodtidy again
  • Loading branch information
UnstoppableMango committed Nov 6, 2024
1 parent 0536f09 commit f13cb76
Show file tree
Hide file tree
Showing 9 changed files with 792 additions and 128 deletions.
3 changes: 2 additions & 1 deletion examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.pulumi/
**/bin/
node_modules/

package-lock.json
yarn.lock
29 changes: 15 additions & 14 deletions examples/examples_nodejs_test.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
//go:build nodejs || all
// +build nodejs all

package examples

import (
//"path"
"path/filepath"
"testing"

"github.com/pulumi/pulumi/pkg/v3/testing/integration"
"github.com/stretchr/testify/require"
)

// func TestAccWebserverNode(t *testing.T) {
// test := getJSBaseOptions(t).
// With(integration.ProgramTestOptions{
// Dir: path.Join(getCwd(t), "ts/server"),
// })
func TestSimpleTs(t *testing.T) {
require.NoError(t, startNodes(t), "failed to start docker nodes")

// integration.ProgramTest(t, &test)
// }
test := getJSBaseOptions(t).With(integration.ProgramTestOptions{
Dir: filepath.Join(getCwd(t), "typescript"),
Config: map[string]string{
"name": "exampleCluster",
"endpoint": "https://cluster.local:6443",
"node0": "10.6.0.2",
},
})
integration.ProgramTest(t, &test)
}

func getJSBaseOptions(t *testing.T) integration.ProgramTestOptions {
base := getBaseOptions(t)
baseJS := base.With(integration.ProgramTestOptions{
ExpectRefreshChanges: true,
Dependencies: []string{
"@pulumiverse/scaleway",
"@pulumiverse/talos",
},
})

Expand Down
46 changes: 33 additions & 13 deletions examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@
package examples

import (
"context"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
tc "github.com/testcontainers/testcontainers-go"
tcc "github.com/testcontainers/testcontainers-go/modules/compose"

"github.com/pulumi/pulumi/pkg/v3/testing/integration"
)

func getProjectId(t *testing.T) string {
name := os.Getenv("SCW_DEFAULT_PROJECT_ID")
if name == "" {
t.Skipf("Skipping test due to missing SCW_DEFAULT_PROJECT_ID environment variable")
}

return name
}

func getCwd(t *testing.T) string {
cwd, err := os.Getwd()
if err != nil {
Expand All @@ -28,10 +25,33 @@ func getCwd(t *testing.T) string {
}

func getBaseOptions(t *testing.T) integration.ProgramTestOptions {
project_id := getProjectId(t)
return integration.ProgramTestOptions{
Config: map[string]string{
"project_id": project_id,
},
LocalProviders: []integration.LocalDependency{{
Package: "talos",
Path: filepath.Join(getCwd(t), "..", "bin"),
}},
}
}

func startNodes(t *testing.T) error {
composePath := filepath.Join(getCwd(t), "testdata", "docker-compose.yaml")
compose, err := tcc.NewDockerComposeWith(
tcc.WithStackFiles(composePath),
tcc.WithLogger(tc.TestLogger(t)),
)
require.NoError(t, err)

t.Cleanup(func() {
err := compose.Down(context.Background(),
tcc.RemoveOrphans(true),
tcc.RemoveImagesLocal,
tcc.RemoveVolumes(true),
)
require.NoError(t, err)
})

ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)

return compose.Up(ctx, tcc.Wait(true))
}
Loading

0 comments on commit f13cb76

Please sign in to comment.