Skip to content

Commit cfe4a84

Browse files
committed
Add suite tests
1 parent a7ee645 commit cfe4a84

3 files changed

Lines changed: 48 additions & 9 deletions

File tree

pkg/runtime/runtime.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ type TestConfig struct {
7272
Retries int
7373
Interval string
7474
InheritEnv bool
75-
SSH SSHExecutor
7675
}
7776

7877
// ResultStatus represents the status code of a test result

pkg/suite/suite.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ type Suite struct {
1212
Nodes []runtime.Node
1313
}
1414

15-
func NewSuite(config runtime.TestConfig, tests ...runtime.TestCase) *Suite {
16-
return &Suite{
17-
TestCases: tests,
18-
Config: config,
19-
}
20-
}
21-
2215
func (s Suite) GetNodes() []runtime.Node {
2316
return s.Nodes
2417
}
@@ -33,7 +26,7 @@ func (s Suite) GetNodeByName(name string) (runtime.Node, error) {
3326
}
3427

3528
func (s Suite) AddTest(t runtime.TestCase) {
36-
if _, err := s.GetTestByTitle(t.Title); err != nil {
29+
if _, err := s.GetTestByTitle(t.Title); err == nil {
3730
panic(fmt.Sprintf("Tests %s was already added to the suite", t.Title))
3831
}
3932
s.TestCases = append(s.TestCases, t)

pkg/suite/suite_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,48 @@
11
package suite
2+
3+
import (
4+
"github.com/SimonBaeumer/commander/pkg/runtime"
5+
"github.com/stretchr/testify/assert"
6+
"testing"
7+
)
8+
9+
func Test_GetNodes(t *testing.T) {
10+
s := Suite{
11+
Nodes: []runtime.Node{runtime.Node{}, runtime.Node{}},
12+
}
13+
14+
assert.Len(t, s.GetNodes(), 2)
15+
}
16+
17+
func Test_GetNodesByName(t *testing.T) {
18+
s := Suite{
19+
Nodes: []runtime.Node{runtime.Node{}, runtime.Node{Name: "node1"}},
20+
}
21+
22+
node, e := s.GetNodeByName("node1")
23+
assert.Equal(t, node.Name, "node1")
24+
assert.Nil(t, e)
25+
26+
node, e = s.GetNodeByName("doesnt-exist")
27+
assert.EqualError(t, e, "could not find node with name doesnt-exist")
28+
}
29+
30+
func Test_AddTest(t *testing.T) {
31+
s := Suite{TestCases: []runtime.TestCase{{Title: "exists"}}}
32+
s.AddTest(runtime.TestCase{Title: "test"})
33+
34+
assert.Len(t, s.GetTests(), 1)
35+
}
36+
37+
func Test_GetTestByTitle(t *testing.T) {
38+
s := Suite{TestCases: []runtime.TestCase{{Title: "exists"}}}
39+
test, err := s.GetTestByTitle("exists")
40+
41+
assert.Nil(t, err)
42+
assert.Equal(t, "exists", test.Title)
43+
}
44+
45+
func Test_GetGlobalConfig(t *testing.T) {
46+
s := Suite{Config: runtime.TestConfig{Dir: "/tmp"}}
47+
assert.Equal(t, "/tmp", s.GetGlobalConfig().Dir)
48+
}

0 commit comments

Comments
 (0)