-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts_test.go
More file actions
57 lines (47 loc) · 1.27 KB
/
Copy pathscripts_test.go
File metadata and controls
57 lines (47 loc) · 1.27 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
package coach
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/alittlebrighter/coach/gen/models"
)
var (
scriptFile = `#-ALIAS- = myscript
# -TAGS- = cheese,whiskey,mashed potatoes
#-SHELL- = bash
#
#-DOCUMENTATION- ` + doNotEditLine + `
# A simple script that does my things.
#
# A second line.
#
#-SCRIPT- ` + doNotEditLine + `
ls -a
cat ~/.bashrc | grep "BILLY BOB"
restart critical service
`
scriptStruct = models.DocumentedScript{
Alias: "myscript",
Tags: []string{"cheese", "whiskey", "mashed potatoes"},
Documentation: `A simple script that does my things.
A second line.`,
Script: &models.Script{
Content: `ls -a
cat ~/.bashrc | grep "BILLY BOB"
restart critical service
`,
Shell: "bash",
},
}
)
func TestMarshalEdit(t *testing.T) {
assert.Equal(t, scriptFile, string(MarshalEdit(scriptStruct)))
}
func TestUnmarshalEdit(t *testing.T) {
newScript, _ := UnmarshalEdit(scriptFile)
assert.Equal(t, scriptStruct.GetAlias(), newScript.GetAlias())
for i := range scriptStruct.GetTags() {
assert.Equal(t, scriptStruct.GetTags()[i], newScript.GetTags()[i])
}
assert.Equal(t, scriptStruct.GetDocumentation(), newScript.GetDocumentation())
assert.Equal(t, scriptStruct.GetScript().GetContent(), newScript.GetScript().GetContent())
}