forked from evergreen-ci/evergreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspawn_test.go
103 lines (81 loc) · 2.71 KB
/
spawn_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 cloud
import (
"testing"
"time"
"github.com/evergreen-ci/birch"
"github.com/evergreen-ci/evergreen"
"github.com/evergreen-ci/evergreen/db"
"github.com/evergreen-ci/evergreen/model/distro"
"github.com/evergreen-ci/evergreen/model/host"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestRDPPasswordValidation(t *testing.T) {
assert := assert.New(t)
goodPasswords := []string{
"地火風水心CP!",
"V3ryStr0ng!",
`Aaa\aa\`,
}
badPasswords := []string{"", "weak", "stilltooweak1", "火火火1"}
for _, password := range goodPasswords {
assert.True(host.ValidateRDPPassword(password), password)
}
for _, password := range badPasswords {
assert.False(host.ValidateRDPPassword(password), password)
}
}
func TestMakeExtendedHostExpiration(t *testing.T) {
assert := assert.New(t)
h := host.Host{
CreationTime: time.Now(),
ExpirationTime: time.Now().Add(12 * time.Hour),
}
expTime, err := MakeExtendedSpawnHostExpiration(&h, time.Hour)
assert.NotZero(expTime)
assert.NoError(err, expTime.Format(time.RFC3339))
}
func TestMakeExtendedHostExpirationFailsBeyondOneWeek(t *testing.T) {
assert := assert.New(t)
h := host.Host{
CreationTime: time.Now(),
ExpirationTime: time.Now().Add(12 * time.Hour),
}
expTime, err := MakeExtendedSpawnHostExpiration(&h, 24*14*time.Hour)
assert.Zero(expTime)
assert.Error(err, expTime.Format(time.RFC3339))
}
func TestMakeExtendedHostExpirationFailsPastMax(t *testing.T) {
assert := assert.New(t)
h := host.Host{
CreationTime: time.Now().Add(-50 * time.Hour * 24), // 50 days in the past
ExpirationTime: time.Now().Add(12 * time.Hour),
}
expTime, err := MakeExtendedSpawnHostExpiration(&h, time.Hour)
assert.Zero(expTime)
assert.Error(err)
assert.Contains(err.Error(), "cannot be extended further")
h.CreationTime = time.Now().Add(-25 * time.Hour * 24)
expTime, err = MakeExtendedSpawnHostExpiration(&h, 7*24*time.Hour) // extend one week
assert.Zero(expTime)
assert.Error(err)
assert.Contains(err.Error(), "cannot be extended more than")
}
func TestModifySpawnHostProviderSettings(t *testing.T) {
require.NoError(t, db.Clear(host.VolumesCollection))
vol := host.Volume{
ID: "v0",
AvailabilityZone: "us-east-1a",
}
require.NoError(t, vol.Insert())
config := evergreen.Settings{}
config.Providers.AWS.Subnets = []evergreen.Subnet{{AZ: "us-east-1a", SubnetID: "new_id"}}
d := distro.Distro{
ProviderSettingsList: []*birch.Document{birch.NewDocument(
birch.EC.String("subnet_id", "old_id"),
)},
}
settingsList, err := modifySpawnHostProviderSettings(d, &config, "", vol.ID)
assert.NoError(t, err)
assert.Equal(t, "new_id", settingsList[0].LookupElement("subnet_id").Value().StringValue())
}