How to use Label method of ginkgo Package

Best Ginkgo code snippet using ginkgo.Label

serial.go

Source:serial.go Github

copy

Full Screen

...156 framework.ExpectNoError(err, "failed to create TidbCluster: %v", tc)157 err = oa.WaitForTidbClusterReady(tc, 30*time.Minute, 5*time.Second)158 framework.ExpectNoError(err, "failed to wait for TidbCluster ready: %v", tc)159 ginkgo.By("Set tikv partition annotation to 1")160 err = setPartitionAnnotation(ns, tc.Name, label.TiKVLabelVal, 1)161 framework.ExpectNoError(err, "set tikv Partition annotation failed")162 ginkgo.By(fmt.Sprintf("Upgrade TidbCluster version to %q", utilimage.TiDBLatest))163 err = controller.GuaranteedUpdate(genericCli, tc, func() error {164 tc.Spec.Version = utilimage.TiDBLatest165 return nil166 })167 framework.ExpectNoError(err, "failed to update TidbCluster to upgrade tidb version to %v", utilimage.TiDBLatest)168 ginkgo.By(fmt.Sprintf("wait for tikv-1 pod upgrading to %q", utilimage.TiDBLatest))169 err = wait.Poll(5*time.Second, 10*time.Minute, func() (done bool, err error) {170 tikvPod, err := c.CoreV1().Pods(ns).Get(context.TODO(), fmt.Sprintf("%s-tikv-1", tc.Name), metav1.GetOptions{})171 if err != nil {172 return false, nil173 }174 if tikvPod.Spec.Containers[0].Image != fmt.Sprintf("pingcap/tikv:%s", utilimage.TiDBLatest) {175 return false, nil176 }177 return true, nil178 })179 framework.ExpectNoError(err, "failed to upgrade tikv-1 to %q", utilimage.TiDBLatest)180 ginkgo.By("Wait to see if tikv sts partition annotation remains 1 for 3 min")181 // TODO: explain the purpose of this testing182 err = wait.Poll(5*time.Second, 3*time.Minute, func() (done bool, err error) {183 tikvSts, err := c.AppsV1().StatefulSets(ns).Get(context.TODO(), fmt.Sprintf("%s-tikv", tc.Name), metav1.GetOptions{})184 if err != nil {185 return false, err186 }187 strategy := tikvSts.Spec.UpdateStrategy188 if strategy.RollingUpdate != nil && strategy.RollingUpdate.Partition != nil &&189 *strategy.RollingUpdate.Partition == int32(1) {190 return false, nil191 }192 return true, nil193 })194 framework.ExpectEqual(err, wait.ErrWaitTimeout, "tikv sts partition annotation should remain 1 for 3 min")195 ginkgo.By("Set tc annotations to nil")196 err = controller.GuaranteedUpdate(genericCli, tc, func() error {197 tc.Annotations = nil198 return nil199 })200 framework.ExpectNoError(err, "failed to set TidbCluster annotation to nil: %v", tc)201 // TODO: find a more graceful way to check tidbcluster during upgrading202 err = oa.WaitForTidbClusterReady(tc, 30*time.Minute, 5*time.Second)203 framework.ExpectNoError(err, "failed to wait for TidbCluster ready: %v", tc)204 })205 })206 ginkgo.Describe("[Feature: Defaulting and Validating]", func() {207 var ocfg *tests.OperatorConfig208 var oa *tests.OperatorActions209 ginkgo.BeforeEach(func() {210 ocfg = &tests.OperatorConfig{211 Namespace: ns,212 ReleaseName: "operator",213 Image: cfg.OperatorImage,214 Tag: cfg.OperatorTag,215 SchedulerImage: "k8s.gcr.io/kube-scheduler",216 LogLevel: "4",217 ImagePullPolicy: v1.PullIfNotPresent,218 TestMode: true,219 WebhookEnabled: false,220 ValidatingEnabled: true,221 DefaultingEnabled: true,222 SchedulerReplicas: util.IntPtr(0),223 ControllerManagerReplicas: util.IntPtr(0),224 }225 oa = tests.NewOperatorActions(cli, c, asCli, aggrCli, apiExtCli, tests.DefaultPollInterval, ocfg, e2econfig.TestConfig, fw, f)226 ginkgo.By("Installing CRDs")227 oa.CleanCRDOrDie()228 oa.CreateCRDOrDie(ocfg)229 ginkgo.By("Installing tidb-operator")230 oa.CleanOperatorOrDie(ocfg)231 oa.DeployOperatorOrDie(ocfg)232 })233 ginkgo.AfterEach(func() {234 ginkgo.By("Uninstall tidb-operator")235 oa.CleanOperatorOrDie(ocfg)236 ginkgo.By("Uninstalling CRDs")237 oa.CleanCRDOrDie()238 })239 ginkgo.It("should perform defaulting and validating properly", func() {240 ginkgo.By("Deploy a legacy tc")241 legacyTc := &v1alpha1.TidbCluster{242 ObjectMeta: metav1.ObjectMeta{243 Namespace: ns,244 Name: "created-by-helm",245 },246 Spec: v1alpha1.TidbClusterSpec{247 TiDB: &v1alpha1.TiDBSpec{248 Replicas: 1,249 ComponentSpec: v1alpha1.ComponentSpec{250 Image: fmt.Sprintf("pingcap/tidb:%s", utilimage.TiDBLatestPrev),251 },252 },253 TiKV: &v1alpha1.TiKVSpec{254 Replicas: 1,255 ComponentSpec: v1alpha1.ComponentSpec{256 Image: fmt.Sprintf("pingcap/tikv:%s", utilimage.TiDBLatestPrev),257 },258 ResourceRequirements: v1.ResourceRequirements{259 Requests: v1.ResourceList{260 v1.ResourceStorage: resource.MustParse("10G"),261 },262 },263 },264 PD: &v1alpha1.PDSpec{265 Replicas: 1,266 ComponentSpec: v1alpha1.ComponentSpec{267 Image: fmt.Sprintf("pingcap/pd:%s", utilimage.TiDBLatestPrev),268 },269 ResourceRequirements: v1.ResourceRequirements{270 Requests: v1.ResourceList{271 v1.ResourceStorage: resource.MustParse("10G"),272 },273 },274 },275 },276 }277 var err error278 legacyTc, err = cli.PingcapV1alpha1().TidbClusters(ns).Create(context.TODO(), legacyTc, metav1.CreateOptions{})279 // err := genericCli.Create(context.TODO(),context.TODO(), legacyTc)280 framework.ExpectNoError(err, "Expected create tidbcluster without defaulting and validating")281 ginkgo.By("Enable webhook in operator")282 ocfg.WebhookEnabled = true283 oa.UpgradeOperatorOrDie(ocfg)284 // now the webhook enabled285 err = controller.GuaranteedUpdate(genericCli, legacyTc, func() error {286 legacyTc.Spec.TiDB.Image = fmt.Sprintf("pingcap/tidb:%s", utilimage.TiDBLatest)287 return nil288 })289 framework.ExpectNoError(err, "Update legacy TidbCluster should not be influenced by validating")290 framework.ExpectEqual(legacyTc.Spec.TiDB.BaseImage, "", "Update legacy tidbcluster should not be influenced by defaulting")291 ginkgo.By("Update TidbCluster to use webhook")292 err = controller.GuaranteedUpdate(genericCli, legacyTc, func() error {293 legacyTc.Spec.TiDB.BaseImage = "pingcap/tidb"294 legacyTc.Spec.TiKV.BaseImage = "pingcap/tikv"295 legacyTc.Spec.PD.BaseImage = "pingcap/pd"296 legacyTc.Spec.PD.Version = pointer.StringPtr(utilimage.TiDBLatest)297 return nil298 })299 framework.ExpectNoError(err, "failed to update TidbCluster")300 ginkgo.By("Set empty values to test validating")301 err = controller.GuaranteedUpdate(genericCli, legacyTc, func() error {302 legacyTc.Spec.TiDB.BaseImage = ""303 legacyTc.Spec.PD.Version = pointer.StringPtr("")304 return nil305 })306 framework.ExpectError(err, "Validating should reject empty mandatory fields")307 ginkgo.By("Deploy a new tc with legacy fields")308 // TODO: explain the purpose of this testing309 newTC := &v1alpha1.TidbCluster{310 ObjectMeta: metav1.ObjectMeta{311 Namespace: ns,312 Name: "newly-created",313 },314 Spec: v1alpha1.TidbClusterSpec{315 TiDB: &v1alpha1.TiDBSpec{316 ComponentSpec: v1alpha1.ComponentSpec{317 Image: fmt.Sprintf("pingcap/tidb:%s", utilimage.TiDBLatest),318 },319 },320 TiKV: &v1alpha1.TiKVSpec{321 ComponentSpec: v1alpha1.ComponentSpec{322 Image: fmt.Sprintf("pingcap/tikv:%s", utilimage.TiDBLatest),323 },324 ResourceRequirements: v1.ResourceRequirements{325 Requests: v1.ResourceList{326 v1.ResourceStorage: resource.MustParse("10G"),327 },328 },329 },330 PD: &v1alpha1.PDSpec{331 ComponentSpec: v1alpha1.ComponentSpec{332 Image: fmt.Sprintf("pingcap/pd:%s", utilimage.TiDBLatest),333 },334 ResourceRequirements: v1.ResourceRequirements{335 Requests: v1.ResourceList{336 v1.ResourceStorage: resource.MustParse("10G"),337 },338 },339 },340 },341 }342 _, err = cli.PingcapV1alpha1().TidbClusters(ns).Create(context.TODO(), newTC, metav1.CreateOptions{})343 framework.ExpectError(err, "Validating should reject legacy fields for newly created cluster")344 ginkgo.By("Deploy a new tc")345 newTC = &v1alpha1.TidbCluster{346 ObjectMeta: metav1.ObjectMeta{347 Namespace: ns,348 Name: "newly-created",349 },350 Spec: v1alpha1.TidbClusterSpec{351 Version: utilimage.TiDBLatest,352 TiDB: &v1alpha1.TiDBSpec{353 Replicas: 1,354 },355 TiKV: &v1alpha1.TiKVSpec{356 Replicas: 1,357 ResourceRequirements: v1.ResourceRequirements{358 Requests: v1.ResourceList{359 v1.ResourceStorage: resource.MustParse("10G"),360 },361 },362 },363 PD: &v1alpha1.PDSpec{364 Replicas: 1,365 ResourceRequirements: v1.ResourceRequirements{366 Requests: v1.ResourceList{367 v1.ResourceStorage: resource.MustParse("10G"),368 },369 },370 },371 },372 }373 newTC, err = cli.PingcapV1alpha1().TidbClusters(ns).Create(context.TODO(), newTC, metav1.CreateOptions{})374 framework.ExpectNoError(err, "required fields should be set by defaulting")375 // don't have to check all fields, just take some to test if defaulting set376 if empty, err := gomega.BeEmpty().Match(newTC.Spec.TiDB.BaseImage); empty {377 log.Failf("Expected tidb.baseImage has default value set, %v", err)378 }379 ginkgo.By("Update tc with invalid instance label value")380 err = controller.GuaranteedUpdate(genericCli, newTC, func() error {381 newTC.Labels = map[string]string{382 label.InstanceLabelKey: "some-insane-label-value",383 }384 return nil385 })386 framework.ExpectError(err, "Could not set instance label with value other than cluster name")387 ginkgo.By("Update pd replication config in tc")388 err = controller.GuaranteedUpdate(genericCli, newTC, func() error {389 c := v1alpha1.NewPDConfig()390 c.Set("replication.max-replicas", 5)391 newTC.Spec.PD.Config = c392 return nil393 })394 framework.ExpectError(err, "PD replication config is immutable through CR")395 })396 })397 ginkgo.Describe("Canary Deploy TiDB Operator", func() {398 var oa *tests.OperatorActions399 var ocfg *tests.OperatorConfig400 ginkgo.BeforeEach(func() {401 ocfg = &tests.OperatorConfig{402 Namespace: ns,403 ReleaseName: "operator",404 Image: cfg.OperatorImage,405 Tag: cfg.OperatorTag,406 ImagePullPolicy: v1.PullIfNotPresent,407 }408 oa = tests.NewOperatorActions(cli, c, asCli, aggrCli, apiExtCli, tests.DefaultPollInterval, ocfg, e2econfig.TestConfig, fw, f)409 ginkgo.By("Installing CRDs")410 oa.CleanCRDOrDie()411 oa.CreateCRDOrDie(ocfg)412 ginkgo.By("Installing tidb-operator")413 oa.CleanOperatorOrDie(ocfg)414 oa.DeployOperatorOrDie(ocfg)415 })416 ginkgo.AfterEach(func() {417 ginkgo.By("Uninstall tidb-operator")418 oa.CleanOperatorOrDie(ocfg)419 ginkgo.By("Uninstalling CRDs")420 oa.CleanCRDOrDie()421 })422 ginkgo.It("Deploy TidbCluster and check the result", func() {423 tcName := "tidbcluster1"424 tc := fixture.GetTidbCluster(ns, tcName, utilimage.TiDBLatestPrev)425 tc.Spec.PD.Replicas = 1426 tc.Spec.TiKV.Replicas = 1427 tc.Spec.TiDB.Replicas = 1428 ginkgo.By(fmt.Sprintf("deploy original tc %q", utilimage.TiDBLatestPrev))429 utiltc.MustCreateTCWithComponentsReady(genericCli, oa, tc, 10*time.Minute, 5*time.Second)430 pdPods := utilpod.MustListPods(labels.SelectorFromSet(label.New().Instance(tcName).PD().Labels()).String(), ns, c)431 ginkgo.By("Set --selector=version=old for the default TiDB Operator")432 ocfg.Selector = []string{"version=old"}433 oa.UpgradeOperatorOrDie(ocfg)434 log.Logf("Upgrade operator with --set-string \"selector=version=old\"")435 ginkgo.By("Upgrade TidbCluster 1 version, wait for 2 minutes, check that no rolling update occurs")436 err := controller.GuaranteedUpdate(genericCli, tc, func() error {437 tc.Spec.Version = utilimage.TiDBLatest438 return nil439 })440 framework.ExpectNoError(err, "failed to update TidbCluster 1 to upgrade PD version to %v", utilimage.TiDBLatest)441 err = wait.Poll(5*time.Second, 2*time.Minute, func() (done bool, err error) {442 // confirm the TidbCluster 1 PD haven't been changed443 changed, err := utilpod.PodsAreChanged(c, pdPods)()444 if err != nil {445 log.Logf("ERROR: meet error during verify TidbCluster 1 PD pods, err:%v", err)446 return false, err447 }448 if changed {449 return true, nil450 }451 log.Logf("confirm TidbCluster 1 PD pods haven't been changed this time")452 return false, nil453 })454 framework.ExpectEqual(err, wait.ErrWaitTimeout, "expect TidbCluster 1 PD haven't been changed for 2 minutes")455 log.Logf("Upgrade TidbCluster 1 to new version, but no rolling update occurs")456 ginkgo.By("Set label version=old to TidbCluster 1, check that PD of TidbCluster 1 has been rolling updated")457 err = controller.GuaranteedUpdate(genericCli, tc, func() error {458 tc.Labels = map[string]string{"version": "old"}459 return nil460 })461 framework.ExpectNoError(err, "failed to update TidbCluster 1 to set label version=old")462 err = wait.Poll(5*time.Second, 5*time.Minute, func() (done bool, err error) {463 // confirm the PD Pods have been changed464 changed, err := utilpod.PodsAreChanged(c, pdPods)()465 if err != nil {466 log.Logf("ERROR: meet error during verify PD pods, err:%v", err)467 return false, err468 }469 if changed {470 return true, nil471 }472 log.Logf("PD pods haven't been changed yet")473 return false, nil474 })475 framework.ExpectNoError(err, "expect PD pods have been changed in 5 minutes")476 log.Logf("Upgrade TidbCluster 1 with label version=old and PD pods have been rolling updated.")477 ginkgo.By("Deploy TidbCluster 2 with label version=new")478 tc2Name := "tidbcluster2"479 tc2 := fixture.GetTidbCluster(ns, tc2Name, utilimage.TiDBLatestPrev)480 tc2.Spec.PD.Replicas = 1481 tc2.Spec.TiKV.Replicas = 1482 tc2.Spec.TiDB.Replicas = 1483 tc2.Labels = map[string]string{"version": "new"}484 err = genericCli.Create(context.TODO(), tc2)485 framework.ExpectNoError(err, "Expected Tidbcluster 2 be created")486 log.Logf("Finished deploying TidbCluster 2 with label version=new")487 ginkgo.By("Wait for 2 minutes and check that no PD Pod is created")488 err = wait.Poll(5*time.Second, 2*time.Minute, func() (created bool, err error) {489 // confirm the Tidbcluster 2 PD Pods don't be created490 pdPods, err = utilpod.ListPods(labels.SelectorFromSet(label.New().Instance(tc2Name).PD().Labels()).String(), ns, c)491 if err != nil {492 log.Logf("ERROR: meet error during get PD pods, err:%v", err)493 return false, nil494 }495 if len(pdPods) != 0 {496 return true, nil497 }498 log.Logf("Tidbcluster 2 PD pods have not been created yet")499 return false, nil500 })501 framework.ExpectEqual(err, wait.ErrWaitTimeout, "No PD Pods created for Tidbcluster 2")502 log.Logf("Confirm that no PD Pods created for Tidbcluster 2")503 ginkgo.By("Deploy TiDB Operator 2 with --selector=version=new")504 ocfg2 := &tests.OperatorConfig{505 Namespace: ns + "-canary-deploy",506 ReleaseName: "operator2",507 Image: cfg.OperatorImage,508 Tag: cfg.OperatorTag,509 ImagePullPolicy: v1.PullIfNotPresent,510 Selector: []string{"version=new"},511 //FIXME: AppendReleaseSuffix: true,512 }513 oa.DeployOperatorOrDie(ocfg2)514 log.Logf("Finished deploying TiDB Operator 2 with --selector=version=new")515 ginkgo.By("Check TidbCluster 2 is ready")516 err = oa.WaitForTidbClusterReady(tc2, 10*time.Minute, 5*time.Second)517 framework.ExpectNoError(err, "Expected TiDB cluster2 ready")518 log.Logf("confirm TidbCluster 2 is ready")519 ginkgo.By("Delete the default TiDB Operator")520 oa.CleanOperatorOrDie(ocfg)521 log.Logf("Finished deleting the default Operator")522 ginkgo.By("Upgrade TiDB version of TidbCluster 2")523 err = controller.GuaranteedUpdate(genericCli, tc2, func() error {524 tc2.Spec.Version = utilimage.TiDBLatest525 return nil526 })527 framework.ExpectNoError(err, "failed to update TidbCluster 2 to upgrade tidb version to %v", utilimage.TiDBLatest)528 log.Logf("Finished upgrading TidbCluster 2")529 err = oa.WaitForTidbClusterReady(tc2, 10*time.Minute, 10*time.Second)530 framework.ExpectNoError(err, "failed to wait for TidbCluster %s/%s components ready", ns, tc2.Name)531 ginkgo.By(fmt.Sprintf("wait for TidbCluster 2 pd-0 pod upgrading to %q", utilimage.TiDBLatest))532 err = wait.Poll(5*time.Second, 10*time.Minute, func() (done bool, err error) {533 pdPod, err := c.CoreV1().Pods(ns).Get(context.TODO(), fmt.Sprintf("%s-pd-0", tc2.Name), metav1.GetOptions{})534 if err != nil {535 return false, nil536 }537 if pdPod.Spec.Containers[0].Image != fmt.Sprintf("pingcap/pd:%s", utilimage.TiDBLatest) {538 return false, nil539 }540 return true, nil541 })542 framework.ExpectNoError(err, "failed to upgrade TidbCluster 2 pd-0 to %q", utilimage.TiDBLatest)543 log.Logf("Finished upgrading TidbCluster 2")544 ginkgo.By("Deploy the default TiDB Operator with --selector=version=old")545 ocfg = &tests.OperatorConfig{546 Namespace: ns,547 ReleaseName: "operator",548 Image: cfg.OperatorImage,549 Tag: cfg.OperatorTag,550 ImagePullPolicy: v1.PullIfNotPresent,551 Selector: []string{"version=old"},552 }553 oa.DeployOperatorOrDie(ocfg)554 log.Logf("Finished deploying TiDB Operator 1 with --selector=version=old")555 ginkgo.By("Delete the TiDB Operator 2")556 oa.CleanOperatorOrDie(ocfg2)557 log.Logf("Finished deleting the Operator 2")558 ginkgo.By("Scale-out TiDB of TidbCluster 1, wait for 5 minuts, check that scale up occurs")559 err = controller.GuaranteedUpdate(genericCli, tc, func() error {560 tc.Spec.TiDB.Replicas = 2561 return nil562 })563 framework.ExpectNoError(err, "failed to scale out TidbCluster 1")564 err = wait.Poll(5*time.Second, 5*time.Minute, func() (done bool, err error) {565 tidbStatefulSet, err := c.AppsV1().StatefulSets(ns).Get(context.TODO(), fmt.Sprintf("%s-tidb", tc.Name), metav1.GetOptions{})566 if err != nil {567 return false, nil568 }569 if *tidbStatefulSet.Spec.Replicas != 2 {570 return false, nil571 }572 return true, nil573 })574 framework.ExpectNoError(err, "expect TiDB in tidbcluster 1 to scale out to 2")575 log.Logf("Succeed to scale out TiDB of TidbCluster 1")576 })577 })578 ginkgo.Describe("Upgrade TiDB Operator", func() {579 var (580 operatorVersion string581 oa *tests.OperatorActions582 ocfg *tests.OperatorConfig583 )584 ginkgo.JustBeforeEach(func() {585 // deploy older operator and CRDs586 ocfg = &tests.OperatorConfig{587 Namespace: ns,588 ReleaseName: "operator",589 Tag: operatorVersion,590 Image: fmt.Sprintf("pingcap/tidb-operator:%s", operatorVersion),591 }592 oa = tests.NewOperatorActions(cli, c, asCli, aggrCli, apiExtCli, tests.DefaultPollInterval, ocfg, e2econfig.TestConfig, fw, f)593 ginkgo.By("Installing CRDs")594 oa.CleanCRDOrDie()595 oa.CreateReleasedCRDOrDie(operatorVersion)596 ginkgo.By("Installing TiDB Operator")597 oa.CleanOperatorOrDie(ocfg)598 oa.DeployOperatorOrDie(ocfg)599 })600 ginkgo.JustAfterEach(func() {601 // clean current operator and CRDs602 ginkgo.By("Uninstall tidb-operator")603 oa.CleanOperatorOrDie(ocfg)604 ginkgo.By("Uninstalling CRDs")605 oa.CleanCRDOrDie()606 })607 ginkgo.Context("From latest version", func() {608 ginkgo.BeforeEach(func() {609 operatorVersion = OperatorLatestVersion610 })611 ginkgo.It("should not trigger rolling-update", func() {612 tcName := fmt.Sprintf("upgrade-operator-from-%s", strings.ReplaceAll(operatorVersion, ".", "x"))613 tc := fixture.GetTidbCluster(ns, tcName, utilimage.TiDBLatest)614 tc = fixture.AddTiFlashForTidbCluster(tc)615 tc = fixture.AddTiCDCForTidbCluster(tc)616 tc = fixture.AddPumpForTidbCluster(tc)617 tc.Spec.PD.Replicas = 1618 tc.Spec.TiKV.Replicas = 1619 tc.Spec.TiDB.Replicas = 1620 tc.Spec.TiFlash.Replicas = 1621 ginkgo.By("Deploy original TiDB cluster")622 utiltc.MustCreateTCWithComponentsReady(genericCli, oa, tc, 6*time.Minute, 5*time.Second)623 selector := MustGetLabelSelectorForComponents(tcName, label.DiscoveryLabelVal) // ingore discovery624 pods := utilpod.MustListPods(selector.String(), ns, c)625 ginkgo.By("Upgrade TiDB Operator and CRDs to current version")626 ocfg.Tag = cfg.OperatorTag627 ocfg.Image = cfg.OperatorImage628 oa.ReplaceCRDOrDie(ocfg)629 oa.UpgradeOperatorOrDie(ocfg)630 ginkgo.By("Wait for pods are not changed in 5 minutes")631 err := utilpod.WaitForPodsAreChanged(c, pods, time.Minute*5)632 framework.ExpectEqual(err, wait.ErrWaitTimeout, "pods should not change in 5 minutes")633 })634 })635 ginkgo.Context("From prev major version", func() {636 ginkgo.BeforeEach(func() {637 operatorVersion = OperatorPrevMajorVersion638 })639 type testCase struct {640 name string641 tls bool642 }643 cases := []testCase{644 {645 name: "should not trigger rolling-update and database work fine",646 tls: false,647 },648 {649 name: "should not trigger rolling-update and database work fine with TLS-enabled",650 tls: true,651 },652 }653 for i := range cases {654 testcase := cases[i]655 ginkgo.It(testcase.name, func() {656 dbName := "test"657 tables := []string{"test_0", "test_1", "test_2"}658 recordCount := 30659 batchCount := 100660 expectCount := recordCount * batchCount661 bw := blockwriter.New(blockwriter.WithTableNum(len(tables)),662 blockwriter.WithRecordNum(recordCount),663 blockwriter.WithBatchSize(batchCount),664 blockwriter.WithGenTableName(func(nr int) string {665 return tables[nr]666 }))667 tcName := fmt.Sprintf("upgrade-operator-from-%s", strings.ReplaceAll(operatorVersion, ".", "x"))668 tc := fixture.GetTidbCluster(ns, tcName, utilimage.TiDBLatestPrev)669 tc = fixture.AddTiFlashForTidbCluster(tc)670 tc = fixture.AddTiCDCForTidbCluster(tc)671 tc = fixture.AddPumpForTidbCluster(tc)672 tc.Spec.PD.Replicas = 1673 tc.Spec.TiKV.Replicas = 1674 tc.Spec.TiDB.Replicas = 1675 tc.Spec.TiFlash.Replicas = 1676 if testcase.tls {677 tc.Spec.TiDB.TLSClient = &v1alpha1.TiDBTLSClient{Enabled: true}678 tc.Spec.TLSCluster = &v1alpha1.TLSCluster{Enabled: true}679 ginkgo.By("Installing tidb CA certificate")680 err := InstallTiDBIssuer(ns, tcName)681 framework.ExpectNoError(err, "failed to install CA certificate")682 ginkgo.By("Installing tidb server and client certificate")683 err = InstallTiDBCertificates(ns, tcName)684 framework.ExpectNoError(err, "failed to install tidb server and client certificate")685 ginkgo.By("Installing tidbInitializer client certificate")686 err = installTiDBInitializerCertificates(ns, tcName)687 framework.ExpectNoError(err, "failed to install tidbInitializer client certificate")688 ginkgo.By("Installing dashboard client certificate")689 err = installPDDashboardCertificates(ns, tcName)690 framework.ExpectNoError(err, "failed to install dashboard client certificate")691 ginkgo.By("Installing tidb components certificates")692 err = InstallTiDBComponentsCertificates(ns, tcName)693 framework.ExpectNoError(err, "failed to install tidb components certificates")694 }695 ginkgo.By("Deploy original TiDB cluster with prev version")696 utiltc.MustCreateTCWithComponentsReady(genericCli, oa, tc, 6*time.Minute, 5*time.Second)697 selector := MustGetLabelSelectorForComponents(tcName, label.DiscoveryLabelVal) // ingore discovery698 pods := utilpod.MustListPods(selector.String(), ns, c)699 dsn, fwcancel, err := utiltidb.PortForwardAndGetTiDBDSN(fw, ns, tcName, "root", "", dbName)700 framework.ExpectNoError(err, "failed to get dsn")701 defer fwcancel()702 db := utildb.NewDatabaseOrDie(dsn)703 defer db.Close()704 ginkgo.By("Prepare data in database")705 err = bw.Write(context.Background(), dsn)706 framework.ExpectNoError(err, "failed to write data")707 ginkgo.By("Create TiFlash replicas for table 0 and ensure it is ready")708 MustCreateTiFlashReplicationForTable(db, dbName, tables[0], expectCount)709 ginkgo.By("Upgrade TiDB Operator and CRDs to current version")710 ocfg.Tag = cfg.OperatorTag711 ocfg.Image = cfg.OperatorImage712 oa.ReplaceCRDOrDie(ocfg)713 oa.UpgradeOperatorOrDie(ocfg)714 ginkgo.By("Wait for pods are not changed in 5 minutes")715 err = utilpod.WaitForPodsAreChanged(c, pods, time.Minute*5)716 framework.ExpectEqual(err, wait.ErrWaitTimeout, "pods should not change in 5 minutes")717 ginkgo.By("Ensure records in table 0 have not changed after upgrading TiDB Operator")718 EnsureRecordsNotChangedForTables(db, "tiflash", dbName, tables[0:1], expectCount)719 EnsureRecordsNotChangedForTables(db, "tikv", dbName, tables[0:1], expectCount)720 ginkgo.By("Create TiFlash replicas for table 1 and ensure it is ready")721 MustCreateTiFlashReplicationForTable(db, dbName, tables[1], expectCount)722 ginkgo.By("Update TiDB cluster to latest version")723 err = controller.GuaranteedUpdate(genericCli, tc, func() error {724 tc.Spec.Version = utilimage.TiDBLatest725 return nil726 })727 framework.ExpectNoError(err, "failed to upgrade TidbCluster: %q", tc.Name)728 err = oa.WaitForTidbClusterReady(tc, 7*time.Minute, 5*time.Second)729 framework.ExpectNoError(err, "waiting for cluster %q ready", tcName)730 // reopen db after upgrade731 dsn2, fwcancel2, err := utiltidb.PortForwardAndGetTiDBDSN(fw, ns, tcName, "root", "", dbName)732 framework.ExpectNoError(err, "failed to get dsn")733 defer fwcancel2()734 db2 := utildb.NewDatabaseOrDie(dsn2)735 defer db2.Close()736 ginkgo.By("Ensure records in table 0 and table 1 have not changed after upgrading TiDB Operator")737 EnsureRecordsNotChangedForTables(db2, "tiflash", dbName, tables[0:2], expectCount)738 EnsureRecordsNotChangedForTables(db2, "tikv", dbName, tables[0:2], expectCount)739 ginkgo.By("Create TiFlash replicas for table 2 and ensure it is ready")740 MustCreateTiFlashReplicationForTable(db2, dbName, tables[2], expectCount)741 })742 }743 })744 ginkgo.Context("From v1.1.7", func() {745 ginkgo.BeforeEach(func() {746 operatorVersion = "v1.1.7"747 })748 ginkgo.It("should not change old TidbCluster", func() {749 tcName := fmt.Sprintf("upgrade-operator-from-%s", strings.ReplaceAll(operatorVersion, ".", "x"))750 tc := fixture.GetTidbCluster(ns, tcName, utilimage.TiDBV5x3)751 tc = fixture.AddTiFlashForTidbCluster(tc)752 tc = fixture.AddTiCDCForTidbCluster(tc)753 tc = fixture.AddPumpForTidbCluster(tc)754 tc.Spec.PD.Replicas = 3755 tc.Spec.TiKV.Replicas = 1756 tc.Spec.TiDB.Replicas = 1757 tc.Spec.TiCDC.Config = nil758 ginkgo.By("Deploy original TiDB cluster")759 utiltc.MustCreateTCWithComponentsReady(genericCli, oa, tc, 10*time.Minute, 5*time.Second)760 selector := MustGetLabelSelectorForComponents(tcName,761 label.DiscoveryLabelVal,762 label.PumpLabelVal,763 label.TiCDCLabelVal, // ingore ticdc because of PR #4494764 )765 pods := utilpod.MustListPods(selector.String(), ns, c)766 ginkgo.By("Upgrade TiDB Operator and CRDs to current version")767 ocfg.Tag = cfg.OperatorTag768 ocfg.Image = cfg.OperatorImage769 oa.ReplaceCRDOrDie(ocfg)770 oa.UpgradeOperatorOrDie(ocfg)771 ginkgo.By("Wait for pods are not changed in 5 minutes")772 err := utilpod.WaitForPodsAreChanged(c, pods, time.Minute*5)773 framework.ExpectEqual(err, wait.ErrWaitTimeout, "pods should not change in 5 minutes")774 })775 /*776 Release: v1.2.0777 new feature in https://github.com/pingcap/tidb-operator/pull/3440778 deploy tidbmonitor and upgrade tidb-perator, then tidbmonitor should switch from deployment to statefulset779 */780 ginkgo.It("should migrate tidbmonitor from deployment to sts", func() {781 tcName := "smooth-tidbcluster"782 tc := fixture.GetTidbCluster(ns, tcName, utilimage.TiDBLatest)783 tc.Spec.PD.Replicas = 1784 tc.Spec.TiKV.Replicas = 1785 tc.Spec.TiDB.Replicas = 1786 ginkgo.By("Deploy original TiDB cluster")787 utiltc.MustCreateTCWithComponentsReady(genericCli, oa, tc, 6*time.Minute, 5*time.Second)788 ginkgo.By("Deploy tidb monitor")789 monitorName := "smooth-migrate"790 tc, err := cli.PingcapV1alpha1().TidbClusters(ns).Get(context.TODO(), tcName, metav1.GetOptions{})791 framework.ExpectNoError(err, "failed to get tidbcluster")792 tm := fixture.NewTidbMonitor(monitorName, ns, tc, true, true, true)793 _, err = cli.PingcapV1alpha1().TidbMonitors(ns).Create(context.TODO(), tm, metav1.CreateOptions{})794 framework.ExpectNoError(err, "Expected tidbmonitor deployed success")795 err = tests.CheckTidbMonitor(tm, cli, c, fw)796 framework.ExpectNoError(err, "Expected tidbmonitor checked success")797 deploymentPvcName := fmt.Sprintf("%s-monitor", monitorName)798 deploymentPvc, err := c.CoreV1().PersistentVolumeClaims(ns).Get(context.TODO(), deploymentPvcName, metav1.GetOptions{})799 framework.ExpectNoError(err, "Expected tidbmonitor deployment pvc success")800 oldVolumeName := deploymentPvc.Spec.VolumeName801 ginkgo.By("Upgrade tidb-operator and CRDs to the latest version")802 ocfg.Tag = cfg.OperatorTag803 ocfg.Image = cfg.OperatorImage804 oa.ReplaceCRDOrDie(ocfg)805 oa.UpgradeOperatorOrDie(ocfg)806 err = tests.CheckTidbMonitor(tm, cli, c, fw)807 framework.ExpectNoError(err, "Expected tidbmonitor checked success under migration")808 err = wait.Poll(5*time.Second, 3*time.Minute, func() (done bool, err error) {809 tmSet, err := stsGetter.StatefulSets(ns).Get(context.TODO(), monitor.GetMonitorObjectName(tm), metav1.GetOptions{})810 if err != nil {811 log.Logf("ERROR: failed to get statefulset: %s/%s, %v", ns, tmSet, err)812 return false, nil813 }814 return true, nil815 })816 framework.ExpectNoError(err, "Expected tidbmonitor sts success")817 err = wait.Poll(5*time.Second, 5*time.Minute, func() (done bool, err error) {818 newStsPvcName := monitor.GetMonitorFirstPVCName(tm.Name)819 log.Logf("tidbmonitor newStsPvcName:%s", newStsPvcName)820 stsPvc, err := c.CoreV1().PersistentVolumeClaims(ns).Get(context.TODO(), newStsPvcName, metav1.GetOptions{})821 if err != nil {822 if errors.IsNotFound(err) {823 log.Logf("tm[%s/%s]'s first sts pvc not found,tag:%s,image:%s", ns, tm.Name, cfg.OperatorTag, cfg.OperatorImage)824 return false, nil825 }826 log.Logf("ERROR: get tidbmonitor sts pvc err:%v", err)827 return false, nil828 }829 if stsPvc.Spec.VolumeName == oldVolumeName {830 return true, nil831 }832 log.Logf("tidbmonitor sts pv unequal to old deployment pv")833 return false, nil834 })835 framework.ExpectNoError(err, "Expected tidbmonitor sts use pv of old deployment")836 err = tests.CheckTidbMonitor(tm, cli, c, fw)837 framework.ExpectNoError(err, "Expected tidbmonitor checked success")838 })839 })840 })841})842func setPartitionAnnotation(namespace, tcName, component string, ordinal int) error {843 // add annotation to pause statefulset upgrade process844 output, err := framework.RunKubectl(namespace, "annotate", "tc", tcName, fmt.Sprintf("tidb.pingcap.com/%s-partition=%d", component, ordinal), "--overwrite")845 if err != nil {846 return fmt.Errorf("fail to set annotation for [%s/%s], component: %s, partition: %d, err: %v, output: %s", namespace, tcName, component, ordinal, err, output)847 }848 return nil849}850func MustGetLabelSelectorForComponents(tcName string, filterComponents ...string) labels.Selector {851 selector := labels.SelectorFromSet(label.New().Instance(tcName).Labels())852 r, err := labels.NewRequirement(label.ComponentLabelKey, selection.NotIn, filterComponents)853 framework.ExpectNoError(err, "failed to create label requirement")854 return selector.Add(*r)855}856// MustCreateTiFlashReplicationForTable create TiFLash replication and ensure it is ready857func MustCreateTiFlashReplicationForTable(db *utildb.Database, dbName string, table string, expectCount int) {858 err := utildb.CreateTiFlashReplicationAndWaitToComplete(db.TiFlashAction(), dbName, table, 1, time.Minute)859 framework.ExpectNoError(err, "failed to create TiFlash replication for %s", table)860 count, err := utildb.Count(db, "tiflash", dbName, table)861 framework.ExpectNoError(err, "failed to count records in %s by using %s", table, "tiflash")862 framework.ExpectEqual(count, expectCount, "count of records in %s changed by using %s", table, "tiflash")863}864// EnsureRecordsNotChangedForTables ensure records not changed for tables865func EnsureRecordsNotChangedForTables(db *utildb.Database, engine string, dbName string, tables []string, expectCount int) {866 for _, table := range tables {...

Full Screen

Full Screen

label_test.go

Source:label_test.go Github

copy

Full Screen

1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17package label18import (19 "net/http"20 "github.com/onsi/ginkgo"21 "github.com/apisix/manager-api/test/e2enew/base"22)23var _ = ginkgo.Describe("Test label", func() {24 ginkgo.Context("test label", func() {25 ginkgo.It("config route", func() {26 base.RunTestCase(base.HttpTestCase{27 Object: base.ManagerApiExpect(),28 Path: "/apisix/admin/routes/r1",29 Method: http.MethodPut,30 Body: `{31 "name": "route1",32 "uri": "/hello",33 "labels": {34 "build":"16",35 "env":"production",36 "version":"v2"37 },38 "upstream": {39 "type": "roundrobin",40 "nodes": [{41 "host": "` + base.UpstreamIp + `",42 "port": 1980,43 "weight": 144 }]45 }46 }`,47 Headers: map[string]string{"Authorization": base.GetToken()},48 ExpectStatus: http.StatusOK,49 })50 })51 ginkgo.It("create consumer", func() {52 base.RunTestCase(base.HttpTestCase{53 Object: base.ManagerApiExpect(),54 Path: "/apisix/admin/consumers/c1",55 Method: http.MethodPut,56 Body: `{57 "username": "c1",58 "plugins": {59 "key-auth": {60 "key": "auth-one"61 }62 },63 "labels": {64 "build":"16",65 "env":"production",66 "version":"v3"67 },68 "desc": "test description"69 }`,70 Headers: map[string]string{"Authorization": base.GetToken()},71 ExpectStatus: http.StatusOK,72 })73 })74 ginkgo.It("create upstream", func() {75 base.RunTestCase(base.HttpTestCase{76 Object: base.ManagerApiExpect(),77 Method: http.MethodPut,78 Path: "/apisix/admin/upstreams/u1",79 Body: `{80 "nodes": [{81 "host": "` + base.UpstreamIp + `",82 "port": 1980,83 "weight": 184 }],85 "labels": {86 "build":"17",87 "env":"production",88 "version":"v2"89 },90 "type": "roundrobin"91 }`,92 Headers: map[string]string{"Authorization": base.GetToken()},93 ExpectStatus: http.StatusOK,94 })95 })96 ginkgo.It("create service", func() {97 base.RunTestCase(base.HttpTestCase{98 Object: base.ManagerApiExpect(),99 Method: http.MethodPost,100 Path: "/apisix/admin/services",101 Body: `{102 "id": "s1",103 "plugins": {104 "limit-count": {105 "count": 2,106 "time_window": 60,107 "rejected_code": 503,108 "key": "remote_addr"109 }110 },111 "upstream": {112 "type": "roundrobin",113 "nodes": [{114 "host": "39.97.63.215",115 "port": 80,116 "weight": 1117 }]118 },119 "labels": {120 "build":"16",121 "env":"production",122 "version":"v2",123 "extra": "test"124 }125 }`,126 Headers: map[string]string{"Authorization": base.GetToken()},127 ExpectStatus: http.StatusOK,128 })129 })130 ginkgo.It("create plugin_config", func() {131 base.RunTestCase(base.HttpTestCase{132 Object: base.ManagerApiExpect(),133 Method: http.MethodPut,134 Path: "/apisix/admin/plugin_configs/1",135 Body: `{136 "plugins": {137 "response-rewrite": {138 "headers": {139 "X-VERSION":"22.0"140 }141 }142 },143 "labels": {144 "version": "v2",145 "build": "17",146 "extra": "test"147 }148 }`,149 Headers: map[string]string{"Authorization": base.GetToken()},150 ExpectStatus: http.StatusOK,151 })152 })153 ginkgo.It("get route label", func() {154 base.RunTestCase(base.HttpTestCase{155 Object: base.ManagerApiExpect(),156 Method: http.MethodGet,157 Headers: map[string]string{"Authorization": base.GetToken()},158 Path: "/apisix/admin/labels/route",159 ExpectStatus: http.StatusOK,160 ExpectBody: "{\"build\":\"16\"},{\"env\":\"production\"},{\"version\":\"v2\"}",161 Sleep: base.SleepTime,162 })163 })164 ginkgo.It("get consumer label", func() {165 base.RunTestCase(base.HttpTestCase{166 Object: base.ManagerApiExpect(),167 Method: http.MethodGet,168 Headers: map[string]string{"Authorization": base.GetToken()},169 Path: "/apisix/admin/labels/consumer",170 ExpectStatus: http.StatusOK,171 ExpectBody: "{\"build\":\"16\"},{\"env\":\"production\"},{\"version\":\"v3\"}",172 })173 })174 ginkgo.It("get upstream label", func() {175 base.RunTestCase(base.HttpTestCase{176 Object: base.ManagerApiExpect(),177 Method: http.MethodGet,178 Headers: map[string]string{"Authorization": base.GetToken()},179 Path: "/apisix/admin/labels/upstream",180 ExpectStatus: http.StatusOK,181 ExpectBody: "{\"build\":\"17\"},{\"env\":\"production\"},{\"version\":\"v2\"}",182 })183 })184 ginkgo.It("get service label", func() {185 base.RunTestCase(base.HttpTestCase{186 Object: base.ManagerApiExpect(),187 Method: http.MethodGet,188 Headers: map[string]string{"Authorization": base.GetToken()},189 Path: "/apisix/admin/labels/service",190 ExpectStatus: http.StatusOK,191 ExpectBody: "{\"build\":\"16\"},{\"env\":\"production\"},{\"extra\":\"test\"},{\"version\":\"v2\"}",192 })193 })194 ginkgo.It("get plugin_config label", func() {195 base.RunTestCase(base.HttpTestCase{196 Object: base.ManagerApiExpect(),197 Method: http.MethodGet,198 Headers: map[string]string{"Authorization": base.GetToken()},199 Path: "/apisix/admin/labels/plugin_config",200 ExpectStatus: http.StatusOK,201 ExpectBody: "{\"build\":\"17\"},{\"extra\":\"test\"},{\"version\":\"v2\"}",202 })203 })204 ginkgo.It("update plugin_config", func() {205 base.RunTestCase(base.HttpTestCase{206 Object: base.ManagerApiExpect(),207 Method: http.MethodPut,208 Path: "/apisix/admin/plugin_configs/1",209 Body: `{210 "plugins": {211 "response-rewrite": {212 "headers": {213 "X-VERSION":"22.0"214 }215 }216 },217 "labels": {218 "version": "v3",219 "build": "16",220 "extra": "test"221 }222 }`,223 Headers: map[string]string{"Authorization": base.GetToken()},224 ExpectStatus: http.StatusOK,225 })226 })227 ginkgo.It("get plugin_config label again to verify update", func() {228 base.RunTestCase(base.HttpTestCase{229 Object: base.ManagerApiExpect(),230 Method: http.MethodGet,231 Headers: map[string]string{"Authorization": base.GetToken()},232 Path: "/apisix/admin/labels/plugin_config",233 ExpectStatus: http.StatusOK,234 ExpectBody: "{\"build\":\"16\"},{\"extra\":\"test\"},{\"version\":\"v3\"}",235 Sleep: base.SleepTime,236 })237 })238 ginkgo.It("get all label", func() {239 base.RunTestCase(base.HttpTestCase{240 Object: base.ManagerApiExpect(),241 Method: http.MethodGet,242 Headers: map[string]string{"Authorization": base.GetToken()},243 Path: "/apisix/admin/labels/all",244 ExpectStatus: http.StatusOK,245 ExpectBody: "{\"build\":\"16\"},{\"build\":\"17\"},{\"env\":\"production\"},{\"extra\":\"test\"},{\"version\":\"v2\"},{\"version\":\"v3\"}",246 })247 })248 ginkgo.It("get label with page", func() {249 base.RunTestCase(base.HttpTestCase{250 Object: base.ManagerApiExpect(),251 Method: http.MethodGet,252 Query: "page=1&page_size=1",253 Headers: map[string]string{"Authorization": base.GetToken()},254 Path: "/apisix/admin/labels/all",255 ExpectStatus: http.StatusOK,256 ExpectBody: "{\"build\":\"16\"}",257 })258 })259 ginkgo.It("get label with page", func() {260 base.RunTestCase(base.HttpTestCase{261 Object: base.ManagerApiExpect(),262 Method: http.MethodGet,263 Query: "page=3&page_size=1",264 Headers: map[string]string{"Authorization": base.GetToken()},265 Path: "/apisix/admin/labels/all",266 ExpectStatus: http.StatusOK,267 ExpectBody: "{\"env\":\"production\"}",268 })269 })270 ginkgo.It("get labels (key = build)", func() {271 base.RunTestCase(base.HttpTestCase{272 Object: base.ManagerApiExpect(),273 Method: http.MethodGet,274 Headers: map[string]string{"Authorization": base.GetToken()},275 Query: "label=build",276 Path: "/apisix/admin/labels/all",277 ExpectStatus: http.StatusOK,278 ExpectBody: "{\"build\":\"16\"},{\"build\":\"17\"}",279 })280 })281 ginkgo.It("get labels with the same key (key = build)", func() {282 base.RunTestCase(base.HttpTestCase{283 Object: base.ManagerApiExpect(),284 Method: http.MethodGet,285 Headers: map[string]string{"Authorization": base.GetToken()},286 Query: "label=build:16,build:17",287 Path: "/apisix/admin/labels/all",288 ExpectStatus: http.StatusOK,289 ExpectBody: "{\"build\":\"16\"},{\"build\":\"17\"}",290 })291 })292 ginkgo.It("get labels (key = build) with page", func() {293 base.RunTestCase(base.HttpTestCase{294 Object: base.ManagerApiExpect(),295 Method: http.MethodGet,296 Headers: map[string]string{"Authorization": base.GetToken()},297 Query: "label=build&page=2&page_size=1",298 Path: "/apisix/admin/labels/all",299 ExpectStatus: http.StatusOK,300 ExpectBody: "{\"build\":\"17\"}",301 })302 })303 ginkgo.It("get labels with same key (key = build) and page", func() {304 base.RunTestCase(base.HttpTestCase{305 Object: base.ManagerApiExpect(),306 Method: http.MethodGet,307 Headers: map[string]string{"Authorization": base.GetToken()},308 Query: "label=build:16,build:17&page=1&page_size=2",309 Path: "/apisix/admin/labels/all",310 ExpectStatus: http.StatusOK,311 ExpectBody: "{\"build\":\"16\"},{\"build\":\"17\"}",312 })313 })314 ginkgo.It("get labels with same key (key = build) and page", func() {315 base.RunTestCase(base.HttpTestCase{316 Object: base.ManagerApiExpect(),317 Method: http.MethodGet,318 Headers: map[string]string{"Authorization": base.GetToken()},319 Query: "label=build:16,build:17&page=2&page_size=1",320 Path: "/apisix/admin/labels/all",321 ExpectStatus: http.StatusOK,322 ExpectBody: "{\"build\":\"17\"}",323 })324 })325 ginkgo.It("get labels (key = build && env = production)", func() {326 base.RunTestCase(base.HttpTestCase{327 Object: base.ManagerApiExpect(),328 Method: http.MethodGet,329 Headers: map[string]string{"Authorization": base.GetToken()},330 Query: "label=build,env:production",331 Path: "/apisix/admin/labels/all",332 ExpectStatus: http.StatusOK,333 ExpectBody: "{\"build\":\"16\"},{\"build\":\"17\"},{\"env\":\"production\"}",334 })335 })336 ginkgo.It("get labels (build=16 | 17 and env = production)", func() {337 base.RunTestCase(base.HttpTestCase{338 Object: base.ManagerApiExpect(),339 Method: http.MethodGet,340 Headers: map[string]string{"Authorization": base.GetToken()},341 Query: "label=build:16,build:17,env:production",342 Path: "/apisix/admin/labels/all",343 ExpectStatus: http.StatusOK,344 ExpectBody: "{\"build\":\"16\"},{\"build\":\"17\"},{\"env\":\"production\"}",345 })346 })347 ginkgo.It("get labels (key = build && env = production) with page", func() {348 base.RunTestCase(base.HttpTestCase{349 Object: base.ManagerApiExpect(),350 Method: http.MethodGet,351 Headers: map[string]string{"Authorization": base.GetToken()},352 Query: "label=build,env:production&page=3&page_size=1",353 Path: "/apisix/admin/labels/all",354 ExpectStatus: http.StatusOK,355 ExpectBody: "{\"env\":\"production\"}",356 })357 })358 ginkgo.It("delete route", func() {359 base.RunTestCase(base.HttpTestCase{360 Object: base.ManagerApiExpect(),361 Method: http.MethodDelete,362 Path: "/apisix/admin/routes/r1",363 Headers: map[string]string{"Authorization": base.GetToken()},364 ExpectStatus: http.StatusOK,365 })366 })367 ginkgo.It("delete consumer", func() {368 base.RunTestCase(base.HttpTestCase{369 Object: base.ManagerApiExpect(),370 Method: http.MethodDelete,371 Path: "/apisix/admin/consumers/c1",372 Headers: map[string]string{"Authorization": base.GetToken()},373 ExpectStatus: http.StatusOK,374 })375 })376 ginkgo.It("delete service", func() {377 base.RunTestCase(base.HttpTestCase{378 Object: base.ManagerApiExpect(),379 Method: http.MethodDelete,380 Path: "/apisix/admin/services/s1",381 Headers: map[string]string{"Authorization": base.GetToken()},382 ExpectStatus: http.StatusOK,383 })384 })385 ginkgo.It("delete upstream", func() {386 base.RunTestCase(base.HttpTestCase{387 Object: base.ManagerApiExpect(),388 Method: http.MethodDelete,389 Path: "/apisix/admin/upstreams/u1",390 Headers: map[string]string{"Authorization": base.GetToken()},391 ExpectStatus: http.StatusOK,392 })393 })394 ginkgo.It("delete plugin_config", func() {395 base.RunTestCase(base.HttpTestCase{396 Object: base.ManagerApiExpect(),397 Method: http.MethodDelete,398 Path: "/apisix/admin/plugin_configs/1",399 Headers: map[string]string{"Authorization": base.GetToken()},400 ExpectStatus: http.StatusOK,401 })402 })403 })404})...

Full Screen

Full Screen

Label

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 gomega.RegisterFailHandler(ginkgo.Fail)4 ginkgo.RunSpecs(ginkgo.NewDefaultSuite(), "1 Suite")5}6import (7var _ = ginkgo.Describe("1", func() {8 gomega.RegisterFailHandler(ginkgo.Fail)9 ginkgo.RunSpecs(ginkgo.NewDefaultSuite(), "1 Suite")10})11import (12var _ = ginkgo.Describe("1", func() {13 gomega.RegisterFailHandler(ginkgo.Fail)14 ginkgo.RunSpecs(ginkgo.NewDefaultSuite(), "1 Suite")15})16Your name to display (optional):17Your name to display (optional):

Full Screen

Full Screen

Label

Using AI Code Generation

copy

Full Screen

1ginkgo.Label("label1")2ginkgo.Label("label2")3ginkgo.Label("label3")4ginkgo.Label("label4")5ginkgo.Label("label5")6ginkgo.Label("label6")7ginkgo.Label("label7")8ginkgo.Label("label8")9ginkgo.Label("label9")10ginkgo.Label("label10")11ginkgo.Label("label11")12ginkgo.Label("label12")13ginkgo.Label("label13")14ginkgo.Label("label14")15ginkgo.Label("label15")16ginkgo.Label("label16")17ginkgo.Label("label17")18ginkgo.Label("label18")19ginkgo.Label("label19")20ginkgo.Label("label20")21ginkgo.Label("label21")22ginkgo.Label("label22")

Full Screen

Full Screen

Label

Using AI Code Generation

copy

Full Screen

1import (2var _ = ginkgo.Describe("My First Test", func() {3 ginkgo.It("should work", func() {4 gomega.Expect(1).To(gomega.Equal(1))5 })6})7import (8var _ = ginkgo.Describe("My First Test", func() {9 ginkgo.It("should work", func() {10 gomega.Expect(1).To(gomega.Equal(1))11 })12})13import (14var _ = ginkgo.Describe("My First Test", func() {15 ginkgo.It("should work", func() {16 gomega.Expect(1).To(gomega.Equal(1))17 })18})19import (20var _ = ginkgo.Describe("My First Test", func() {21 ginkgo.It("should work", func() {22 gomega.Expect(1).To(gomega.Equal(1))23 })24})25import (26var _ = ginkgo.Describe("My First Test", func() {27 ginkgo.It("should work", func() {28 gomega.Expect(1).To(gomega.Equal(1))29 })30})31import (32var _ = ginkgo.Describe("My First Test", func() {

Full Screen

Full Screen

Label

Using AI Code Generation

copy

Full Screen

1ginkgo.Label("1st Test")2Expect(1).To(Equal(1))3ginkgo.Label("2nd Test")4Expect(1).To(Equal(1))5ginkgo.Label("3rd Test")6Expect(1).To(Equal(1))7ginkgo.Label("4th Test")8Expect(1).To(Equal(1))9ginkgo.Label("5th Test")10Expect(1).To(Equal(1))11ginkgo.Label("6th Test")12Expect(1).To(Equal(1))13ginkgo.Label("7th Test")14Expect(1).To(Equal(1))15ginkgo.Label("8th Test")16Expect(1).To(Equal(1))17ginkgo.Label("9th Test")18Expect(1).To(Equal(1))19ginkgo.Label("10th Test")20Expect(1).To(Equal(1))21ginkgo.Label("11th Test")22Expect(1).To(Equal(1))23ginkgo.Label("12th Test")24Expect(1).To(Equal(1))25ginkgo.Label("13th Test")26Expect(1).To(Equal(1))27ginkgo.Label("14th Test")28Expect(1).To(Equal(1

Full Screen

Full Screen

Label

Using AI Code Generation

copy

Full Screen

1var _ = Describe("My First Test", func() {2 It("should be true", func() {3 Expect(true).Should(BeTrue())4 })5})6var _ = Describe("My Second Test", func() {7 It("should be true", func() {8 Expect(true).Should(BeTrue())9 })10})11var _ = Describe("My Third Test", func() {12 It("should be true", func() {13 Expect(true).Should(BeTrue())14 })15})16var _ = Describe("My Fourth Test", func() {17 It("should be true", func() {18 Expect(true).Should(BeTrue())19 })20})21var _ = Describe("My Fifth Test", func() {22 It("should be true", func() {23 Expect(true).Should(BeTrue())24 })25})26var _ = Describe("My Sixth Test", func() {27 It("should be true", func() {28 Expect(true).Should(BeTrue())29 })30})31var _ = Describe("My Seventh Test", func() {32 It("should be true", func() {33 Expect(true).Should(BeTrue())34 })35})36var _ = Describe("My Eighth Test", func() {37 It("should be true", func() {38 Expect(true).Should(BeTrue())39 })40})41var _ = Describe("My Ninth Test", func() {42 It("should be true", func() {43 Expect(true).Should(BeTrue())44 })45})46var _ = Describe("My Tenth Test", func() {47 It("should be true", func() {48 Expect(true).Should(BeTrue

Full Screen

Full Screen

Label

Using AI Code Generation

copy

Full Screen

1func Test1(t *testing.T) {2 g := ginkgo.GinkgoT(t)3 g.Label("Test1")4 g.By("Step 1")5 g.By("Step 2")6 g.By("Step 3")7}8func Test2(t *testing.T) {9 g := ginkgo.GinkgoT(t)10 g.Label("Test2")11 g.By("Step 1")12 g.By("Step 2")13 g.By("Step 3")14}

Full Screen

Full Screen

Label

Using AI Code Generation

copy

Full Screen

1ginkgo.Label("Test Case 1")2ginkgo.It("should do something", func() {3 gomega.Expect(1).Should(gomega.BeEquivalentTo(1))4})5ginkgo.Label("Test Case 2")6ginkgo.It("should do something", func() {7 gomega.Expect(1).Should(gomega.BeEquivalentTo(1))8})9ginkgo.Label("Test Case 3")10ginkgo.It("should do something", func() {11 gomega.Expect(1).Should(gomega.BeEquivalentTo(1))12})13ginkgo.Label("Test Case 4")14ginkgo.It("should do something", func() {15 gomega.Expect(1).Should(gomega.BeEquivalentTo(1))16})17ginkgo.Label("Test Case 5")18ginkgo.It("should do something", func() {19 gomega.Expect(1).Should(gomega.BeEquivalentTo(1))20})21ginkgo.Label("Test Case 6")22ginkgo.It("should do something", func() {23 gomega.Expect(1).Should(gomega.BeEquivalentTo(1))24})25ginkgo.Label("Test Case 7")26ginkgo.It("

Full Screen

Full Screen

Label

Using AI Code Generation

copy

Full Screen

1import "github.com/onsi/ginkgo"2func main() {3 ginkgo.Label("Example of using Label method")4}5import "github.com/onsi/ginkgo"6func main() {7 ginkgo.By("Example of using By method")8}9import "github.com/onsi/ginkgo"10func main() {11 ginkgo.Describe("Example of using Describe method", func() {12 ginkgo.It("Example of using It method", func() {13 })14 })15}16import "github.com/onsi/ginkgo"17func main() {18 ginkgo.BeforeSuite(func() {19 })20}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful