Skip to content

Commit

Permalink
enhance(executor tests): Sanitize pipelines to handle runtime specifi…
Browse files Browse the repository at this point in the history
…c differences (#422)
  • Loading branch information
cognifloyd authored Feb 6, 2023
1 parent 058848b commit 2ca2dd3
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 42 deletions.
4 changes: 3 additions & 1 deletion executor/linux/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package linux
import (
"reflect"
"testing"

"github.com/go-vela/types/constants"
)

func TestLinux_GetBuild(t *testing.T) {
Expand Down Expand Up @@ -64,7 +66,7 @@ func TestLinux_GetBuild(t *testing.T) {

func TestLinux_GetPipeline(t *testing.T) {
// setup types
_steps := testSteps()
_steps := testSteps(constants.DriverDocker)

_engine, err := New(
WithPipeline(_steps),
Expand Down
20 changes: 19 additions & 1 deletion executor/linux/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ func TestLinux_CreateBuild(t *testing.T) {
t.Errorf("unable to compile %s pipeline %s: %v", test.name, test.pipeline, err)
}

// Docker uses _ while Kubernetes uses -
_pipeline = _pipeline.Sanitize(test.runtime)

var _runtime runtime.Engine

switch test.runtime {
Expand Down Expand Up @@ -1074,6 +1077,9 @@ func TestLinux_PlanBuild(t *testing.T) {
t.Errorf("unable to compile %s pipeline %s: %v", test.name, test.pipeline, err)
}

// Docker uses _ while Kubernetes uses -
_pipeline = _pipeline.Sanitize(test.runtime)

var _runtime runtime.Engine

switch test.runtime {
Expand Down Expand Up @@ -1269,6 +1275,9 @@ func TestLinux_AssembleBuild(t *testing.T) {
t.Errorf("unable to compile %s pipeline %s: %v", test.name, test.pipeline, err)
}

// Docker uses _ while Kubernetes uses -
_pipeline = _pipeline.Sanitize(test.runtime)

var _runtime runtime.Engine

switch test.runtime {
Expand Down Expand Up @@ -1420,6 +1429,9 @@ func TestLinux_ExecBuild(t *testing.T) {
t.Errorf("unable to compile %s pipeline %s: %v", test.name, test.pipeline, err)
}

// Docker uses _ while Kubernetes uses -
_pipeline = _pipeline.Sanitize(test.runtime)

var _runtime runtime.Engine

switch test.runtime {
Expand Down Expand Up @@ -1450,7 +1462,7 @@ func TestLinux_ExecBuild(t *testing.T) {
// run create to init steps to be created properly
err = _engine.CreateBuild(context.Background())
if err != nil {
t.Errorf("unable to create build: %v", err)
t.Errorf("%s unable to create build: %v", test.name, err)
}

// TODO: hack - remove this
Expand Down Expand Up @@ -1800,6 +1812,9 @@ func TestLinux_StreamBuild(t *testing.T) {
t.Errorf("unable to compile %s pipeline %s: %v", test.name, test.pipeline, err)
}

// Docker uses _ while Kubernetes uses -
_pipeline = _pipeline.Sanitize(test.runtime)

var _runtime runtime.Engine

switch test.runtime {
Expand Down Expand Up @@ -2003,6 +2018,9 @@ func TestLinux_DestroyBuild(t *testing.T) {
t.Errorf("unable to compile %s pipeline %s: %v", test.name, test.pipeline, err)
}

// Docker uses _ while Kubernetes uses -
_pipeline = _pipeline.Sanitize(test.runtime)

var _runtime runtime.Engine

switch test.runtime {
Expand Down
2 changes: 1 addition & 1 deletion executor/linux/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestLinux_Driver(t *testing.T) {
_engine, err := New(
WithBuild(testBuild()),
WithHostname("localhost"),
WithPipeline(testSteps()),
WithPipeline(testSteps(constants.DriverDocker)),
WithRepo(testRepo()),
WithRuntime(_runtime),
WithUser(testUser()),
Expand Down
22 changes: 11 additions & 11 deletions executor/linux/linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ import (
"testing"

"github.com/gin-gonic/gin"

"github.com/go-vela/sdk-go/vela"
"github.com/go-vela/server/mock/server"
"github.com/go-vela/types"

"github.com/go-vela/worker/runtime/docker"

"github.com/go-vela/sdk-go/vela"

"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
"github.com/go-vela/types/pipeline"
"github.com/go-vela/worker/runtime/docker"
)

func TestEqual(t *testing.T) {
Expand All @@ -40,7 +37,7 @@ func TestEqual(t *testing.T) {
_linux, err := New(
WithBuild(testBuild()),
WithHostname("localhost"),
WithPipeline(testSteps()),
WithPipeline(testSteps(constants.DriverDocker)),
WithRepo(testRepo()),
WithRuntime(_runtime),
WithUser(testUser()),
Expand All @@ -53,7 +50,7 @@ func TestEqual(t *testing.T) {
_alternate, err := New(
WithBuild(testBuild()),
WithHostname("a.different.host"),
WithPipeline(testSteps()),
WithPipeline(testSteps(constants.DriverDocker)),
WithRepo(testRepo()),
WithRuntime(_runtime),
WithUser(testUser()),
Expand Down Expand Up @@ -149,7 +146,7 @@ func TestLinux_New(t *testing.T) {
_, err := New(
WithBuild(test.build),
WithHostname("localhost"),
WithPipeline(testSteps()),
WithPipeline(testSteps(constants.DriverDocker)),
WithRepo(testRepo()),
WithRuntime(_runtime),
WithUser(testUser()),
Expand Down Expand Up @@ -265,8 +262,8 @@ func testMetadata() *types.Metadata {

// testSteps is a test helper function to create a steps
// pipeline with fake steps.
func testSteps() *pipeline.Build {
return &pipeline.Build{
func testSteps(runtime string) *pipeline.Build {
steps := &pipeline.Build{
Version: "1",
ID: "github_octocat_1",
Services: pipeline.ContainerSlice{
Expand Down Expand Up @@ -335,4 +332,7 @@ func testSteps() *pipeline.Build {
},
},
}

// apply any runtime-specific cleanups
return steps.Sanitize(runtime)
}
15 changes: 6 additions & 9 deletions executor/linux/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ import (
"time"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"

"github.com/go-vela/server/mock/server"

"github.com/go-vela/worker/runtime"
"github.com/go-vela/worker/runtime/docker"

"github.com/go-vela/sdk-go/vela"

"github.com/go-vela/server/mock/server"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
"github.com/go-vela/types/pipeline"
"github.com/go-vela/worker/runtime"
"github.com/go-vela/worker/runtime/docker"
"github.com/sirupsen/logrus"
)

func TestLinux_Opt_WithBuild(t *testing.T) {
Expand Down Expand Up @@ -384,7 +381,7 @@ func TestLinux_Opt_WithLogger(t *testing.T) {

func TestLinux_Opt_WithPipeline(t *testing.T) {
// setup types
_steps := testSteps()
_steps := testSteps(constants.DriverDocker)

// setup tests
tests := []struct {
Expand Down
42 changes: 23 additions & 19 deletions executor/linux/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,25 @@ import (
"testing"

"github.com/gin-gonic/gin"
"github.com/urfave/cli/v2"

"github.com/go-vela/sdk-go/vela"
"github.com/go-vela/server/compiler/native"
"github.com/go-vela/server/mock/server"

"github.com/go-vela/worker/internal/message"
"github.com/go-vela/worker/runtime"
"github.com/go-vela/worker/runtime/docker"

"github.com/go-vela/sdk-go/vela"

"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
"github.com/go-vela/types/pipeline"

"github.com/go-vela/worker/internal/message"
"github.com/go-vela/worker/runtime"
"github.com/go-vela/worker/runtime/docker"
"github.com/google/go-cmp/cmp"
"github.com/urfave/cli/v2"
)

func TestLinux_Secret_create(t *testing.T) {
// setup types
_build := testBuild()
_repo := testRepo()
_user := testUser()
_steps := testSteps()
_steps := testSteps(constants.DriverDocker)

gin.SetMode(gin.TestMode)

Expand Down Expand Up @@ -125,7 +120,7 @@ func TestLinux_Secret_delete(t *testing.T) {
_build := testBuild()
_repo := testRepo()
_user := testUser()
_steps := testSteps()
_dockerSteps := testSteps(constants.DriverDocker)

gin.SetMode(gin.TestMode)

Expand Down Expand Up @@ -153,6 +148,7 @@ func TestLinux_Secret_delete(t *testing.T) {
runtime runtime.Engine
container *pipeline.Container
step *library.Step
steps *pipeline.Build
}{
{
name: "docker-running container-empty step",
Expand All @@ -167,7 +163,8 @@ func TestLinux_Secret_delete(t *testing.T) {
Number: 1,
Pull: "always",
},
step: new(library.Step),
step: new(library.Step),
steps: _dockerSteps,
},
{
name: "docker-running container-pending step",
Expand All @@ -182,7 +179,8 @@ func TestLinux_Secret_delete(t *testing.T) {
Number: 2,
Pull: "always",
},
step: _step,
step: _step,
steps: _dockerSteps,
},
{
name: "docker-inspecting container failure due to invalid container id",
Expand All @@ -197,7 +195,8 @@ func TestLinux_Secret_delete(t *testing.T) {
Number: 2,
Pull: "always",
},
step: new(library.Step),
step: new(library.Step),
steps: _dockerSteps,
},
{
name: "docker-removing container failure",
Expand All @@ -212,7 +211,8 @@ func TestLinux_Secret_delete(t *testing.T) {
Number: 2,
Pull: "always",
},
step: new(library.Step),
step: new(library.Step),
steps: _dockerSteps,
},
}

Expand All @@ -221,7 +221,7 @@ func TestLinux_Secret_delete(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
_engine, err := New(
WithBuild(_build),
WithPipeline(_steps),
WithPipeline(test.steps),
WithRepo(_repo),
WithRuntime(test.runtime),
WithUser(_user),
Expand All @@ -231,6 +231,7 @@ func TestLinux_Secret_delete(t *testing.T) {
t.Errorf("unable to create %s executor engine: %v", test.name, err)
}

// add init container info to client
_ = _engine.CreateBuild(context.Background())

_engine.steps.Store(test.container.ID, test.step)
Expand Down Expand Up @@ -310,6 +311,9 @@ func TestLinux_Secret_exec(t *testing.T) {
t.Errorf("unable to compile pipeline %s: %v", test.pipeline, err)
}

// Docker uses _ while Kubernetes uses -
p = p.Sanitize(test.runtime)

var _runtime runtime.Engine

switch test.runtime {
Expand Down Expand Up @@ -506,7 +510,7 @@ func TestLinux_Secret_pull(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
_engine, err := New(
WithBuild(_build),
WithPipeline(testSteps()),
WithPipeline(testSteps(constants.DriverDocker)),
WithRepo(_repo),
WithRuntime(test.runtime),
WithUser(_user),
Expand Down Expand Up @@ -538,7 +542,7 @@ func TestLinux_Secret_stream(t *testing.T) {
_build := testBuild()
_repo := testRepo()
_user := testUser()
_steps := testSteps()
_steps := testSteps(constants.DriverDocker)

gin.SetMode(gin.TestMode)

Expand Down

0 comments on commit 2ca2dd3

Please sign in to comment.