github.com/xgoffin/jenkins-library@v1.154.0/integration/integration_api_cli_test.go (about)

     1  //go:build integration
     2  // +build integration
     3  
     4  // can be execute with go test -tags=integration ./integration/...
     5  
     6  package main
     7  
     8  import (
     9  	"context"
    10  	"os"
    11  	"path/filepath"
    12  	"testing"
    13  
    14  	"github.com/stretchr/testify/assert"
    15  	"github.com/testcontainers/testcontainers-go"
    16  )
    17  
    18  func TestDummy(t *testing.T) {
    19  
    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-stretch",
    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  }