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

Add integration tests #88

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
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
Loading