-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtasks_test.go
More file actions
123 lines (100 loc) · 3.06 KB
/
tasks_test.go
File metadata and controls
123 lines (100 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package app_test
import (
"runtime"
"testing"
"github.com/stackup-app/stackup/lib/app"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
type MockJsEngine struct {
MockEvaluate func(script string) interface{}
mock.Mock
}
func (m *MockJsEngine) Evaluate(script string) interface{} {
return m.MockEvaluate(script)
}
func TestGetDisplayName(t *testing.T) {
assert := assert.New(t)
// Test case: When Include field has a value with "https://"
task1 := app.Task{
Include: "https://example.com",
Name: "TestName",
Id: "TestId",
Uuid: "TestUuid",
}
assert.Equal("example.com", task1.GetDisplayName())
// Test case: When Include field has a value without "https://"
task2 := app.Task{
Include: "example.com",
Name: "TestName",
Id: "TestId",
Uuid: "TestUuid",
}
assert.Equal("example.com", task2.GetDisplayName())
// Test case: When Name field has a value
task3 := app.Task{
Name: "TestName",
Id: "TestId",
Uuid: "TestUuid",
}
assert.Equal("TestName", task3.GetDisplayName())
// Test case: When Id field has a value
task4 := app.Task{
Id: "TestId",
Uuid: "TestUuid",
}
assert.Equal("TestId", task4.GetDisplayName())
// Test case: When only Uuid field has a value
task5 := app.Task{
Uuid: "TestUuid",
}
assert.Equal("TestUuid", task5.GetDisplayName())
// Test case: When no fields have values
task6 := app.Task{}
assert.Equal("", task6.GetDisplayName())
}
func TestCanRunOnCurrentPlatform(t *testing.T) {
assert := assert.New(t)
// Test case: When Platforms is nil
task1 := &app.Task{}
assert.True(task1.CanRunOnCurrentPlatform())
// Test case: When Platforms is empty
task2 := &app.Task{Platforms: []string{}}
assert.True(task2.CanRunOnCurrentPlatform())
// Test case: When Platforms contains the current platform (case insensitive)
task3 := &app.Task{Platforms: []string{runtime.GOOS}}
assert.True(task3.CanRunOnCurrentPlatform())
// Test case: When Platforms does not contain the current platform
task4 := &app.Task{Platforms: []string{"someotherplatform"}}
assert.False(task4.CanRunOnCurrentPlatform())
}
// func TestCanRunConditionally(t *testing.T) {
// assert := assert.New(t)
// // Test case: When If field is empty
// task1 := &app.Task{If: ""}
// assert.True(task1.CanRunConditionally())
// // Test case: When JsEngine.Evaluate returns true
// getJsEngine := func(mockEval func(script string) interface{}) interface{} {
// engine := &MockJsEngine{
// MockEvaluate: mockEval,
// }
// return engine
// }
// jsengine2 := getJsEngine(func(script string) interface{} {
// return true
// })
// task2 := &app.Task{
// If: "{{ some condition }}",
// JsEngine: jsengine2.(*scripting.JavaScriptEngine),
// }
// assert.True(task2.CanRunConditionally())
// // Test case: When JsEngine.Evaluate returns false
// jsengine3 := getJsEngine(func(script string) interface{} {
// return false
// })
// task3 := &app.Task{
// If: "some condition",
// JsEngine: jsengine3.(*scripting.JavaScriptEngine),
// }
// assert.False(task3.CanRunConditionally())
// }