forked from tophat1720/eris-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_test.go
More file actions
120 lines (97 loc) · 2.88 KB
/
data_test.go
File metadata and controls
120 lines (97 loc) · 2.88 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
package data
import (
"os"
"path/filepath"
"testing"
"github.com/monax/cli/config"
"github.com/monax/cli/definitions"
"github.com/monax/cli/log"
"github.com/monax/cli/testutil"
)
var dataName string = "dataTest1"
var newName string = "dataTest2"
func TestMain(m *testing.M) {
log.SetLevel(log.WarnLevel)
// log.SetLevel(log.InfoLevel)
// log.SetLevel(log.DebugLevel)
testutil.IfExit(testutil.Init(testutil.Pull{
Images: []string{"data"},
}))
exitCode := m.Run()
testutil.IfExit(testutil.TearDown())
os.Exit(exitCode)
}
// TODO add some export/import test robustness
func TestImportDataRawNoPriorExist(t *testing.T) {
testCreateDataByImport(t, dataName)
defer testKillDataCont(t, dataName)
}
func TestExportData(t *testing.T) {
testCreateDataByImport(t, dataName)
defer testKillDataCont(t, dataName)
do := definitions.NowDo()
do.Name = dataName
do.Source = config.MonaxContainerRoot
do.Destination = filepath.Join(config.DataContainersPath, do.Name)
if err := ExportData(do); err != nil {
log.Error(err)
t.FailNow()
}
if _, err := os.Stat(filepath.Join(config.DataContainersPath, dataName, "test")); os.IsNotExist(err) {
log.Errorf("Exported file does not exist: %s", err)
t.Fail()
}
}
func TestExecData(t *testing.T) {
testCreateDataByImport(t, dataName)
defer testKillDataCont(t, dataName)
do := definitions.NowDo()
do.Name = dataName
do.Operations.Args = []string{"mv", "/home/monax/.monax/test", "/home/monax/.monax/tset"}
do.Operations.Interactive = false
log.WithFields(log.Fields{
"data container": do.Name,
"args": do.Operations.Args,
}).Info("Executing data (from tests)")
if _, err := ExecData(do); err != nil {
log.Error(err)
t.Fail()
}
//TODO check that the file was actually moved! (TestExport _used_ todo that)
}
//creates a new data container w/ dir to be used by a test
//maybe give create opts? => paths, files, file contents, etc
func testCreateDataByImport(t *testing.T, name string) {
newDataDir := filepath.Join(config.DataContainersPath, name)
if err := os.MkdirAll(newDataDir, 0777); err != nil {
t.Fatalf("err mkdir: %v", err)
}
f, err := os.Create(filepath.Join(newDataDir, "test"))
if err != nil {
t.Fatalf("err creating file: %v", err)
}
defer f.Close()
do := definitions.NowDo()
do.Name = name
do.Source = filepath.Join(config.DataContainersPath, do.Name)
do.Destination = config.MonaxContainerRoot
if err := ImportData(do); err != nil {
t.Fatalf("error importing data: %v", err)
}
testExist(t, name, true)
}
func testKillDataCont(t *testing.T, name string) {
testCreateDataByImport(t, name)
testExist(t, name, true)
do := definitions.NowDo()
do.Name = name
if err := RmData(do); err != nil {
t.Fatalf("error rm data: %v", err)
}
testExist(t, name, false)
}
func testExist(t *testing.T, name string, toExist bool) {
if err := testutil.ExistAndRun(name, "data", toExist, false); err != nil {
t.Fail()
}
}