Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

add e2e test #107

Merged
merged 1 commit into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
107 changes: 107 additions & 0 deletions .github/workflows/e2e-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: E2E Test

on:
push:
branches:
- master
- release-*
tags:
- v*
workflow_dispatch: {}
pull_request:
branches:
- master
- release-*

env:
# Common versions
GO_VERSION: '1.17'
KIND_CLUSTER_NAME: 'kind'
KIND_VERSION: 'v0.14.0'
KIND_IMAGE_VERSION: '[\"v1.22.9\"]'
KIND_IMAGE_VERSIONS: '[\"v1.22.9\"]'

jobs:

detect-noop:
runs-on: ubuntu-20.04
outputs:
noop: ${{ steps.noop.outputs.should_skip }}
steps:
- name: Detect No-op Changes
id: noop
uses: fkirc/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
paths_ignore: '["**.md", "**.mdx", "**.png", "**.jpg"]'
do_not_skip: '["workflow_dispatch", "schedule", "push"]'
concurrent_skipping: false

set-k8s-matrix:
runs-on: ubuntu-20.04
outputs:
matrix: ${{ steps.set-k8s-matrix.outputs.matrix }}
steps:
- id: set-k8s-matrix
run: |
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
echo "pushing tag: ${{ github.ref_name }}"
echo "::set-output name=matrix::${{ env.KIND_IMAGE_VERSIONS }}"
else
echo "::set-output name=matrix::${{ env.KIND_IMAGE_VERSION }}"
fi
e2e-multi-cluster-tests:
runs-on: ubuntu-20.04
needs: [ detect-noop,set-k8s-matrix ]
if: needs.detect-noop.outputs.noop != 'true'
strategy:
matrix:
k8s-version: ${{ fromJson(needs.set-k8s-matrix.outputs.matrix) }}

steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Get dependencies
run: |
go get -v -t -d ./...
mkdir -p ${GITHUB_WORKSPACE}
cp ./tests/kind-conf.yaml ${GITHUB_WORKSPACE}/kind-conf.yaml

- name: Setup Kind Cluster
uses: engineerd/[email protected]
with:
image: kindest/node:${{ matrix.k8s-version }}
version: ${{ env.KIND_VERSION }}
config: kind-conf.yaml
name: ${{ env.KIND_CLUSTER_NAME }}

- name: Load Image to kind cluster
run: |
kubectl version
kubectl cluster-info
IMAGE_TAG=latest TARGET_PLATFORMS=linux/amd64 GIT_VERSION=e2e-test make kind-load

- name: Prepare for e2e tests
run: |
helm install -n kube-system yurt-app-manager ./charts/yurt-app-manager --timeout 5m

- name: Run e2e tests
run: make e2e-test

# TODO implement e2e profile
# - name: Upload coverage report
# uses: codecov/codecov-action@v1
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# files: /tmp/e2e-profile.out,/tmp/e2e_multicluster_test.out
# flags: e2e-multicluster-test
# name: codecov-umbrella
#
# - name: Clean e2e profile
# run: rm /tmp/e2e-profile.out
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ verify-mod:

generate: controller-gen manifests generate-goclient

e2e-build:
hack/make-rules/build-e2e.sh

e2e-test:
go test -v ./tests/e2e/... -args -ginkgo.v
#bash hack/run-e2e-tests.sh

kind-load: docker-build
kind load docker-image ${IMAGE_REPO}/yurt-app-manager:${IMAGE_TAG} || { echo >&2 "kind not installed or error loading image: ${IMAGE_REPO}/yurt-app-manager:${IMAGE_TAG}"; exit 1; }

# Generate manifests, e.g., CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." paths="./pkg/yurtappmanager/..." output:crd:artifacts:config=config/yurt-app-manager/crd/bases output:rbac:artifacts:config=config/yurt-app-manager/rbac output:webhook:artifacts:config=config/yurt-app-manager/webhook
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/openyurtio/yurt-app-manager
go 1.16

require (
github.com/onsi/ginkgo v1.16.4
github.com/onsi/ginkgo/v2 v2.1.4
github.com/onsi/gomega v1.19.0
github.com/pkg/errors v0.9.1
Expand All @@ -17,6 +18,7 @@ require (
k8s.io/kubernetes v1.22.3
k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a
sigs.k8s.io/controller-runtime v0.10.3
sigs.k8s.io/yaml v1.2.0
)

replace (
Expand Down
2 changes: 2 additions & 0 deletions hack/lib/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ YURT_MOD="$(head -1 $YURT_ROOT/go.mod | awk '{print $2}')"
YURT_OUTPUT_DIR=${YURT_ROOT}/_output
YURT_LOCAL_BIN_DIR=${YURT_OUTPUT_DIR}/local/bin

YURT_E2E_TARGETS="tests/e2e/yurt-e2e-test"

PROJECT_PREFIX=${PROJECT_PREFIX:-yurt}
LABEL_PREFIX=${LABEL_PREFIX:-openyurt.io}
GIT_COMMIT=$(git rev-parse --short HEAD)
Expand Down
37 changes: 37 additions & 0 deletions hack/make-rules/build-e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

# Copyright 2020 The OpenYurt 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.

YURT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
source "${YURT_ROOT}/hack/lib/init.sh"
source "${YURT_ROOT}/hack/lib/build.sh"

function build_e2e() {
local goflags goldflags gcflags
goldflags="${GOLDFLAGS:--s -w $(project_info)}"
gcflags="${GOGCFLAGS:-}"
goflags=${GOFLAGS:-}


local target_bin_dir=$(get_binary_dir_with_arch ${YURT_LOCAL_BIN_DIR})
mkdir -p ${target_bin_dir}
cd ${target_bin_dir}
echo "Building ${YURT_E2E_TARGETS}"
local testpkg="$(dirname ${YURT_E2E_TARGETS})"
local filename="$(basename ${YURT_E2E_TARGETS})"
go test -c -gcflags "${gcflags:-}" ${goflags} -o $filename "$YURT_ROOT/${testpkg}"
}

build_e2e
43 changes: 43 additions & 0 deletions hack/run-e2e-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

# Copyright 2020 The OpenYurt 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.

set -x
set -e
set -u

YURT_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)
source "${YURT_ROOT}/hack/lib/init.sh"
source "${YURT_ROOT}/hack/lib/build.sh"

KUBECONFIG=${KUBECONFIG:-${HOME}/.kube/config}


# run e2e tests
function run_e2e_tests {
# check kubeconfig
if [ ! -f "${KUBECONFIG}" ]; then
echo "kubeconfig does not exist at ${KUBECONFIG}"
exit -1
fi

local target_bin_dir=$(get_binary_dir_with_arch ${YURT_LOCAL_BIN_DIR})
local e2e_test_file_name=$(basename ${YURT_E2E_TARGETS})
${target_bin_dir}/${e2e_test_file_name} -kubeconfig ${KUBECONFIG}
}

#deploy_app_manager

run_e2e_tests
49 changes: 49 additions & 0 deletions tests/e2e/e2e.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright 2022 The OpenYurt 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.
*/

package e2e

import (
"fmt"
"os"
"path"
"testing"

"github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/config"
"github.com/onsi/ginkgo/reporters"
"github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/klog"

"github.com/openyurtio/yurt-app-manager/tests/e2e/util/ginkgowrapper"
"github.com/openyurtio/yurt-app-manager/tests/e2e/yurtconfig"
)

func RunE2ETests(t *testing.T) {
klog.Infof("[edge] Start run e2e test")
gomega.RegisterFailHandler(ginkgowrapper.Fail)
var r []ginkgo.Reporter
if yurtconfig.YurtE2eCfg.ReportDir != "" {
if err := os.MkdirAll(yurtconfig.YurtE2eCfg.ReportDir, 0755); err != nil {
klog.Errorf("Failed creating report directory: %v", err)
} else {
r = append(r, reporters.NewJUnitReporter(path.Join(yurtconfig.YurtE2eCfg.ReportDir, fmt.Sprintf("yurt-e2e-test-report_%02d.xml", config.GinkgoConfig.ParallelNode))))
}
}
klog.Infof("Starting e2e run %q on Ginkgo node %d", uuid.NewUUID(), config.GinkgoConfig.ParallelNode)
ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "yurt-app-manager e2e suites", r)
}
Loading