forked from networkservicemesh/integration-k8s-kind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_suite_test.go
139 lines (106 loc) · 5.98 KB
/
basic_suite_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
// Copyright (c) 2020 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package integration_k8s_kind_test
import (
"testing"
v1 "k8s.io/api/apps/v1"
v1core "k8s.io/api/core/v1"
"github.com/networkservicemesh/integration-k8s-kind/k8s"
"github.com/networkservicemesh/integration-k8s-kind/k8s/require"
"github.com/networkservicemesh/integration-k8s-kind/spire"
"github.com/edwarnicke/exechelper"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
)
type BasicTestsSuite struct {
suite.Suite
options []*exechelper.Option
}
func (s *BasicTestsSuite) SetupSuite() {
writer := logrus.StandardLogger().Writer()
s.options = []*exechelper.Option{
exechelper.WithStderr(writer),
exechelper.WithStdout(writer),
}
s.Require().NoError(spire.Setup(s.options...))
}
func (s *BasicTestsSuite) TearDownSuite() {
s.Require().NoError(spire.Delete(s.options...))
}
func (s *BasicTestsSuite) TearDownTest() {
k8s.ShowLogs(s.options...)
s.Require().NoError(exechelper.Run("kubectl delete serviceaccounts --all"))
s.Require().NoError(exechelper.Run("kubectl delete services --all"))
s.Require().NoError(exechelper.Run("kubectl delete deployment --all"))
s.Require().NoError(exechelper.Run("kubectl delete pods --all --grace-period=0 --force"))
}
func (s *BasicTestsSuite) TestNSE_CanRegisterInRegistry() {
defer require.NoRestarts(s.T())
s.Require().NoError(exechelper.Run("kubectl apply -f ./deployments/registry-service.yaml", s.options...))
s.Require().NoError(exechelper.Run("kubectl apply -f ./deployments/registry-memory.yaml", s.options...))
s.Require().NoError(exechelper.Run("kubectl wait --timeout=120s --for=condition=ready pod -l app=nsm-registry", s.options...))
s.Require().NoError(exechelper.Run("kubectl apply -f ./deployments/nse.yaml", s.options...))
s.Require().NoError(exechelper.Run("kubectl wait --timeout=120s --for=condition=ready pod -l app=nse", s.options...))
}
func (s *BasicTestsSuite) TestNSMgr_CanCanFindNSEInRegistry() {
defer require.NoRestarts(s.T())
s.Require().NoError(exechelper.Run("kubectl apply -f ./deployments/registry-service.yaml", s.options...))
s.Require().NoError(exechelper.Run("kubectl apply -f ./deployments/registry-memory.yaml", s.options...))
s.Require().NoError(exechelper.Run("kubectl wait --timeout=120s --for=condition=ready pod -l app=nsm-registry", s.options...))
s.Require().NoError(exechelper.Run("kubectl apply -f ./deployments/nse.yaml", s.options...))
s.Require().NoError(exechelper.Run("kubectl wait --timeout=120s --for=condition=ready pod -l app=nse", s.options...))
s.Require().NoError(exechelper.Run("kubectl apply -f ./deployments/fake-nsmgr.yaml", s.options...))
s.Require().NoError(exechelper.Run("kubectl wait --timeout=120s --for=condition=ready pod -l app=fake-nsmgr", s.options...))
}
func (s *BasicTestsSuite) TestProxyRegistryDNS_CanCanFindNSE_Local() {
defer require.NoRestarts(s.T())
s.Require().NoError(exechelper.Run("kubectl apply -f ./deployments/proxy-registry-service.yaml", s.options...))
s.Require().NoError(exechelper.Run("kubectl apply -f ./deployments/registry-service.yaml", s.options...))
s.Require().NoError(k8s.ApplyDeployment("./deployments/registry-proxy-dns.yaml", func(proxyRegistry *v1.Deployment) {
proxyRegistry.Spec.Template.Spec.Containers[0].Env = append(proxyRegistry.Spec.Template.Spec.Containers[0].Env, v1core.EnvVar{
Name: "REGISTRY-PROXY-DNS_DOMAIN",
Value: "default.svc.cluster.local",
})
}))
s.Require().NoError(exechelper.Run("kubectl apply -f ./deployments/registry-memory.yaml", s.options...))
s.Require().NoError(exechelper.Run("kubectl wait --timeout=120s --for=condition=ready pod -l app=nsm-registry", s.options...))
s.Require().NoError(exechelper.Run("kubectl apply -f ./deployments/nse.yaml", s.options...))
s.Require().NoError(exechelper.Run("kubectl wait --timeout=120s --for=condition=ready pod -l app=nse", s.options...))
s.Require().NoError(exechelper.Run("kubectl wait --timeout=120s --for=condition=ready pod -l app=nsm-registry-proxy-dns", s.options...))
s.Require().NoError(k8s.ApplyDeployment("./deployments/fake-nsmgr.yaml", func(nsmgr *v1.Deployment) {
nsmgr.Spec.Template.Spec.Containers[0].Env = append(nsmgr.Spec.Template.Spec.Containers[0].Env, v1core.EnvVar{
Name: "FAKE-NSMGR_FIND_NETWORK_SERVICE_ENDPOINT_NAME",
Value: "icmp-responder@default.svc.cluster.local",
})
}))
s.Require().NoError(exechelper.Run("kubectl wait --timeout=120s --for=condition=ready pod -l app=fake-nsmgr", s.options...))
}
func (s *BasicTestsSuite) TestDeployMemoryRegistry() {
defer require.NoRestarts(s.T())
s.Require().NoError(exechelper.Run("kubectl apply -f ./deployments/registry-service.yaml", s.options...))
s.Require().NoError(exechelper.Run("kubectl apply -f ./deployments/registry-memory.yaml", s.options...))
s.Require().NoError(exechelper.Run("kubectl wait --timeout=120s --for=condition=ready pod -l app=nsm-registry", s.options...))
s.Require().NoError(exechelper.Run("kubectl describe pod -l app=nsm-registry", s.options...))
}
func (s *BasicTestsSuite) TestDeployAlpine() {
defer require.NoRestarts(s.T())
s.Require().NoError(exechelper.Run("kubectl apply -f ./deployments/registry-service.yaml", s.options...))
s.Require().NoError(exechelper.Run("kubectl apply -f ./deployments/alpine.yaml", s.options...))
s.Require().NoError(exechelper.Run("kubectl wait --for=condition=ready pod -l app=alpine", s.options...))
}
func TestRunBasicSuite(t *testing.T) {
suite.Run(t, &BasicTestsSuite{})
}