-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
deploy_test.go
74 lines (69 loc) · 2.04 KB
/
deploy_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
package ecspresso_test
import (
"testing"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ecs/types"
"github.com/kayac/ecspresso/v2"
)
type desiredCountTestCase struct {
sv *ecspresso.Service
opt ecspresso.DeployOption
expected *int32
}
var desiredCountTestSuite = []desiredCountTestCase{
{
sv: &ecspresso.Service{DesiredCount: nil},
opt: ecspresso.DeployOption{DesiredCount: nil},
expected: nil,
},
{
sv: &ecspresso.Service{
Service: types.Service{
SchedulingStrategy: types.SchedulingStrategyDaemon,
},
},
opt: ecspresso.DeployOption{DesiredCount: aws.Int32(10)},
expected: nil,
},
{
sv: &ecspresso.Service{DesiredCount: aws.Int32(2)},
opt: ecspresso.DeployOption{DesiredCount: nil},
expected: nil,
},
{
sv: &ecspresso.Service{DesiredCount: aws.Int32(1)},
opt: ecspresso.DeployOption{DesiredCount: aws.Int32(3)},
expected: aws.Int32(3),
},
{
sv: &ecspresso.Service{DesiredCount: aws.Int32(1)},
opt: ecspresso.DeployOption{DesiredCount: aws.Int32(ecspresso.DefaultDesiredCount)},
expected: aws.Int32(1),
},
{
sv: &ecspresso.Service{DesiredCount: aws.Int32(0)},
opt: ecspresso.DeployOption{DesiredCount: aws.Int32(5)},
expected: aws.Int32(5),
},
{
sv: &ecspresso.Service{DesiredCount: aws.Int32(0)},
opt: ecspresso.DeployOption{DesiredCount: aws.Int32(ecspresso.DefaultDesiredCount)},
expected: aws.Int32(0),
},
}
func TestCalcDesiredCount(t *testing.T) {
for n, c := range desiredCountTestSuite {
count := ecspresso.CalcDesiredCount(c.sv, c.opt)
if count == nil && c.expected == nil {
// ok
} else if count != nil && c.expected == nil {
t.Errorf("case %d unexpected desired count:%d expected:nil", n, *count)
} else if count == nil && c.expected != nil {
t.Errorf("case %d unexpected desired count:nil expected:%d", n, *c.expected)
} else if *count != *c.expected {
t.Errorf("case %d unexpected desired count:%d expected:%d", n, *count, *c.expected)
} else {
// ok
}
}
}