diff options
| author | GsssC <914617455@qq.com> | 2021-05-19 18:16:38 +0800 |
|---|---|---|
| committer | GsssC <914617455@qq.com> | 2021-05-19 18:45:35 +0800 |
| commit | 7cd877ae3f9afb37e96681fb12b4abbade4abc74 (patch) | |
| tree | 1b5b80478239045996427fb3d23609d6ef31b07a /edge/test | |
| parent | delete all omitempty tag in enable (diff) | |
| download | kubeedge-7cd877ae3f9afb37e96681fb12b4abbade4abc74.tar.gz | |
add basic integration test for meta server
Signed-off-by: GsssC <914617455@qq.com>
Diffstat (limited to 'edge/test')
| -rw-r--r-- | edge/test/integration/metaserver/metaserver_suite_test.go | 37 | ||||
| -rw-r--r-- | edge/test/integration/metaserver/metaserver_test.go | 57 | ||||
| -rwxr-xr-x | edge/test/integration/scripts/fast_test.sh | 1 | ||||
| -rw-r--r-- | edge/test/integration/utils/test_setup.go | 13 |
4 files changed, 108 insertions, 0 deletions
diff --git a/edge/test/integration/metaserver/metaserver_suite_test.go b/edge/test/integration/metaserver/metaserver_suite_test.go new file mode 100644 index 000000000..485aa09d7 --- /dev/null +++ b/edge/test/integration/metaserver/metaserver_suite_test.go @@ -0,0 +1,37 @@ +package metaserver_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "github.com/kubeedge/kubeedge/edge/test/integration/utils" + "github.com/kubeedge/kubeedge/edge/test/integration/utils/common" + "github.com/kubeedge/kubeedge/edge/test/integration/utils/edge" + edgeconfig "github.com/kubeedge/kubeedge/pkg/apis/componentconfig/edgecore/v1alpha1" + "github.com/kubeedge/kubeedge/tests/integration/framework" +) + +func TestEdgecoreMetaServer(t *testing.T) { + RegisterFailHandler(Fail) + //var UID string + var _ = BeforeSuite(func() { + common.Infof("Before Suite Execution") + cfg := edge.LoadConfig() + + c := edgeconfig.NewDefaultEdgeCoreConfig() + framework.DisableAllModules(c) + c.Modules.Edged.HostnameOverride = cfg.NodeID + c.Modules.MetaManager.Enable = true + c.Modules.MetaManager.MetaServer.Enable = true + + Expect(utils.CfgToFile(c)).Should(BeNil()) + Expect(utils.StartEdgeCore()).Should(BeNil()) + }) + AfterSuite(func() { + By("After Suite Execution....!") + }) + + RunSpecs(t, "kubeedge metaserver Suite") +} diff --git a/edge/test/integration/metaserver/metaserver_test.go b/edge/test/integration/metaserver/metaserver_test.go new file mode 100644 index 000000000..681537919 --- /dev/null +++ b/edge/test/integration/metaserver/metaserver_test.go @@ -0,0 +1,57 @@ +package metaserver + +import ( + "net/http" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +var _ = Describe("Test MetaServer", func() { + Context("Test Access MetaServer at local", func() { + BeforeEach(func() { + }) + AfterEach(func() { + }) + It("Test NotFound response", func() { + var ( + coreAPIPrefix = "api" + coreAPIGroupVersion = schema.GroupVersion{Group: "", Version: "v1"} + prefix = "apis" + //testGroupVersion = schema.GroupVersion{Group: "test-group", Version: "test-version"} + ) + type T struct { + Method string + Path string + Status int + } + cases := map[string]T{ + // Positive checks to make sure everything is wired correctly + "List Core Cluster-Scope API": {"GET", "/" + coreAPIPrefix + "/" + coreAPIGroupVersion.Version + "/nodes", http.StatusOK}, + "List Core Namespace-Scope API": {"GET", "/" + coreAPIPrefix + "/" + coreAPIGroupVersion.Version + "/namespaces/ns/pods", http.StatusOK}, + "List Cluster-Scope API": {"GET", "/" + prefix + "/apiextensions.k8s.io/v1beta1/customresourcedefinitions", http.StatusOK}, + "List Namespace-Scope API": {"GET", "/" + prefix + "/apps/v1/namespaces/ns-foo/jobs", http.StatusOK}, + + "Get Core Cluster-Scope API": {"GET", "/" + coreAPIPrefix + "/" + coreAPIGroupVersion.Version + "/nodes/node-foo", http.StatusNotFound}, + "Get Core Namespace-Scope API": {"GET", "/" + coreAPIPrefix + "/" + coreAPIGroupVersion.Version + "/namespaces/ns/pods/pod-foo", http.StatusNotFound}, + "Get Cluster-Scope API": {"GET", "/" + prefix + "/apiextensions.k8s.io/v1beta1/customresourcedefinitions/crd-foo", http.StatusNotFound}, + "Get Namespace-Scope API": {"GET", "/" + prefix + "/apps/v1/namespaces/ns-foo/jobs/job-foo", http.StatusNotFound}, + + "Get Core Cluster-Scope API with extra segment": {"GET", "/" + coreAPIPrefix + "/" + coreAPIGroupVersion.Version + "/nodes/node-foo/baz", http.StatusNotFound}, + //"Watch with bad method": {"POST", "/" + prefix + "/" + testGroupVersion.Group + "/" + testGroupVersion.Version + "/watch/namespaces/ns/simples/", http.StatusMethodNotAllowed}, + //"Watch param with bad method": {"POST", "/" + prefix + "/" + testGroupVersion.Group + "/" + testGroupVersion.Version + "/namespaces/ns-foo/simples?watch=true", http.StatusMethodNotAllowed}, + } + client := http.Client{} + url := "http://127.0.0.1:10550" + for _, v := range cases { + request, err := http.NewRequest(v.Method, url+v.Path, nil) + Expect(err).Should(BeNil()) + response, err := client.Do(request) + Expect(err).Should(BeNil()) + isEqual := v.Status == response.StatusCode + Expect(isEqual).Should(BeTrue(), "Expected response status %v, Got %v", v.Status, response.Status) + } + }) + }) +}) diff --git a/edge/test/integration/scripts/fast_test.sh b/edge/test/integration/scripts/fast_test.sh index eb23f7423..2de3e0090 100755 --- a/edge/test/integration/scripts/fast_test.sh +++ b/edge/test/integration/scripts/fast_test.sh @@ -39,6 +39,7 @@ if [[ $# -eq 0 ]]; then export KUBEEDGE_ROOT=$KUBEEDGE_ROOT ./appdeployment/appdeployment.test $debugflag 2>&1 | tee -a /tmp/testcase.log ./device/device.test $debugflag 2>&1 | tee -a /tmp/testcase.log + ./metaserver/metaserver.test $debugflag 2>&1 | tee -a /tmp/testcase.log else ./$compilemodule/$compilemodule.test $debugflag $runtest 2>&1 | tee -a /tmp/testcase.log fi diff --git a/edge/test/integration/utils/test_setup.go b/edge/test/integration/utils/test_setup.go index dc40218e9..328d70159 100644 --- a/edge/test/integration/utils/test_setup.go +++ b/edge/test/integration/utils/test_setup.go @@ -22,6 +22,19 @@ const ( DBFile = "/tmp/edgecore/edgecore.db" ) +func CfgToFile(c *edgecore.EdgeCoreConfig) error { + data, err := yaml.Marshal(c) + if err != nil { + fmt.Printf("Marshal edgecore config to yaml error %v\n", err) + os.Exit(1) + } + if err := ioutil.WriteFile(EdgeCoreConfigFile, data, os.ModePerm); err != nil { + fmt.Printf("Create edgecore config file %v error %v\n", EdgeCoreConfigFile, err) + os.Exit(1) + } + return nil +} + func CreateEdgeCoreConfigFile(nodeName string) error { c := edgecore.NewDefaultEdgeCoreConfig() c.Modules.Edged.HostnameOverride = nodeName |
