forked from inlets/inlets-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate_test.go
97 lines (85 loc) · 2.02 KB
/
validate_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
package main
import (
"testing"
)
func Test_validateFlags_DO(t *testing.T) {
c := InfraConfig{
Provider: "digitalocean",
Region: "lon1",
AccessKey: "set",
}
err := validateFlags(c)
if err != nil {
t.Errorf("expected no error for valid DO config")
}
}
func Test_validateFlags_Packet(t *testing.T) {
c := InfraConfig{
Provider: "packet",
ProjectID: "",
}
err := validateFlags(c)
want := "project-id required for provider: packet"
if err.Error() != want {
t.Errorf("expected error: %s, got: %s", want, err)
}
}
func Test_validateFlags_GCE_Zone(t *testing.T) {
c := InfraConfig{
Provider: "gce",
Zone: "",
ProjectID: "my-project",
}
err := validateFlags(c)
want := "zone required for provider: gce"
if err.Error() != want {
t.Errorf("expected error: %s, got: %s", want, err)
}
}
func Test_validateFlags_GCE_ProjectID(t *testing.T) {
c := InfraConfig{
Provider: "gce",
Zone: "zone",
ProjectID: "",
}
err := validateFlags(c)
want := "project-id required for provider: gce"
if err.Error() != want {
t.Errorf("expected error: %s, got: %s", want, err)
}
}
func Test_validateFlags_BadMemoryValue(t *testing.T) {
c := InfraConfig{
Provider: "digitalocean",
MaxClientMemory: "hundred",
}
err := validateFlags(c)
want := "invalid memory value: quantities must match the regular expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$'"
if err == nil {
t.Errorf("expected an error with bad memory format")
return
}
if err.Error() != want {
t.Errorf("expected error: %q, got: %q", want, err)
}
}
func Test_validateFlags_GoodMemoryValue(t *testing.T) {
c := InfraConfig{
Provider: "digitalocean",
MaxClientMemory: "100Mi",
}
err := validateFlags(c)
if err != nil {
t.Errorf("expected no error, got: %s", err.Error())
}
}
func Test_validateFlags_EmptyMemoryValue(t *testing.T) {
c := InfraConfig{
Provider: "digitalocean",
MaxClientMemory: "",
}
err := validateFlags(c)
if err != nil {
t.Errorf("expected no error, got: %s", err.Error())
}
}