-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_test.go
125 lines (108 loc) · 3.11 KB
/
task_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
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
124
125
package main
import (
"net/url"
"os"
"path/filepath"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLive_AcronisAPI_walkTasks(t *testing.T) {
api := acronisLiveConn(t)
uuidCfg, err := cacheByUuid("testdata/cache/byTask")
require.NoError(t, err)
policyCfg, err := cacheByPolicy("testdata/cache/byPolicy")
require.NoError(t, err)
tenantCfg, err := cacheByTenantName("testdata/cache/byTenant")
require.NoError(t, err)
cachePipeline := multiTaskPipelineFunc(
filterUpdatesOnly(uuidCfg, writeTaskPipeline(uuidCfg)),
filterUpdatesOnly(policyCfg, writeTaskPipeline(policyCfg)),
filterUpdatesOnly(policyCfg, writeTaskPipeline(tenantCfg)),
)
query := url.Values{}
query.Set("order", "asc(updatedAt)")
query.Set("updatedAt", "gt("+time.Now().Add(-48*time.Hour).Format(time.RFC3339)+")")
query.Set("state", "completed")
err = api.walkTasks(query, 5000, cachePipeline)
assert.NoError(t, err)
}
func TestReadTask(t *testing.T) {
for path, expErr := range testReadTask_testdata {
uuid := strings.TrimSuffix(filepath.Base(path), ".json")
t.Run(uuid, func(t *testing.T) {
path, uuid, expErr := path, uuid, expErr
t.Parallel()
task, err := readTask(path)
if expErr != nil {
if os.IsNotExist(expErr) {
assert.True(t, os.IsNotExist(err))
} else {
assert.EqualError(t, err, expErr.Error())
}
assert.Equal(t, task, Task{})
} else {
require.NoError(t, err)
assert.Equal(t, uuid, task.UUID)
}
})
}
}
func TestWriteTask(t *testing.T) {
require.NoError(t, os.MkdirAll("testdata/cache/writeTask", 0755))
for name, td := range testWriteTask_testdata {
t.Run(name, func(t *testing.T) {
name, td := name, td
t.Parallel()
cfg := cacheConfig{
cacheDir: td.cacheDir,
targetToPath: stdTargetToCachePathFunc(td.cacheDir),
taskToTarget: func(task Task) tgtStr { return tgtStr(name) },
}
writePipeline := writeTaskPipeline(cfg)
task, err := readTask(td.taskPath)
require.NoError(t, err)
err = writePipeline(task)
if td.expErr == "" {
assert.NoError(t, err)
assertGoldenFile(t, cfg.taskPath(task))
} else {
assert.EqualError(t, err, td.expErr)
}
})
}
}
func TestFilterUpdatesOnly(t *testing.T) {
require.NoError(t, os.MkdirAll("testdata/cache/filterUpdates/", 0755))
for name, td := range testFilterTaskUpdatesOnly_testdata {
t.Run(name, func(t *testing.T) {
name, td := name, td
t.Parallel()
var writeErr error
cfg := cacheConfig{
cacheDir: td.cacheDir,
targetToPath: stdTargetToCachePathFunc(td.cacheDir),
taskToTarget: func(task Task) tgtStr { return tgtStr(name) },
}
writePipeline := multiTaskPipelineFunc(filterUpdatesOnly(cfg,
writeTaskPipeline(cfg)))
var task Task
for _, taskPath := range td.taskPath {
task, err := readTask(taskPath)
require.NoError(t, err)
writeErr = writePipeline(task)
if writeErr != nil {
break
}
}
if td.expErr == "" {
assert.NoError(t, writeErr)
assertGoldenFile(t, cfg.taskPath(task))
} else {
assert.EqualError(t, writeErr, td.expErr)
}
})
}
}