github.com/jingruilea/kubeedge@v1.2.0-beta.0.0.20200410162146-4bb8902b3879/edge/test/integration/device/device_suite_test.go (about) 1 /* 2 Copyright 2019 The KubeEdge Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package device_test 18 19 import ( 20 "net/http" 21 "testing" 22 "time" 23 24 . "github.com/onsi/ginkgo" 25 . "github.com/onsi/gomega" 26 27 "github.com/kubeedge/kubeedge/edge/pkg/devicetwin/dtcommon" 28 "github.com/kubeedge/kubeedge/edge/test/integration/utils/common" 29 "github.com/kubeedge/kubeedge/edge/test/integration/utils/edge" 30 "github.com/kubeedge/kubeedge/edge/test/integration/utils/helpers" 31 ) 32 33 //context to load config and access across the package 34 var ( 35 ctx *edge.TestContext 36 cfg edge.Config 37 ) 38 39 //Interface to validate the MQTT connection. 40 type Token interface { 41 Wait() bool 42 WaitTimeout(time.Duration) bool 43 Error() error 44 } 45 46 const ( 47 Devicehandler = "/devices" 48 ) 49 50 var ( 51 //deviceupload topic 52 DeviceUpload = "$hw/events/upload/#" 53 //device status update topic "$hw/events/device/+/state/update" 54 DevicestatusUpdate = dtcommon.DeviceETPrefix + "+" + dtcommon.DeviceETStateUpdateSuffix 55 //device twin update topic "$hw/events/device/+/twin/+" 56 DeviceTwinUpdate = dtcommon.DeviceETPrefix + "+" + dtcommon.DeviceTwinModule + "/+" 57 //device membership update topic "$hw/events/node/+/membership/get" 58 DeviceMembershipUpdate = dtcommon.MemETPrefix + "+" + dtcommon.MemETGetSuffix 59 //upload record to cloud topic 60 UploadRecordToCloud = "SYS/dis/upload_records" 61 //client id used in MQTT connection 62 ClientID = "eventbus" 63 ) 64 65 //Function to run the Ginkgo Test 66 func TestEdgecoreEventBus(t *testing.T) { 67 68 RegisterFailHandler(Fail) 69 var _ = BeforeSuite(func() { 70 71 MemDeviceUpdate = &MembershipUpdate{} 72 common.Infof("Before Suite execution") 73 74 cfg = edge.LoadConfig() 75 ctx = edge.NewTestContext(cfg) 76 //Expect(utils.CreateEdgeCoreConfigFile()).Should(BeNil()) 77 //Expect(utils.StartEdgeCore()).Should(BeNil()) 78 }) 79 AfterSuite(func() { 80 By("After Suite Executing....!") 81 common.Infof("Remove Mock devices from edgenode !!") 82 83 //Deleting all the devices created for testing purposes. 84 IsDeviceDeleted := helpers.HandleAddAndDeleteDevice(http.MethodDelete, 85 ctx.Cfg.TestManager+Devicehandler, DeviceN) 86 Expect(IsDeviceDeleted).Should(BeTrue()) 87 88 IsDeviceDeleted = helpers.HandleAddAndDeleteDevice(http.MethodDelete, 89 ctx.Cfg.TestManager+Devicehandler, DeviceATT) 90 Expect(IsDeviceDeleted).Should(BeTrue()) 91 92 IsDeviceDeleted = helpers.HandleAddAndDeleteDevice(http.MethodDelete, 93 ctx.Cfg.TestManager+Devicehandler, DeviceTW) 94 Expect(IsDeviceDeleted).Should(BeTrue()) 95 }) 96 97 RunSpecs(t, "edgecore Suite") 98 }