-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgo_faas_integration_test.go
142 lines (127 loc) · 4.01 KB
/
go_faas_integration_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// +build integration
package gofaas
import (
"github.com/stretchr/testify/assert"
"testing"
)
func (suite *GoFaasTestSuite) TestFunctionsCRUD() {
funcName := "integration_testnodeinfo"
// get functions
suite.T().Run("IntTests/TestFunctionsCRUD/GetSystemFunctions", func(t *testing.T) {
resp, err := suite.cli.GetSystemFunctions()
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 200, resp.StatusCode)
})
// create a func
def := &FunctionDefintion{
Service: funcName,
Network: "func_functions",
Image: "functions/nodeinfo:latest",
EnvProcess: "node main.js",
Constraints: []string{
"node.platform.os == linux",
},
Labels: map[string]string{
"labelkey": "labelval",
},
Annotations: Annotations{
Topics: "awesome-kafka-topic",
Foo: "some",
},
RegistryAuth: "dXNlcjpwYXNzd29yZA==",
Limits: Limits{
Memory: "128M",
CPU: "0.01",
},
Requests: Requests{
Memory: "128M",
CPU: "0.01",
},
ReadOnlyRootFilesystem: true,
}
suite.T().Run("IntTests/TestFunctionsCRUD/CreateSystemFunctions", func(t *testing.T) {
resp, err = suite.cli.CreateSystemFunctions(def)
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 202, resp.StatusCode)
})
// get function summary
suite.T().Run("IntTests/TestFunctionsCRUD/GetFunctionSummary", func(t *testing.T) {
resp, err = suite.cli.GetFunctionSummary(funcName)
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 200, resp.StatusCode)
})
// update the func
update := &FunctionDefintion{
Service: funcName,
Image: "functions/nodeinfo:latest",
Limits: Limits{
Memory: "130M",
CPU: "0.01",
},
}
suite.T().Run("IntTests/TestFunctionsCRUD/UpdateSystemFunctions", func(t *testing.T) {
resp, err = suite.cli.UpdateSystemFunctions(update)
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 202, resp.StatusCode)
})
// scale up the func
suite.T().Run("IntTests/TestFunctionsCRUD/ScaleFunction/Up", func(t *testing.T) {
resp, err = suite.cli.ScaleFunction(&ScaleFunctionBodyOpts{
Service: funcName,
Replicas: 3,
})
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 202, resp.StatusCode)
})
// scale down the func
suite.T().Run("IntTests/TestFunctionsCRUD/ScaleFunction/Down", func(t *testing.T) {
resp, err = suite.cli.ScaleFunction(&ScaleFunctionBodyOpts{
Service: funcName,
Replicas: 1,
})
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 202, resp.StatusCode)
})
// delete the func
suite.T().Run("IntTests/TestFunctionsCRUD/DeleteSystemFunction", func(t *testing.T) {
resp, err = suite.cli.DeleteSystemFunction(&DeleteFunctionBodyOpts{FunctionName: funcName})
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 202, resp.StatusCode)
})
}
func (suite *GoFaasTestSuite) TestSecretsCRUD() {
secretName := "integration_test_secret"
secretVal := "integration_test_secret_val"
//get secrets list
suite.T().Run("IntTests/TestSecretsCRUD/GetSecrets", func(t *testing.T) {
resp, err := suite.cli.GetSecrets()
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), resp.StatusCode, 200)
})
// create new secret
suite.T().Run("IntTests/TestSecretsCRUD/CreateNewSecret", func(t *testing.T) {
resp, err = suite.cli.CreateNewSecret(&SecretBodyOpts{
Name: secretName,
Value: secretVal,
})
})
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 201, resp.StatusCode)
// update the secret if not a swarm cluster
if suite.cli.ClusterType != "swarm" {
suite.T().Run("IntTests/TestSecretsCRUD/UpdateSecret", func(t *testing.T) {
resp, err = suite.cli.UpdateSecret(&SecretBodyOpts{
Name: secretName,
Value: "updated_integration_test_secret_val",
})
})
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 200, resp.StatusCode)
}
// delete the secret
suite.T().Run("IntTests/TestSecretsCRUD/DeleteSecret", func(t *testing.T) {
resp, err = suite.cli.DeleteSecret(&SecretNameBodyOpts{Name: secretName})
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 200, resp.StatusCode)
})
}