From 8988075dad61699aeb2f718334d3744ab8de8e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20H=C3=B6rl?= Date: Wed, 22 Nov 2017 16:13:26 +0000 Subject: [PATCH] Wire the test framework in to the demo tests We're not exercising the test framework yet, but it's in place. Our democli expects its test assets to be in `./assets/bin`. We have a script `./scripts/download-binaries.sh` which will populate that directory from a google storage bucket. Once those assets are in place, you can run tests with `./scripts/run-tests.sh`. --- .gitignore | 1 + pkg/framework/test/assets/bin/.gitkeep | 1 + pkg/framework/test/ci/pipeline.yml | 4 ++-- .../integration/integration_suite_test.go | 13 ++++++++++ .../test/scripts/download-binaries.sh | 24 +++++++++++++++++++ pkg/framework/test/scripts/run-tests.sh | 14 +++++++++++ 6 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 pkg/framework/test/assets/bin/.gitkeep create mode 100755 pkg/framework/test/scripts/download-binaries.sh create mode 100755 pkg/framework/test/scripts/run-tests.sh diff --git a/.gitignore b/.gitignore index 485dee64b..b258db398 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea +pkg/framework/test/assets/bin diff --git a/pkg/framework/test/assets/bin/.gitkeep b/pkg/framework/test/assets/bin/.gitkeep new file mode 100644 index 000000000..172cb3f18 --- /dev/null +++ b/pkg/framework/test/assets/bin/.gitkeep @@ -0,0 +1 @@ +This directory will be the home of some binaries which are downloaded with `pkg/framework/test/scripts/download-binaries`. diff --git a/pkg/framework/test/ci/pipeline.yml b/pkg/framework/test/ci/pipeline.yml index d2119936c..f9320fe69 100644 --- a/pkg/framework/test/ci/pipeline.yml +++ b/pkg/framework/test/ci/pipeline.yml @@ -27,8 +27,8 @@ jobs: export GOPATH="${PWD}/go" export PATH="${PATH}:${GOPATH}/bin" go get github.com/onsi/ginkgo/ginkgo - cd "${GOPATH}/src/k8s.io/kubectl/pkg/framework/test" - ginkgo -r + "${GOPATH}/src/k8s.io/kubectl/pkg/framework/test/scripts/download-binaries.sh" + "${GOPATH}/src/k8s.io/kubectl/pkg/framework/test/scripts/run-tests.sh" - name: push-to-prod-branch serial: true plan: diff --git a/pkg/framework/test/democli/integration/integration_suite_test.go b/pkg/framework/test/democli/integration/integration_suite_test.go index c1de39c41..a10a43ffb 100644 --- a/pkg/framework/test/democli/integration/integration_suite_test.go +++ b/pkg/framework/test/democli/integration/integration_suite_test.go @@ -6,7 +6,12 @@ import ( "testing" + "os" + + "path/filepath" + "github.com/onsi/gomega/gexec" + "k8s.io/kubectl/pkg/framework/test" ) func TestIntegration(t *testing.T) { @@ -16,14 +21,22 @@ func TestIntegration(t *testing.T) { var ( pathToDemoCommand string + fixtures *test.Fixtures ) var _ = BeforeSuite(func() { var err error pathToDemoCommand, err = gexec.Build("k8s.io/kubectl/pkg/framework/test/democli/") Expect(err).NotTo(HaveOccurred()) + + assetsDir, ok := os.LookupEnv("KUBE_ASSETS_DIR") + Expect(ok).To(BeTrue(), "KUBE_ASSETS_DIR should point to a directory containing etcd and apiserver binaries") + fixtures = test.NewFixtures(filepath.Join(assetsDir, "etcd"), filepath.Join(assetsDir, "kube-apiserver")) + err = fixtures.Start() + Expect(err).NotTo(HaveOccurred()) }) var _ = AfterSuite(func() { + fixtures.Stop() gexec.CleanupBuildArtifacts() }) diff --git a/pkg/framework/test/scripts/download-binaries.sh b/pkg/framework/test/scripts/download-binaries.sh new file mode 100755 index 000000000..5822f9c26 --- /dev/null +++ b/pkg/framework/test/scripts/download-binaries.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -eu + +# Use DEBUG=1 ./scripts/download-binaries.sh to get debug output +quiet="--quiet" +[[ -z "${DEBUG:-""}" ]] || { + set -x + quiet="" +} + +# Use BASE_URL=https://my/binaries/url ./scripts/download-binaries to download +# from a different bucket +: "${BASE_URL:="https://storage.googleapis.com/k8s-c10s-test-binaries"}" + +test_framework_dir="$(cd "$(dirname "$0")/.." ; pwd)" +os="$(uname -s)" +arch="$(uname -m)" + +echo "About to download a couple of binaries. This might take a while..." +wget $quiet "${BASE_URL}/etcd-${os}-${arch}" -O "${test_framework_dir}/assets/bin/etcd" +wget $quiet "${BASE_URL}/kube-apiserver-${os}-${arch}" -O "${test_framework_dir}/assets/bin/kube-apiserver" +chmod +x "${test_framework_dir}/assets/bin/etcd" +chmod +x "${test_framework_dir}/assets/bin/kube-apiserver" +echo "Done!" diff --git a/pkg/framework/test/scripts/run-tests.sh b/pkg/framework/test/scripts/run-tests.sh new file mode 100755 index 000000000..fc9c21f7e --- /dev/null +++ b/pkg/framework/test/scripts/run-tests.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -eu + +# Use DEBUG=1 ./scripts/run-tests.sh to get debug output +[[ -z "${DEBUG:-""}" ]] || set -x + +ginkgo_args='' +[[ -z "${GINKGO_WATCH:-""}" ]] || ginkgo_args="${ginkgo_args} watch" + +test_framework_dir="$(cd "$(dirname "$0")/.." ; pwd)" + +export KUBE_ASSETS_DIR="${test_framework_dir}/assets/bin" + +ginkgo $ginkgo_args -r "${test_framework_dir}"