1
1
package containerd_test
2
2
3
3
import (
4
+ "context"
4
5
"testing"
5
6
7
+ ctr "github.com/containerd/containerd"
6
8
. "github.com/onsi/gomega"
7
9
8
10
"github.com/weaveworks-liquidmetal/flintlock/core/models"
9
11
"github.com/weaveworks-liquidmetal/flintlock/core/ports"
10
12
"github.com/weaveworks-liquidmetal/flintlock/infrastructure/containerd"
11
13
)
12
14
15
+ const ctrdRepoNS = "flintlock_test_ctr_repo"
16
+
13
17
func TestMicroVMRepo_Integration (t * testing.T ) {
14
18
if ! runContainerDTests () {
15
19
t .Skip ("skipping containerd microvm repo integration test" )
16
20
}
17
21
22
+ var (
23
+ repo ports.MicroVMRepository
24
+ ctx context.Context
25
+ testVm , testVm2 * models.MicroVM
26
+ )
27
+
28
+ t .Cleanup (func () {
29
+ if testVm != nil {
30
+ _ = repo .Delete (ctx , testVm )
31
+ }
32
+
33
+ if testVm2 != nil {
34
+ _ = repo .Delete (ctx , testVm2 )
35
+ }
36
+ })
37
+
18
38
RegisterTestingT (t )
19
39
20
- client , ctx := testCreateClient (t )
40
+ var client * ctr.Client
41
+ client , ctx = testCreateClient (t )
21
42
22
- repo : = containerd .NewMicroVMRepoWithClient (& containerd.Config {
43
+ repo = containerd .NewMicroVMRepoWithClient (& containerd.Config {
23
44
SnapshotterKernel : testSnapshotter ,
24
45
SnapshotterVolume : testSnapshotter ,
25
- Namespace : testContainerdNS ,
46
+ Namespace : ctrdRepoNS ,
26
47
}, client )
27
48
exists , err := repo .Exists (ctx , * models .NewVMIDForce (testOwnerName , testOwnerNamespace , testOwnerUID ))
28
49
Expect (err ).NotTo (HaveOccurred ())
29
50
Expect (exists ).To (BeFalse ())
30
51
31
- testVm : = makeSpec (testOwnerName , testOwnerNamespace )
52
+ testVm = makeSpec (testOwnerName , testOwnerNamespace , "uid" )
32
53
savedVM , err := repo .Save (ctx , testVm )
33
54
Expect (err ).NotTo (HaveOccurred ())
34
55
Expect (savedVM ).NotTo (BeNil ())
@@ -40,6 +61,12 @@ func TestMicroVMRepo_Integration(t *testing.T) {
40
61
Expect (savedVM ).NotTo (BeNil ())
41
62
Expect (savedVM .Version ).To (Equal (3 ))
42
63
64
+ testVm2 = makeSpec ("bar" , "foo" , "uid2" )
65
+ savedVM2 , err := repo .Save (ctx , testVm2 )
66
+ Expect (err ).NotTo (HaveOccurred ())
67
+ Expect (savedVM2 ).NotTo (BeNil ())
68
+ Expect (savedVM2 .Version ).To (Equal (2 ))
69
+
43
70
exists , err = repo .Exists (ctx , * models .NewVMIDForce (testOwnerName , testOwnerNamespace , testOwnerUID ))
44
71
Expect (err ).NotTo (HaveOccurred ())
45
72
Expect (exists ).To (BeTrue ())
@@ -67,6 +94,10 @@ func TestMicroVMRepo_Integration(t *testing.T) {
67
94
Expect (err ).NotTo (HaveOccurred ())
68
95
Expect (len (all )).To (Equal (1 ))
69
96
97
+ all2 , err := repo .GetAll (ctx , models.ListMicroVMQuery {})
98
+ Expect (err ).NotTo (HaveOccurred ())
99
+ Expect (len (all2 )).To (Equal (2 ))
100
+
70
101
err = repo .Delete (ctx , testVm )
71
102
Expect (err ).NotTo (HaveOccurred ())
72
103
@@ -90,12 +121,12 @@ func TestMicroVMRepo_Integration_MultipleSave(t *testing.T) {
90
121
91
122
client , ctx := testCreateClient (t )
92
123
93
- testVm := makeSpec (testOwnerName , testOwnerNamespace )
124
+ testVm := makeSpec (testOwnerName , testOwnerNamespace , "uid" )
94
125
95
126
repo := containerd .NewMicroVMRepoWithClient (& containerd.Config {
96
127
SnapshotterKernel : testSnapshotter ,
97
128
SnapshotterVolume : testSnapshotter ,
98
- Namespace : testContainerdNS ,
129
+ Namespace : ctrdRepoNS ,
99
130
}, client )
100
131
savedVM , err := repo .Save (ctx , testVm )
101
132
Expect (err ).NotTo (HaveOccurred ())
@@ -111,8 +142,8 @@ func TestMicroVMRepo_Integration_MultipleSave(t *testing.T) {
111
142
Expect (err ).NotTo (HaveOccurred ())
112
143
}
113
144
114
- func makeSpec (name , ns string ) * models.MicroVM {
115
- vmid , _ := models .NewVMID (name , ns , " uid" )
145
+ func makeSpec (name , ns , uid string ) * models.MicroVM {
146
+ vmid , _ := models .NewVMID (name , ns , uid )
116
147
return & models.MicroVM {
117
148
ID : * vmid ,
118
149
Version : 1 ,
0 commit comments