-
Notifications
You must be signed in to change notification settings - Fork 47
/
workflow_paths_test.go
84 lines (71 loc) · 2.06 KB
/
workflow_paths_test.go
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
// Copyright (c) 2019 Dean Jackson <deanishe@deanishe.net>
// MIT Licence applies http://opensource.org/licenses/MIT
package aw
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestReset(t *testing.T) {
withTestWf(func(wf *Workflow) {
s := wf.Dir()
x, err := os.Getwd()
require.Nil(t, err, "Getwd failed")
assert.Equal(t, x, s, "unexpected dir")
name := "xyz.json"
data := []byte("muh bytes")
err = wf.Cache.Store(name, data)
assert.Nil(t, err, "cache store failed")
err = wf.Data.Store(name, data)
assert.Nil(t, err, "data store failed")
err = wf.Session.Store(name, data)
assert.Nil(t, err, "session store failed")
assert.True(t, wf.Cache.Exists(name), "cache data do not exist")
assert.True(t, wf.Data.Exists(name), "data do not exist")
assert.True(t, wf.Session.Exists(name), "session data do not exist")
require.Nil(t, wf.Reset(), "reset failed")
assert.False(t, wf.Cache.Exists(name), "cache data exist")
assert.False(t, wf.Data.Exists(name), "data exist")
assert.False(t, wf.Session.Exists(name), "session data exist")
})
}
func TestWorkflowRoot(t *testing.T) {
withTestWf(func(wf *Workflow) {
wd, err := os.Getwd()
require.Nil(t, err, "Getwd failed")
p := findWorkflowRoot(wd)
assert.Equal(t, wd, p, "unexpected workflow directory")
})
}
func TestOpen(t *testing.T) {
helpURL := "https://github.com/deanishe/awgo"
withTestWf(func(wf *Workflow) {
wf.Configure(HelpURL(helpURL))
tests := []struct {
fn func() error
name string
args []string
}{
{wf.OpenLog, "open",
[]string{"open", wf.LogFile()},
},
{wf.OpenHelp, "open",
[]string{"open", helpURL},
},
{wf.OpenCache, "open",
[]string{"open", wf.CacheDir()},
},
{wf.OpenData, "open",
[]string{"open", wf.DataDir()},
},
}
for _, td := range tests {
me := &mockExec{}
wf.execFunc = me.Run
assert.Nil(t, td.fn(), "test command failed")
assert.Equal(t, td.name, me.name, "Wrong command name")
assert.Equal(t, td.args, me.args, "Wrong command args")
}
})
}