Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

[kn-admin]Add e2e tests for kn admin plugin #63

Merged
merged 5 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugins/admin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ module knative.dev/client-contrib/plugins/admin
go 1.14

require (
github.com/maximilien/kn-source-pkg v0.4.8
github.com/mitchellh/go-homedir v1.1.0
github.com/spf13/cobra v0.0.5
github.com/spf13/cobra v0.0.6
github.com/spf13/viper v1.6.2
gopkg.in/yaml.v2 v2.2.8
gotest.tools v2.2.0+incompatible
Expand Down
40 changes: 40 additions & 0 deletions plugins/admin/go.sum

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions plugins/admin/test/e2e-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2020 The Knative Authors
#
# 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.

# ===============================================
# Add you integration tests here

source $TEST_INFRA_SCRIPTS/e2e-tests.sh

export PATH=$PWD:$PATH

dir=$(dirname "${BASH_SOURCE[0]}")
base=$(cd "$dir/.." && pwd)

echo "TEST_INFRA_SCRIPTS: $TEST_INFRA_SCRIPTS"
echo "Testing kn-admin plugin"
cd ${REPO_ROOT_DIR}

function plugin_test_setup {
# TODO: add setup steps
}

run() {

header "Running plugin kn-admin e2e tests for Knative Serving $KNATIVE_SERVING_VERSION and Eventing $KNATIVE_EVENTING_VERSION"

# Will create and delete this namespace (used for all tests, modify if you want a different one used)
export KN_E2E_NAMESPACE=kne2etests

echo "🧪 Setup"
plugin_test_setup
echo "🧪 Build"
./hack/build.sh -f
echo "🧪 Testing"
go_test_e2e -timeout=45m ./test/e2e || fail_test
echo "🧪 Teardown"
plugin_test_teardown
success
}

# Fire up
run $@
76 changes: 76 additions & 0 deletions plugins/admin/test/e2e/kn_admin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright 2020 The Knative Authors

// 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.

// +build e2e
// +build !eventing

package e2e

import (
"os"
"path/filepath"
"testing"

testcommon "github.com/maximilien/kn-source-pkg/test/e2e"
"gotest.tools/assert"
"knative.dev/client/lib/test"
)

type e2eTest struct {
it *testcommon.E2ETest
}

func newE2ETest(t *testing.T) *e2eTest {
currentDir, err := os.Getwd()
if err != nil {
return nil
}

it, err := testcommon.NewE2ETest("kn-admin", filepath.Join(currentDir, "../.."), false)
if err != nil {
return nil
}

e2eTest := &e2eTest{
it: it,
}
return e2eTest
}

func TestKnAdminPlugin(t *testing.T) {
t.Parallel()

e2eTest := newE2ETest(t)
assert.Assert(t, e2eTest != nil)
defer func() {
assert.NilError(t, e2eTest.it.KnTest().Teardown())
}()

r := test.NewKnRunResultCollector(t, e2eTest.it.KnTest())
defer r.DumpIfFailed()

err := e2eTest.it.KnPlugin().Install()
assert.NilError(t, err)

t.Log("test kn admin domain set")
e2eTest.knAdminSetDomain(t, r, "dummy.com")

err = e2eTest.it.KnPlugin().Uninstall()
assert.NilError(t, err)
}

func (et *e2eTest) knAdminSetDomain(t *testing.T, r *test.KnRunResultCollector, domain string) {
out := et.it.KnPlugin().Run("domain", "set", "--custom-domain", domain)
r.AssertNoError(out)
}
201 changes: 201 additions & 0 deletions plugins/admin/vendor/github.com/maximilien/kn-source-pkg/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading