github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/integration/integration_dummy_test.go (about)

     1  //go:build integration
     2  // +build integration
     3  
     4  // can be executed with
     5  // go test -v -tags integration -run TestAPICLIIntegration ./integration/...
     6  
     7  package main
     8  
     9  import (
    10  	"context"
    11  	"os"
    12  	"path/filepath"
    13  	"testing"
    14  
    15  	"github.com/stretchr/testify/assert"
    16  	"github.com/testcontainers/testcontainers-go"
    17  )
    18  
    19  func TestDummyIntegration(t *testing.T) {
    20  	t.Skip("Skipping testing - this is just to show how it can be done")
    21  	ctx := context.Background()
    22  
    23  	dir, err := os.Getwd()
    24  	assert.NoError(t, err, "Getting current working directory failed.")
    25  	dir = filepath.Dir(dir)
    26  
    27  	req := testcontainers.ContainerRequest{
    28  		Image:      "node:lts-buster",
    29  		Cmd:        []string{"tail", "-f"},
    30  		BindMounts: map[string]string{dir: "/data"},
    31  		//ToDo: we may set up a tmp directory and mount it in addition, e.g. for runtime artifacts ...
    32  	}
    33  
    34  	testContainer, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
    35  		ContainerRequest: req,
    36  		Started:          true,
    37  	})
    38  	assert.NoError(t, err)
    39  
    40  	piperOptions := []string{
    41  		"<piperStep>",
    42  		"-- <piperFlag1>",
    43  		"<piperFlag1Value>",
    44  		"...",
    45  		"--noTelemetry",
    46  	}
    47  
    48  	code, err := testContainer.Exec(ctx, append([]string{"/data/piper"}, piperOptions...))
    49  	assert.NoError(t, err)
    50  	assert.Equal(t, 0, code)
    51  }