Skip to content

Commit 3daeaa3

Browse files
authored
[integration-test] add smoke test for each main build (#16523)
1 parent 695e528 commit 3daeaa3

File tree

4 files changed

+162
-4
lines changed

4 files changed

+162
-4
lines changed

.github/workflows/preview-env-check-regressions.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ jobs:
5151
needs: [configuration]
5252
if: ${{ needs.configuration.outputs.skip == 'false' }}
5353
runs-on: [self-hosted]
54+
container:
55+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:kylos101-kubecdl-home.1
5456
steps:
5557
- uses: actions/checkout@v3
5658
- name: Create preview environment infrastructure
@@ -68,7 +70,58 @@ jobs:
6870
sa_key: ${{ secrets.GCP_CREDENTIALS }}
6971
version: ${{ needs.configuration.outputs.version}}
7072
- name: Check
73+
shell: bash
74+
env:
75+
ROBOQUAT_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+
USERNAME: ${{ secrets.IDE_INTEGRATION_TEST_USERNAME }}
77+
USER_TOKEN: ${{ secrets.IDE_INTEGRATION_TEST_USER_TOKEN }}
78+
PREVIEW_ENV_DEV_SA_KEY: ${{ secrets.GCP_CREDENTIALS }}
79+
PREVIEW_NAME: ${{ needs.configuration.outputs.name }}
7180
run: |
81+
set -euo pipefail
82+
83+
export LEEWAY_WORKSPACE_ROOT="$(pwd)"
84+
export HOME="/home/gitpod"
85+
export PREVIEW_ENV_DEV_SA_KEY_PATH="/home/gitpod/.config/gcloud/preview-environment-dev-sa.json"
86+
87+
echo "${PREVIEW_ENV_DEV_SA_KEY}" > "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
88+
gcloud auth activate-service-account --key-file "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
89+
90+
leeway run dev/preview/previewctl:install
91+
92+
echo "Setting up access to core-dev and harvester"
93+
previewctl get-credentials --gcp-service-account "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
94+
95+
previewctl install-context --branch "${PREVIEW_NAME}" --log-level debug --timeout 1m --gcp-service-account "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
96+
97+
# start integration test
98+
args=()
99+
args+=( "-kubeconfig=/home/gitpod/.kube/config" )
100+
args+=( "-namespace=default" )
101+
[[ "$USERNAME" != "" ]] && args+=( "-username=$USERNAME" )
102+
args+=( "-timeout=60m" )
103+
104+
TESTS_DIR="$GITHUB_WORKSPACE/test/tests/smoke-test"
105+
106+
go install github.com/jstemmer/go-junit-report/v2@latest
107+
108+
echo "running integration for smoke test"
109+
110+
cd "${TESTS_DIR}"
111+
set +e
112+
go test -v ./... "${args[@]}" 2>&1 | go-junit-report -subtest-mode=exclude-parents -set-exit-code -out "TEST.xml" -iocopy
113+
RC=${PIPESTATUS[0]}
114+
set -e
115+
116+
if [ "${RC}" -ne "0" ]; then
117+
exit ${RC}
118+
fi
119+
- name: Test Summary
120+
id: test_summary
121+
uses: test-summary/action@v2
122+
with:
123+
paths: "test/tests/**/TEST.xml"
124+
if: always()
72125
echo "No regressions caught because I didn't check anything 🤡 Sleeping for 2 minutes."
73126
sleep 60
74127
- name: Delete preview environment

test/pkg/integration/workspace.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,20 @@ func LaunchWorkspaceFromContextURL(t *testing.T, ctx context.Context, contextURL
378378
}
379379

380380
t.Logf("attemp to get the workspace information: %s", resp.CreatedWorkspaceID)
381-
wi, err := server.GetWorkspace(ctx, resp.CreatedWorkspaceID)
382-
if err != nil {
383-
return nil, nil, xerrors.Errorf("cannot get workspace: %w", err)
381+
382+
var wi *protocol.WorkspaceInfo
383+
for i := 0; i < 3; i++ {
384+
wi, err = server.GetWorkspace(ctx, resp.CreatedWorkspaceID)
385+
if err != nil || wi.LatestInstance == nil {
386+
time.Sleep(2 * time.Second)
387+
continue
388+
}
389+
if wi.LatestInstance.Status.Phase != "preparing" {
390+
break
391+
}
392+
time.Sleep(5 * time.Second)
384393
}
385-
if wi.LatestInstance == nil {
394+
if wi == nil || wi.LatestInstance == nil {
386395
return nil, nil, xerrors.Errorf("CreateWorkspace did not start the workspace")
387396
}
388397
t.Logf("got the workspace information: %s", wi.Workspace.ID)
@@ -393,6 +402,19 @@ func LaunchWorkspaceFromContextURL(t *testing.T, ctx context.Context, contextURL
393402
wi.LatestInstance.IdeURL = resp.WorkspaceURL
394403
}
395404

405+
if wi.LatestInstance.Status.Conditions.NeededImageBuild {
406+
for ctx.Err() == nil {
407+
wi, err = server.GetWorkspace(ctx, resp.CreatedWorkspaceID)
408+
if err != nil {
409+
return nil, nil, xerrors.Errorf("cannot get workspace: %w", err)
410+
}
411+
if wi.LatestInstance.Status.Phase == "running" {
412+
break
413+
}
414+
time.Sleep(10 * time.Second)
415+
}
416+
}
417+
396418
stopWs = stopWsF(t, wi.LatestInstance.ID, resp.CreatedWorkspaceID, api, false)
397419
defer func() {
398420
if err != nil {

test/tests/smoke-test/main_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License.AGPL.txt in the project root for license information.
4+
5+
package smoketest
6+
7+
import (
8+
"context"
9+
"os"
10+
"testing"
11+
12+
"github.com/gitpod-io/gitpod/test/pkg/integration"
13+
"sigs.k8s.io/e2e-framework/pkg/env"
14+
)
15+
16+
var (
17+
testEnv env.Environment
18+
username string
19+
namespace string
20+
kubeconfig string
21+
gitlab bool
22+
)
23+
24+
func TestMain(m *testing.M) {
25+
username, namespace, testEnv, _, kubeconfig, gitlab = integration.Setup(context.Background())
26+
os.Exit(testEnv.Run(m))
27+
}

test/tests/smoke-test/smoke_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License.AGPL.txt in the project root for license information.
4+
5+
package smoketest
6+
7+
import (
8+
"context"
9+
"os"
10+
"testing"
11+
"time"
12+
13+
"sigs.k8s.io/e2e-framework/pkg/envconf"
14+
"sigs.k8s.io/e2e-framework/pkg/features"
15+
16+
"github.com/gitpod-io/gitpod/test/pkg/integration"
17+
)
18+
19+
func TestStartWorkspaceWithImageBuild(t *testing.T) {
20+
userToken, _ := os.LookupEnv("USER_TOKEN")
21+
integration.SkipWithoutUsername(t, username)
22+
integration.SkipWithoutUserToken(t, userToken)
23+
24+
f := features.New("Start regular workspace").
25+
Assess("it can start a regular workspace with image build", func(_ context.Context, t *testing.T, cfg *envconf.Config) context.Context {
26+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
27+
defer cancel()
28+
29+
api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
30+
t.Cleanup(func() {
31+
api.Done(t)
32+
})
33+
34+
_, err := api.CreateUser(username, userToken)
35+
if err != nil {
36+
t.Fatal(err)
37+
}
38+
39+
_, stopWs, err := integration.LaunchWorkspaceFromContextURL(t, ctx, "imagebuild/https://github.com/gitpod-integration-test/example", username, api)
40+
if err != nil {
41+
t.Fatal(err)
42+
}
43+
defer func() {
44+
sctx, scancel := context.WithTimeout(context.Background(), 5*time.Minute)
45+
defer scancel()
46+
47+
sapi := integration.NewComponentAPI(sctx, cfg.Namespace(), kubeconfig, cfg.Client())
48+
defer sapi.Done(t)
49+
50+
_, _ = stopWs(true, sapi)
51+
}()
52+
return ctx
53+
}).
54+
Feature()
55+
testEnv.Test(t, f)
56+
}

0 commit comments

Comments
 (0)