Skip to content

Commit

Permalink
add e2e for http
Browse files Browse the repository at this point in the history
Signed-off-by: ii2day <ji.li@daocloud.io>
  • Loading branch information
ii2day committed Jun 28, 2023
1 parent e08bac9 commit ce5ca04
Show file tree
Hide file tree
Showing 16 changed files with 1,648 additions and 127 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ e2e_init:
make -C test deploy_metallb
make -C test deploy_contour
make -C test deploy_project
make -C test install_example_app
make -C test install_apiserver_token



Expand Down
30 changes: 10 additions & 20 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ deploy_project:
HELM_OPTION+=" --set kdoctorAgent.ingress.enable=false " ; \
fi ; \
HELM_OPTION+=" --set feature.aggregateReport.enabled=true " ; \
HELM_OPTION+=" --set feature.nethttp_defaultConcurrency=10 " ; \
HELM_OPTION+=" --set feature.aggregateReport.controller.reportHostPath=/var/run/kdoctor/controller " ; \
HELM_OPTION+=" --set kdoctorAgent.debug.logLevel=debug --set kdoctorController.debug.logLevel=debug " ; \
HELM_OPTION+=" --set kdoctorAgent.prometheus.enabled=true --set kdoctorController.prometheus.enabled=true " ; \
Expand Down Expand Up @@ -506,26 +507,12 @@ install_nginx:

#==========================

# test kind is ok
.PHONY: install_example_app
install_example_app: KIND_KUBECONFIG ?= $(E2E_KIND_KUBECONFIG_PATH)
install_example_app: KIND_CLUSTER_NAME ?= $(E2E_KIND_CLUSTER_NAME)
install_example_app: IMAGE_TAG ?= $(GIT_COMMIT_VERSION)
install_example_app:
@echo "---------- install example app"
sed 's?<<EXAMPLE_APP_IMAGE>>?ghcr.io/kdoctor-io/kdoctor-agent:'$(IMAGE_TAG)'?' yaml/testpod.yaml | kubectl --kubeconfig=$(KIND_KUBECONFIG) apply -f -
@ if ! kubectl rollout status daemonset/kdoctor-test -n kube-system --kubeconfig $(KIND_KUBECONFIG) -w --timeout=120s ; then \
kubectl get pod -A ; \
echo "error, failed to create a test pod" ; \
exit 1 ; \
fi ; \
echo "succeeded to deploy test deployment "
@echo "========================================================"
@echo " deploy kind cluster $(KIND_CLUSTER_NAME) "
@echo " export KUBECONFIG=$(KIND_KUBECONFIG) "
@echo " kubectl get pod -o wide -A "
@echo "========================================================"
@ KUBECONFIG=$(KIND_KUBECONFIG) kubectl get pod -o wide -A
.PHONY: install_apiserver_token
install_apiserver_token: KIND_KUBECONFIG ?= $(E2E_KIND_KUBECONFIG_PATH)
install_apiserver_token: KIND_CLUSTER_NAME ?= $(E2E_KIND_CLUSTER_NAME)
install_apiserver_token:
@echo "---------- install apiserver token"
sed 's?<<TEST_NAMESPACE>>?$(E2E_INSTALL_NAMESPACE)?' yaml/kdoctortoken.yaml | kubectl --kubeconfig=$(KIND_KUBECONFIG) apply -f -


.PHONY: clean
Expand All @@ -551,6 +538,9 @@ e2e_test:
echo "find cluster node: $${NODE_LIST}" ; \
export E2E_KIND_CLUSTER_NODE_LIST="$${NODE_LIST}" ; \
export E2E_CLUSTER_NAME=$(KIND_CLUSTER_NAME) ; \
export APISERVER=`kubectl config view --kubeconfig $(KIND_KUBECONFIG) |grep server | awk '{print $$2}'` ;\
export E2E_INSTALL_NAMESPACE=$(E2E_INSTALL_NAMESPACE) ;\
export GIT_COMMIT_VERSION=$(GIT_COMMIT_VERSION) ;\
if [ "$(E2E_IP_FAMILY)" == "ipv4" ] ; then \
export E2E_IPV4_ENABLED=true ; export E2E_IPV6_ENABLED=false ; \
elif [ "$(E2E_IP_FAMILY)" == "ipv6" ] ; then \
Expand Down
18 changes: 18 additions & 0 deletions test/docs/AppHttpHealth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# E2E Cases for AppHttpHealth

| Case ID | Title | Priority | Smoke | Status | Other |
|---------|-----------------------------------------------------------------------------|----------|-------|--------|-------------|
| A00001 | Successfully http testing appHttpHealth method GET case | p1 | | done | |
| A00002 | Failed http testing appHttpHealth due to status code case | p1 | | done | |
| A00003 | Failed http testing appHttpHealth due to delay case | p1 | | done | |
| A00004 | Successfully https testing appHttpHealth method GET case | p1 | | done | |
| A00005 | Failed https testing appHttpHealth due to tls case | p1 | | done | |
| A00006 | Successfully http testing appHttpHealth method PUT case | p1 | | done | |
| A00007 | Successfully http testing appHttpHealth method POST With Body case | p1 | | done | |
| A00008 | Successfully http testing appHttpHealth method HEAD case | p1 | | done | |
| A00009 | Successfully http testing appHttpHealth method PATCH case | p1 | | done | |
| A000010 | Successfully http testing appHttpHealth method OPTIONS case | p1 | | done | |
| A000011 | After QPS is specified, the number of requests meets the requirements case | p1 | | done | |
| A000012 | Successfully http testing appHttpHealth due to success rate case | p1 | | done | |
| A000013 | Successfully https testing appHttpHealth method GET Protocol Http2 case | p1 | | done | |
| A000014 | Report request count equal real request count case | p1 | | done | |
6 changes: 6 additions & 0 deletions test/docs/NetReach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# E2E Cases for IP NetReach

| Case ID | Title | Priority | Smoke | Status | Other |
|---------|--------------------------------------------------------|----------|-------|--------|-------------|
| B00001 | Successfully testing netReach case | p1 | | done | |

9 changes: 9 additions & 0 deletions test/docs/schedule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# E2E Cases for IP schedule

| Case ID | Title | Priority | Smoke | Status | Other |
|---------|-------------------------------------------------|----------|-------|--------|-------------|
| C00001 | Successfully testing NetReach crontab case | p1 | | done | |
| C00002 | Successfully testing AppHttpHealth crontab case | p1 | | done | |
| C00003 | Successfully testing NetReach sample case | p1 | | done | |
| C00004 | Successfully testing AppHttpHealth sample case | p1 | | done | |

134 changes: 134 additions & 0 deletions test/e2e/apphttphealth/apphttphealth_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Copyright 2023 Authors of kdoctor-io
// SPDX-License-Identifier: Apache-2.0

package apphttphealth_test

import (
"context"
kdoctor_v1beta1 "github.com/kdoctor-io/kdoctor/pkg/k8s/apis/kdoctor.io/v1beta1"
"github.com/kdoctor-io/kdoctor/test/e2e/common"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
e2e "github.com/spidernet-io/e2eframework/framework"
"github.com/spidernet-io/e2eframework/tools"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"testing"
"time"
)

func TestNetReach(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "AppHttpHealth Suite")
}

var frame *e2e.Framework

var commonSvcIP string
var countSvcIP string
var commonPodIPs = make([]string, 0)
var countPodIPs = make([]string, 0)

var httpPort = 80
var httpsPort = 443
var bodyConfigMapName string
var commonTestDsName string
var countTestDsName string

var _ = BeforeSuite(func() {
defer GinkgoRecover()
var e error
frame, e = e2e.NewFramework(GinkgoT(), []func(*runtime.Scheme) error{kdoctor_v1beta1.AddToScheme})
Expect(e).NotTo(HaveOccurred())

// test request body
bodyConfigMapName = "kdoctor-test-body-" + tools.RandomName()
cm := new(v1.ConfigMap)
cm.SetName(bodyConfigMapName)
cm.SetNamespace(common.TestNameSpace)
body := make(map[string]string, 0)
body["test1"] = "test1"
body["test2"] = "test2"
cm.Data = body
e = frame.CreateConfigmap(cm)
Expect(e).NotTo(HaveOccurred(), "create test body configmap")

// test pod
commonTestDsName = "kdoctor-test-server-" + tools.RandomName()
commonKey := metav1.ObjectMeta{
Name: commonTestDsName,
Namespace: common.TestNameSpace,
Labels: map[string]string{"app": commonTestDsName},
}
e = common.CreateDaemonSetAndService(frame, commonKey, true, false)
Expect(e).NotTo(HaveOccurred(), "create common test daemonSet and service")

// count test pod
countTestDsName = "kdoctor-test-server-" + tools.RandomName()
countKey := metav1.ObjectMeta{
Name: countTestDsName,
Namespace: common.TestNameSpace,
Labels: map[string]string{"app": countTestDsName},
}
e = common.CreateDaemonSetAndService(frame, countKey, true, true)
Expect(e).NotTo(HaveOccurred(), "create count test daemonSet and service")
// wait test ds ready
ctx, cancel := context.WithTimeout(context.Background(), time.Second*60)
defer cancel()
_, e = frame.WaitDaemonSetReady(commonTestDsName, common.TestNameSpace, ctx)
Expect(e).NotTo(HaveOccurred(), "wait common test daemonSet and service ready")
ctx2, cancel2 := context.WithTimeout(context.Background(), time.Second*60)
defer cancel2()
_, e = frame.WaitDaemonSetReady(countTestDsName, common.TestNameSpace, ctx2)
Expect(e).NotTo(HaveOccurred(), "wait count test daemonSet and service ready")

// get common test service ip and pod ip
commonSvc, e := frame.GetService(commonTestDsName, common.TestNameSpace)
Expect(e).NotTo(HaveOccurred(), "get kdoctor common test service")
commonSvcIP = commonSvc.Spec.ClusterIP
GinkgoWriter.Printf("get common service ip %v \n", commonSvcIP)

commonDs, e := frame.GetDaemonSet(commonTestDsName, common.TestNameSpace)
Expect(e).NotTo(HaveOccurred(), "get kdoctor common test daemonset")

commonPods, e := frame.GetDaemonSetPodList(commonDs)
Expect(e).NotTo(HaveOccurred(), "get kdoctor common test pod list")

for _, v := range commonPods.Items {
commonPodIPs = append(commonPodIPs, v.Status.PodIP)
}

GinkgoWriter.Printf("get common test pod ips %v \n", commonPodIPs)

// get count test service ip and pod ip
countSvc, e := frame.GetService(countTestDsName, common.TestNameSpace)
Expect(e).NotTo(HaveOccurred(), "get kdoctor count test service")
countSvcIP = countSvc.Spec.ClusterIP
GinkgoWriter.Printf("get count service ip %v \n", countSvcIP)

countDs, e := frame.GetDaemonSet(countTestDsName, common.TestNameSpace)
Expect(e).NotTo(HaveOccurred(), "get kdoctor count test daemonset")

countPods, e := frame.GetDaemonSetPodList(countDs)
Expect(e).NotTo(HaveOccurred(), "get kdoctor count test pod list")

for _, v := range countPods.Items {
countPodIPs = append(countPodIPs, v.Status.PodIP)
}

GinkgoWriter.Printf("get count test pod ips %v \n", countPodIPs)

})

var _ = AfterSuite(func() {
defer GinkgoRecover()
_ = frame.DeleteConfigmap(bodyConfigMapName, common.TestNameSpace)
// common
_ = frame.DeleteDaemonSet(commonTestDsName, common.TestNameSpace)
_ = frame.DeleteService(commonTestDsName, common.TestNameSpace)
// count
_ = frame.DeleteDaemonSet(countTestDsName, common.TestNameSpace)
_ = frame.DeleteService(countTestDsName, common.TestNameSpace)

})
Loading

0 comments on commit ce5ca04

Please sign in to comment.