Skip to content

Commit

Permalink
Refactor exclude prefixes test
Browse files Browse the repository at this point in the history
Signed-off-by: Tigran Manasyan <tigran.manasyan@xored.com>
  • Loading branch information
Tigran Manasyan committed Oct 1, 2020
1 parent 48cbd03 commit 88d96a4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion basic_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s *BasicTestsSuite) TearDownSuite() {
}

func (s *BasicTestsSuite) TearDownTest() {
k8s.ShowLogs(s.options...)
k8s.ShowLogs("default", s.options...)

s.Require().NoError(exechelper.Run("kubectl delete serviceaccounts --all"))
s.Require().NoError(exechelper.Run("kubectl delete services --all"))
Expand Down
7 changes: 6 additions & 1 deletion k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,17 @@ func ApplyDeployment(path string, mutators ...func(deployment *apiv1.Deployment)
for _, m := range mutators {
m(&d)
}

if d.Namespace == "" {
d.Namespace = namespace
}

_, err = client.AppsV1().Deployments(d.Namespace).Create(&d)
return err
}

// ShowLogs prints logs into console all containers of pods
func ShowLogs(options ...*exechelper.Option) {
func ShowLogs(namespace string, options ...*exechelper.Option) {
client, err := Client()

if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions test/excluded_prefixes_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func (et *ExcludedPrefixesSuite) SetupSuite() {
et.Require().NoError(exechelper.Run("kubectl apply -f ../deployments/prefixes-collector/collector-account.yaml", et.options...))
et.Require().NoError(exechelper.Run("kubectl apply -f ../deployments/prefixes-collector/collector-cluster-role.yaml", et.options...))

et.Require().NoError(k8s.ApplyDeployment("../deployments/alpine.yaml", func(collector *v1.Deployment) {
collector.Namespace = collectorNamespace
et.Require().NoError(k8s.ApplyDeployment("../deployments/alpine.yaml", func(alpine *v1.Deployment) {
alpine.Namespace = collectorNamespace
}))
et.waitForPodStart(collectorNamespace, "alpine")

Expand All @@ -87,7 +87,7 @@ func (et *ExcludedPrefixesSuite) SetupSuite() {
}

func (et *ExcludedPrefixesSuite) TearDownTest() {
k8s.ShowLogs(et.options...)
k8s.ShowLogs(collectorNamespace, et.options...)

et.Require().NoError(exechelper.Run("kubectl delete daemonset -n excluded-prefixes-collector excluded-prefixes-collector"))
et.Require().NoError(exechelper.Run("kubectl delete pods -n excluded-prefixes-collector -l app=excluded-prefixes-collector --now"))
Expand All @@ -96,7 +96,7 @@ func (et *ExcludedPrefixesSuite) TearDownTest() {

func (et *ExcludedPrefixesSuite) TearDownSuite() {
et.Require().NoError(exechelper.Run("kubectl delete -f ../deployments/prefixes-collector/collector-cluster-role.yaml", et.options...))
et.Require().NoError(exechelper.Run("kubectl delete -f ../deployments/prefixes-collector/collector-namespace.yaml", et.options...))
et.Require().NoError(exechelper.Run("kubectl delete -f ../deployments/prefixes-collector/collector-namespace.yaml --now", et.options...))
}

func (et *ExcludedPrefixesSuite) TestWithKubeAdmConfigPrefixes() {
Expand Down Expand Up @@ -150,7 +150,7 @@ func (et *ExcludedPrefixesSuite) TestWithUserConfigPrefixes() {
et.Eventually(et.checkPrefixes(kubeAdmPrefixes), time.Second*5, time.Second)
}

func (et *ExcludedPrefixesSuite) TestWithEnvPrefixes() {
func (et *ExcludedPrefixesSuite) TestWithCorrectEnvPrefixes() {
envPrefixes := []string{
"127.0.0.0/8",
"134.65.0.0/16",
Expand Down

0 comments on commit 88d96a4

Please sign in to comment.