-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathassets_test.go
103 lines (88 loc) · 2.57 KB
/
assets_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
package mtest
import (
"encoding/json"
"errors"
"fmt"
"strconv"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
// testAssets tests sabakan assets
func testAssets() {
It("should work as expected", func() {
By("Uploading an asset")
execSafeAt(host1, "echo", "test", ">", "asset.txt")
sabactlSafe("assets", "upload", "test", "asset.txt")
By("Checking all servers pull the asset")
Eventually(func() error {
var info struct {
Urls []string `json:"urls"`
}
stdout, stderr, err := sabactl("assets", "info", "test")
if err != nil {
return fmt.Errorf("%v: stderr=%s", err, stderr)
}
err = json.Unmarshal(stdout, &info)
if err != nil {
return err
}
if len(info.Urls) != 3 {
return errors.New("uploaded asset does not have 3 urls")
}
return nil
}).Should(Succeed())
By("Removing the asset from the index")
sabactlSafe("assets", "delete", "test")
By("Checking all servers remove the asset")
Eventually(func() error {
for _, h := range []string{host1, host2, host3} {
stdout, _, err := execAt(h, "ls", "/var/lib/sabakan/assets")
if err != nil || len(stdout) > 0 {
return err
}
}
return nil
}).Should(Succeed())
By("Stopping host2 sabakan")
_, _, err := stopHost2Sabakan()
Expect(err).To(Succeed())
By("Adding two assets")
execSafeAt(host1, "echo", "test1", ">", "update1.txt")
sabactlSafe("assets", "upload", "test2", "update1.txt")
execSafeAt(host1, "echo", "test2", ">", "update2.txt")
sabactlSafe("assets", "upload", "test2", "update2.txt")
By("Getting the current revision")
stdout, stderr, err := etcdctl("get", "/", "-w=json")
Expect(err).NotTo(HaveOccurred(), "stderr: %s", stderr)
v := &struct {
Header struct {
Revision int `json:"revision"`
} `json:"header"`
}{}
Expect(json.Unmarshal(stdout, v)).To(Succeed())
currentRevision := v.Header.Revision
By("Executing compaction")
etcdctl("compaction", "--physical=true", strconv.Itoa(currentRevision))
By("Restarting host2 sabakan")
_, _, err = startHost2Sabakan(sabakanImageURL)
Expect(err).To(Succeed())
By("Confirming that sabakan can get the latest asset again")
Eventually(func() error {
var info struct {
Urls []string `json:"urls"`
}
stdout, stderr, err := sabactl("assets", "info", "test2")
if err != nil {
return fmt.Errorf("%v: stderr=%s", err, stderr)
}
err = json.Unmarshal(stdout, &info)
if err != nil {
return err
}
if len(info.Urls) != 3 {
return errors.New("uploaded asset does not have 3 urls")
}
return nil
}).Should(Succeed())
})
}