|
| 1 | +// Copyright (c) 2019-2025 Red Hat, Inc. |
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +// you may not use this file except in compliance with the License. |
| 4 | +// You may obtain a copy of the License at |
| 5 | +// |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | + |
| 14 | +package tests |
| 15 | + |
| 16 | +import ( |
| 17 | + "fmt" |
| 18 | + "strings" |
| 19 | + |
| 20 | + dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" |
| 21 | + "github.com/devfile/devworkspace-operator/test/e2e/pkg/config" |
| 22 | + "github.com/onsi/ginkgo/v2" |
| 23 | +) |
| 24 | + |
| 25 | +var _ = ginkgo.Describe("[DevWorkspace Debug Start Mode]", func() { |
| 26 | + defer ginkgo.GinkgoRecover() |
| 27 | + |
| 28 | + ginkgo.It("Wait DevWorkspace Webhook Server Pod", func() { |
| 29 | + controllerLabel := "app.kubernetes.io/name=devworkspace-webhook-server" |
| 30 | + |
| 31 | + deploy, err := config.AdminK8sClient.WaitForPodRunningByLabel(config.OperatorNamespace, controllerLabel) |
| 32 | + if err != nil { |
| 33 | + ginkgo.Fail(fmt.Sprintf("cannot get the DevWorkspace Webhook Server Pod status with label %s: %s", controllerLabel, err.Error())) |
| 34 | + return |
| 35 | + } |
| 36 | + |
| 37 | + if !deploy { |
| 38 | + ginkgo.Fail("Devworkspace webhook didn't start properly") |
| 39 | + } |
| 40 | + }) |
| 41 | + |
| 42 | + ginkgo.It("Add Debug DevWorkspace to cluster and wait starting status", func() { |
| 43 | + commandResult, err := config.DevK8sClient.OcApplyWorkspace(config.DevWorkspaceNamespace, "test/resources/simple-devworkspace-debug-start-annotation.yaml") |
| 44 | + if err != nil { |
| 45 | + ginkgo.Fail(fmt.Sprintf("Failed to create DevWorkspace: %s %s", err.Error(), commandResult)) |
| 46 | + return |
| 47 | + } |
| 48 | + |
| 49 | + deploy, err := config.DevK8sClient.WaitDevWsStatus("code-latest-with-debug-start", config.DevWorkspaceNamespace, dw.DevWorkspaceStatusStarting) |
| 50 | + if !deploy { |
| 51 | + ginkgo.Fail(fmt.Sprintf("DevWorkspace didn't start properly. Error: %s", err)) |
| 52 | + } |
| 53 | + }) |
| 54 | + |
| 55 | + ginkgo.It("Check DevWorkspace Conditions for Debug Start message", func() { |
| 56 | + devWorkspaceStatus, err := config.DevK8sClient.GetDevWsStatus("code-latest-with-debug-start", config.DevWorkspaceNamespace) |
| 57 | + if err != nil { |
| 58 | + ginkgo.Fail(fmt.Sprintf("Failure in fetching DevWorkspace status. Error: %s", err)) |
| 59 | + } |
| 60 | + |
| 61 | + expectedSubstring := "Debug mode: failed postStart commands will be trapped; inspect logs/exec to debug" |
| 62 | + |
| 63 | + found := false |
| 64 | + for _, cond := range devWorkspaceStatus.Conditions { |
| 65 | + if cond.Message != "" && strings.Contains(cond.Message, expectedSubstring) { |
| 66 | + found = true |
| 67 | + break |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + if !found { |
| 72 | + ginkgo.Fail(fmt.Sprintf( |
| 73 | + "DevWorkspace status does not contain expected debug message.\nExpected substring: %q\nGot conditions: %+v", |
| 74 | + expectedSubstring, devWorkspaceStatus.Conditions, |
| 75 | + )) |
| 76 | + } |
| 77 | + }) |
| 78 | +}) |
0 commit comments