Skip to content

Commit

Permalink
tests: test executor engine Equal function
Browse files Browse the repository at this point in the history
  • Loading branch information
cognifloyd committed Apr 22, 2022
1 parent aa9018b commit ad98d13
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
5 changes: 5 additions & 0 deletions executor/linux/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ type (

// Equal returns true if the other client is the equivalent.
func Equal(a, b *client) bool {
// handle any nil comparisons
if a == nil || b == nil {
return a == nil && b == nil
}

if reflect.DeepEqual(a.Logger, b.Logger) &&
reflect.DeepEqual(a.Vela, b.Vela) &&
reflect.DeepEqual(a.Runtime, b.Runtime) &&
Expand Down
69 changes: 69 additions & 0 deletions executor/linux/linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,75 @@ import (
"github.com/go-vela/types/pipeline"
)

func TestEqual(t *testing.T) {
// setup types
gin.SetMode(gin.TestMode)

s := httptest.NewServer(server.FakeHandler())

_client, err := vela.NewClient(s.URL, "", nil)
if err != nil {
t.Errorf("unable to create Vela API client: %v", err)
}

_runtime, err := docker.NewMock()
if err != nil {
t.Errorf("unable to create runtime engine: %v", err)
}

_linux, err := New(
WithBuild(testBuild()),
WithHostname("localhost"),
WithPipeline(testSteps()),
WithRepo(testRepo()),
WithRuntime(_runtime),
WithUser(testUser()),
WithVelaClient(_client),
)
if err != nil {
t.Errorf("unable to create linux executor: %v", err)
}

tests := []struct {
name string
a *client
b *client
want bool
}{
{
name: "both nil",
a: nil,
b: nil,
want: true,
},
{
name: "left nil",
a: nil,
b: _linux,
want: false,
},
{
name: "right nil",
a: _linux,
b: nil,
want: false,
},
{
name: "equal",
a: _linux,
b: _linux,
want: true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if got := Equal(test.a, test.b); got != test.want {
t.Errorf("Equal() = %v, want %v", got, test.want)
}
})
}
}

func TestLinux_New(t *testing.T) {
// setup types
gin.SetMode(gin.TestMode)
Expand Down
5 changes: 5 additions & 0 deletions executor/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ type (

// equal returns true if the other client is the equivalent.
func Equal(a, b *client) bool {
// handle any nil comparisons
if a == nil || b == nil {
return a == nil && b == nil
}

if reflect.DeepEqual(a.Vela, b.Vela) &&
reflect.DeepEqual(a.Runtime, b.Runtime) &&
a.Hostname == b.Hostname &&
Expand Down
69 changes: 69 additions & 0 deletions executor/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,75 @@ import (
"github.com/go-vela/types/pipeline"
)

func TestEqual(t *testing.T) {
// setup types
gin.SetMode(gin.TestMode)

s := httptest.NewServer(server.FakeHandler())

_client, err := vela.NewClient(s.URL, "", nil)
if err != nil {
t.Errorf("unable to create Vela API client: %v", err)
}

_runtime, err := docker.NewMock()
if err != nil {
t.Errorf("unable to create runtime engine: %v", err)
}

_local, err := New(
WithBuild(testBuild()),
WithHostname("localhost"),
WithPipeline(testSteps()),
WithRepo(testRepo()),
WithRuntime(_runtime),
WithUser(testUser()),
WithVelaClient(_client),
)
if err != nil {
t.Errorf("unable to create local executor: %v", err)
}

tests := []struct {
name string
a *client
b *client
want bool
}{
{
name: "both nil",
a: nil,
b: nil,
want: true,
},
{
name: "left nil",
a: nil,
b: _local,
want: false,
},
{
name: "right nil",
a: _local,
b: nil,
want: false,
},
{
name: "equal",
a: _local,
b: _local,
want: true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if got := Equal(test.a, test.b); got != test.want {
t.Errorf("Equal() = %v, want %v", got, test.want)
}
})
}
}

func TestLocal_New(t *testing.T) {
// setup types
gin.SetMode(gin.TestMode)
Expand Down

0 comments on commit ad98d13

Please sign in to comment.