diff --git a/executor/linux/service_test.go b/executor/linux/service_test.go index 144a38bf..44c820ab 100644 --- a/executor/linux/service_test.go +++ b/executor/linux/service_test.go @@ -17,6 +17,7 @@ import ( "github.com/go-vela/worker/internal/message" "github.com/go-vela/worker/runtime" "github.com/go-vela/worker/runtime/docker" + "github.com/go-vela/worker/runtime/kubernetes" ) func TestLinux_CreateService(t *testing.T) { @@ -39,6 +40,11 @@ func TestLinux_CreateService(t *testing.T) { t.Errorf("unable to create docker runtime engine: %v", err) } + _kubernetes, err := kubernetes.NewMock(testPod(false)) + if err != nil { + t.Errorf("unable to create kubernetes runtime engine: %v", err) + } + // setup tests tests := []struct { name string @@ -62,6 +68,22 @@ func TestLinux_CreateService(t *testing.T) { Pull: "not_present", }, }, + { + name: "kubernetes-basic service container", + failure: false, + runtime: _kubernetes, + container: &pipeline.Container{ + ID: "service-github-octocat-1-postgres", + Detach: true, + Directory: "/vela/src/github.com/github/octocat", + Environment: map[string]string{"FOO": "bar"}, + Image: "postgres:12-alpine", + Name: "postgres", + Number: 1, + Ports: []string{"5432:5432"}, + Pull: "not_present", + }, + }, { name: "docker-service container with image not found", failure: true, @@ -78,12 +100,34 @@ func TestLinux_CreateService(t *testing.T) { Pull: "not_present", }, }, + // { + // name: "kubernetes-service container with image not found", + // failure: true, // FIXME: make Kubernetes mock simulate failure similar to Docker mock + // runtime: _kubernetes, + // container: &pipeline.Container{ + // ID: "service-github-octocat-1-postgres", + // Detach: true, + // Directory: "/vela/src/github.com/github/octocat", + // Environment: map[string]string{"FOO": "bar"}, + // Image: "postgres:notfound", + // Name: "postgres", + // Number: 1, + // Ports: []string{"5432:5432"}, + // Pull: "not_present", + // }, + // }, { name: "docker-empty service container", failure: true, runtime: _docker, container: new(pipeline.Container), }, + { + name: "kubernetes-empty service container", + failure: true, + runtime: _kubernetes, + container: new(pipeline.Container), + }, } // run tests @@ -138,6 +182,11 @@ func TestLinux_PlanService(t *testing.T) { t.Errorf("unable to create docker runtime engine: %v", err) } + _kubernetes, err := kubernetes.NewMock(testPod(false)) + if err != nil { + t.Errorf("unable to create kubernetes runtime engine: %v", err) + } + // setup tests tests := []struct { name string @@ -161,6 +210,22 @@ func TestLinux_PlanService(t *testing.T) { Pull: "not_present", }, }, + { + name: "kubernetes-basic service container", + failure: false, + runtime: _kubernetes, + container: &pipeline.Container{ + ID: "service-github-octocat-1-postgres", + Detach: true, + Directory: "/vela/src/github.com/github/octocat", + Environment: map[string]string{"FOO": "bar"}, + Image: "postgres:12-alpine", + Name: "postgres", + Number: 1, + Ports: []string{"5432:5432"}, + Pull: "not_present", + }, + }, { name: "docker-service container with nil environment", failure: true, @@ -177,12 +242,34 @@ func TestLinux_PlanService(t *testing.T) { Pull: "not_present", }, }, + { + name: "kubernetes-service container with nil environment", + failure: true, + runtime: _kubernetes, + container: &pipeline.Container{ + ID: "service-github-octocat-1-postgres", + Detach: true, + Directory: "/vela/src/github.com/github/octocat", + Environment: nil, + Image: "postgres:12-alpine", + Name: "postgres", + Number: 1, + Ports: []string{"5432:5432"}, + Pull: "not_present", + }, + }, { name: "docker-empty service container", failure: true, runtime: _docker, container: new(pipeline.Container), }, + { + name: "kubernetes-empty service container", + failure: true, + runtime: _kubernetes, + container: new(pipeline.Container), + }, } // run tests @@ -237,6 +324,11 @@ func TestLinux_ExecService(t *testing.T) { t.Errorf("unable to create docker runtime engine: %v", err) } + _kubernetes, err := kubernetes.NewMock(testPod(false)) + if err != nil { + t.Errorf("unable to create kubernetes runtime engine: %v", err) + } + streamRequests, done := message.MockStreamRequestsWithCancel(context.Background()) defer done() @@ -263,6 +355,22 @@ func TestLinux_ExecService(t *testing.T) { Pull: "not_present", }, }, + { + name: "kubernetes-basic service container", + failure: false, + runtime: _kubernetes, + container: &pipeline.Container{ + ID: "service-github-octocat-1-postgres", + Detach: true, + Directory: "/vela/src/github.com/github/octocat", + Environment: map[string]string{"FOO": "bar"}, + Image: "postgres:12-alpine", + Name: "postgres", + Number: 1, + Ports: []string{"5432:5432"}, + Pull: "not_present", + }, + }, { name: "docker-service container with image not found", failure: true, @@ -279,12 +387,34 @@ func TestLinux_ExecService(t *testing.T) { Pull: "not_present", }, }, + { + name: "kubernetes-service container with image not found", + failure: false, + runtime: _kubernetes, + container: &pipeline.Container{ + ID: "service-github-octocat-1-postgres", + Detach: true, + Directory: "/vela/src/github.com/github/octocat", + Environment: map[string]string{"FOO": "bar"}, + Image: "postgres:notfound", + Name: "postgres", + Number: 1, + Ports: []string{"5432:5432"}, + Pull: "not_present", + }, + }, { name: "docker-empty service container", failure: true, runtime: _docker, container: new(pipeline.Container), }, + { + name: "kubernetes-empty service container", + failure: true, + runtime: _kubernetes, + container: new(pipeline.Container), + }, } // run tests @@ -345,6 +475,11 @@ func TestLinux_StreamService(t *testing.T) { t.Errorf("unable to create docker runtime engine: %v", err) } + _kubernetes, err := kubernetes.NewMock(testPod(false)) + if err != nil { + t.Errorf("unable to create kubernetes runtime engine: %v", err) + } + // setup tests tests := []struct { name string @@ -368,6 +503,22 @@ func TestLinux_StreamService(t *testing.T) { Pull: "not_present", }, }, + { + name: "kubernetes-basic service container", + failure: false, + runtime: _kubernetes, + container: &pipeline.Container{ + ID: "service-github-octocat-1-postgres", + Detach: true, + Directory: "/vela/src/github.com/github/octocat", + Environment: map[string]string{"FOO": "bar"}, + Image: "postgres:12-alpine", + Name: "postgres", + Number: 1, + Ports: []string{"5432:5432"}, + Pull: "not_present", + }, + }, { name: "docker-service container with name not found", failure: true, @@ -384,12 +535,34 @@ func TestLinux_StreamService(t *testing.T) { Pull: "not_present", }, }, + //{ + // name: "kubernetes-service container with name not found", + // failure: true, // FIXME: make Kubernetes mock simulate failure similar to Docker mock + // runtime: _kubernetes, + // container: &pipeline.Container{ + // ID: "service-github-octocat-1-notfound", + // Detach: true, + // Directory: "/vela/src/github.com/github/octocat", + // Environment: map[string]string{"FOO": "bar"}, + // Image: "postgres:12-alpine", + // Name: "notfound", + // Number: 1, + // Ports: []string{"5432:5432"}, + // Pull: "not_present", + // }, + //}, { name: "docker-empty service container", failure: true, runtime: _docker, container: new(pipeline.Container), }, + { + name: "kubernetes-empty service container", + failure: true, + runtime: _kubernetes, + container: new(pipeline.Container), + }, } // run tests @@ -449,6 +622,11 @@ func TestLinux_DestroyService(t *testing.T) { t.Errorf("unable to create docker runtime engine: %v", err) } + _kubernetes, err := kubernetes.NewMock(testPod(false)) + if err != nil { + t.Errorf("unable to create kubernetes runtime engine: %v", err) + } + // setup tests tests := []struct { name string @@ -472,6 +650,22 @@ func TestLinux_DestroyService(t *testing.T) { Pull: "not_present", }, }, + { + name: "kubernetes-basic service container", + failure: false, + runtime: _kubernetes, + container: &pipeline.Container{ + ID: "service-github-octocat-1-postgres", + Detach: true, + Directory: "/vela/src/github.com/github/octocat", + Environment: map[string]string{"FOO": "bar"}, + Image: "postgres:12-alpine", + Name: "postgres", + Number: 1, + Ports: []string{"5432:5432"}, + Pull: "not_present", + }, + }, { name: "docker-service container with ignoring name not found", failure: true, @@ -488,6 +682,22 @@ func TestLinux_DestroyService(t *testing.T) { Pull: "not_present", }, }, + //{ + // name: "kubernetes-service container with ignoring name not found", + // failure: true, // FIXME: make Kubernetes mock simulate failure similar to Docker mock + // runtime: _kubernetes, + // container: &pipeline.Container{ + // ID: "service-github-octocat-1-ignorenotfound", + // Detach: true, + // Directory: "/vela/src/github.com/github/octocat", + // Environment: map[string]string{"FOO": "bar"}, + // Image: "postgres:12-alpine", + // Name: "ignorenotfound", + // Number: 1, + // Ports: []string{"5432:5432"}, + // Pull: "not_present", + // }, + //}, } // run tests