Skip to content

Commit

Permalink
Add tests for atomix-controller, onos-topo, onos-config, and onos-ric…
Browse files Browse the repository at this point in the history
… Helm charts (#46)
  • Loading branch information
kuujo authored Mar 18, 2020
1 parent 9bf5602 commit 5eb32ed
Show file tree
Hide file tree
Showing 10 changed files with 1,246 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea/
build/_output
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export CGO_ENABLED=0
export GO111MODULE=on

.PHONY: build

ONOS_HELM_CHARTS_TESTS_VERSION := latest

test: # @HELP run the unit tests and source code validation
test: images
onit test --image onosproject/onos-helm-charts-tests:${ONOS_HELM_CHARTS_TESTS_VERSION}

onos-helm-charts-tests-docker: # @HELP build onos-helm-charts-tests Docker image
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o build/_output/bin/onos-helm-charts-tests ./build/cmd
docker build . -f build/Dockerfile -t onosproject/onos-helm-charts-tests:${ONOS_HELM_CHARTS_TESTS_VERSION}

images: # @HELP build all Docker images
images: onos-helm-charts-tests-docker

kind: # @HELP build Docker images and add them to the currently configured kind cluster
kind: images
@if [ "`kind get clusters`" = '' ]; then echo "no kind cluster found" && exit 1; fi
kind load docker-image onosproject/onos-helm-charts-tests:${ONOS_HELM_CHARTS_TESTS_VERSION}

clean: # @HELP remove all the build artifacts
rm -rf ./build/_output

help:
@grep -E '^.*: *# *@HELP' $(MAKEFILE_LIST) \
| sort \
| awk ' \
BEGIN {FS = ": *# *@HELP"}; \
{printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}; \
'
13 changes: 13 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM alpine:3.8

RUN apk upgrade --update --no-cache

RUN addgroup -S test && adduser -S test -G test

USER test

ADD . /etc/onos-helm-charts

ADD build/_output/bin/onos-helm-charts-tests /usr/local/bin/onos-helm-charts-tests

ENTRYPOINT ["onos-helm-charts-tests"]
30 changes: 30 additions & 0 deletions build/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2020-present Open Networking Foundation.
//
// 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 main

import (
"github.com/onosproject/onos-helm-charts/build/tests"
"github.com/onosproject/onos-test/pkg/registry"
"github.com/onosproject/onos-test/pkg/test"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
)

func main() {
registry.RegisterTestSuite("atomix-controller", &tests.AtomixControllerSuite{})
registry.RegisterTestSuite("onos-topo", &tests.ONOSTopoSuite{})
registry.RegisterTestSuite("onos-config", &tests.ONOSConfigSuite{})
registry.RegisterTestSuite("onos-ric", &tests.ONOSRICSuite{})
test.Main()
}
67 changes: 67 additions & 0 deletions build/tests/atomix-controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2020-present Open Networking Foundation.
//
// 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 tests

import (
"github.com/onosproject/onos-test/pkg/helm"
"github.com/onosproject/onos-test/pkg/test"
"github.com/stretchr/testify/assert"
"testing"
)

// AtomixControllerSuite is the atomix-controller chart test suite
type AtomixControllerSuite struct {
test.Suite
}

// TestInstallClusterScoped tests installing the atomix-controller chart at the cluster scope
func (s *AtomixControllerSuite) TestInstallClusterScoped(t *testing.T) {
atomix := helm.Helm().
Chart("/etc/onos-helm-charts/atomix-controller").
Release("atomix-controller-cluster").
Set("scope", "Cluster")
assert.NoError(t, atomix.Install(true))

clusterRoles, err := atomix.RbacV1().ClusterRoles().List()
assert.NoError(t, err)
assert.Len(t, clusterRoles, 1)

clusterRoleBindings, err := atomix.RbacV1().ClusterRoleBindings().List()
assert.NoError(t, err)
assert.Len(t, clusterRoleBindings, 1)

err = atomix.Uninstall()
assert.NoError(t, err)
}

// TestInstallNamespaceScoped tests installing the atomix-controller chart at the namespace scope
func (s *AtomixControllerSuite) TestInstallNamespaceScoped(t *testing.T) {
atomix := helm.Helm().
Chart("/etc/onos-helm-charts/atomix-controller").
Release("atomix-controller-namespace").
Set("scope", "Namespace")
assert.NoError(t, atomix.Install(true))

roles, err := atomix.RbacV1().Roles().List()
assert.NoError(t, err)
assert.Len(t, roles, 1)

roleBindings, err := atomix.RbacV1().RoleBindings().List()
assert.NoError(t, err)
assert.Len(t, roleBindings, 1)

err = atomix.Uninstall()
assert.NoError(t, err)
}
48 changes: 48 additions & 0 deletions build/tests/onos-config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2020-present Open Networking Foundation.
//
// 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 tests

import (
"github.com/golangplus/testing/assert"
"github.com/onosproject/onos-test/pkg/helm"
"github.com/onosproject/onos-test/pkg/test"
"testing"
)

// ONOSConfigSuite is the onos-config chart test suite
type ONOSConfigSuite struct {
test.Suite
}

// TestInstall tests installing the onos-config chart
func (s *ONOSConfigSuite) TestInstall(t *testing.T) {
atomix := helm.Helm().
Chart("/etc/onos-helm-charts/atomix-controller").
Release("atomix-controller").
Set("scope", "Namespace")
assert.NoError(t, atomix.Install(true))

topo := helm.Helm().
Chart("/etc/onos-helm-charts/onos-topo").
Release("onos-topo").
Set("store.controller", "atomix-controller:5679")
assert.NoError(t, topo.Install(false))

config := helm.Helm().
Chart("/etc/onos-helm-charts/onos-config").
Release("onos-config").
Set("store.controller", "atomix-controller:5679")
assert.NoError(t, config.Install(true))
}
48 changes: 48 additions & 0 deletions build/tests/onos-ric.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2020-present Open Networking Foundation.
//
// 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 tests

import (
"github.com/onosproject/onos-test/pkg/helm"
"github.com/onosproject/onos-test/pkg/test"
"github.com/stretchr/testify/assert"
"testing"
)

// ONOSRICSuite is the onos-ric chart test suite
type ONOSRICSuite struct {
test.Suite
}

// TestInstall tests installing the onos-ric chart
func (s *ONOSRICSuite) TestInstall(t *testing.T) {
atomix := helm.Helm().
Chart("/etc/onos-helm-charts/atomix-controller").
Release("atomix-controller").
Set("scope", "Namespace")
assert.NoError(t, atomix.Install(true))

topo := helm.Helm().
Chart("/etc/onos-helm-charts/onos-topo").
Release("onos-topo").
Set("store.controller", "atomix-controller:5679")
assert.NoError(t, topo.Install(false))

ric := helm.Helm().
Chart("/etc/onos-helm-charts/onos-ric").
Release("onos-ric").
Set("store.controller", "atomix-controller:5679")
assert.NoError(t, ric.Install(true))
}
42 changes: 42 additions & 0 deletions build/tests/onos-topo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2020-present Open Networking Foundation.
//
// 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 tests

import (
"github.com/onosproject/onos-test/pkg/helm"
"github.com/onosproject/onos-test/pkg/test"
"github.com/stretchr/testify/assert"
"testing"
)

// ONOSTopoSuite is the onos-topo chart test suite
type ONOSTopoSuite struct {
test.Suite
}

// TestInstall tests installing the onos-topo chart
func (s *ONOSTopoSuite) TestInstall(t *testing.T) {
atomix := helm.Helm().
Chart("/etc/onos-helm-charts/atomix-controller").
Release("atomix-controller").
Set("scope", "Namespace")
assert.NoError(t, atomix.Install(true))

topo := helm.Helm().
Chart("/etc/onos-helm-charts/onos-topo").
Release("onos-topo").
Set("store.controller", "atomix-controller:5679")
assert.NoError(t, topo.Install(true))
}
12 changes: 12 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/onosproject/onos-helm-charts

go 1.13

require (
github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e
github.com/onosproject/onos-test v0.0.0-20200317230736-b84f700a69ff
github.com/stretchr/testify v1.5.1
k8s.io/client-go v0.17.3
)

replace github.com/docker/docker => github.com/docker/engine v1.4.2-0.20200229013735-71373c6105e3
Loading

0 comments on commit 5eb32ed

Please sign in to comment.