Skip to content

Commit

Permalink
enhance(executor tests): Add kubernetes runtime test cases for Servic…
Browse files Browse the repository at this point in the history
…e tests (#442)
  • Loading branch information
cognifloyd authored Mar 20, 2023
1 parent 10042b4 commit e827b1c
Showing 1 changed file with 210 additions and 0 deletions.
210 changes: 210 additions & 0 deletions executor/linux/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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()

Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit e827b1c

Please sign in to comment.