-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplacement_test.go
77 lines (70 loc) · 1.77 KB
/
placement_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
// Copyright 2014 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package instance_test
import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/juju/instance"
)
type PlacementSuite struct{}
var _ = gc.Suite(&PlacementSuite{})
func (s *PlacementSuite) TestParsePlacement(c *gc.C) {
parsePlacementTests := []struct {
arg string
expectScope, expectDirective string
err string
}{{
arg: "",
}, {
arg: "0",
expectScope: instance.MachineScope,
expectDirective: "0",
}, {
arg: "0/lxd/0",
expectScope: instance.MachineScope,
expectDirective: "0/lxd/0",
}, {
arg: "#:x",
err: `invalid value "x" for "#" scope: expected machine-id`,
}, {
arg: "lxd:x",
err: `invalid value "x" for "lxd" scope: expected machine-id`,
}, {
arg: "kvm:x",
err: `invalid value "x" for "kvm" scope: expected machine-id`,
}, {
arg: "kvm:123",
expectScope: string(instance.KVM),
expectDirective: "123",
}, {
arg: "lxd",
expectScope: string(instance.LXD),
}, {
arg: "non-standard",
err: "placement scope missing",
}, {
arg: ":non-standard",
err: "placement scope missing",
}, {
arg: "non:standard",
expectScope: "non",
expectDirective: "standard",
}}
for i, t := range parsePlacementTests {
c.Logf("test %d: %s", i, t.arg)
p, err := instance.ParsePlacement(t.arg)
if t.err != "" {
c.Assert(err, gc.ErrorMatches, t.err)
} else {
c.Assert(err, jc.ErrorIsNil)
}
if t.expectScope == "" && t.expectDirective == "" {
c.Assert(p, gc.IsNil)
} else {
c.Assert(p, gc.DeepEquals, &instance.Placement{
Scope: t.expectScope,
Directive: t.expectDirective,
})
}
}
}