|
| 1 | +// Copyright (c) 2022 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 workspace |
| 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 | +type GitHooksTest struct { |
| 20 | + Name string |
| 21 | + ContextURL string |
| 22 | + WorkspaceRoot string |
| 23 | +} |
| 24 | + |
| 25 | +func GithuHooksTest(t *testing.T) { |
| 26 | + userToken, _ := os.LookupEnv("USER_TOKEN") |
| 27 | + integration.SkipWithoutUsername(t, username) |
| 28 | + integration.SkipWithoutUserToken(t, userToken) |
| 29 | + |
| 30 | + parallelLimiter := make(chan struct{}, 2) |
| 31 | + |
| 32 | + tests := []GitHooksTest{ |
| 33 | + { |
| 34 | + Name: "husky", |
| 35 | + ContextURL: "https://github.com/gitpod-io/gitpod-test-repo/tree/husky", |
| 36 | + WorkspaceRoot: "/workspace/template-golang-cli", |
| 37 | + }, |
| 38 | + } |
| 39 | + |
| 40 | + f := features.New("git hooks"). |
| 41 | + WithLabel("component", "server"). |
| 42 | + Assess("should run git hooks tests", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { |
| 43 | + ffs := []struct { |
| 44 | + Name string |
| 45 | + FF string |
| 46 | + }{ |
| 47 | + {Name: "classic"}, |
| 48 | + {Name: "pvc", FF: "persistent_volume_claim"}, |
| 49 | + } |
| 50 | + |
| 51 | + for _, ff := range ffs { |
| 52 | + func() { |
| 53 | + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) |
| 54 | + defer cancel() |
| 55 | + |
| 56 | + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) |
| 57 | + defer api.Done(t) |
| 58 | + |
| 59 | + username := username + ff.Name |
| 60 | + userId, err := api.CreateUser(username, userToken) |
| 61 | + if err != nil { |
| 62 | + t.Fatal(err) |
| 63 | + } |
| 64 | + |
| 65 | + if err := api.UpdateUserFeatureFlag(userId, ff.FF); err != nil { |
| 66 | + t.Fatal(err) |
| 67 | + } |
| 68 | + }() |
| 69 | + } |
| 70 | + |
| 71 | + for _, ff := range ffs { |
| 72 | + for _, test := range tests { |
| 73 | + t.Run(test.ContextURL+"_"+ff.Name, func(t *testing.T) { |
| 74 | + t.Parallel() |
| 75 | + |
| 76 | + t.Logf("Waiting %s", test.ContextURL+"_"+ff.Name) |
| 77 | + |
| 78 | + parallelLimiter <- struct{}{} |
| 79 | + defer func() { |
| 80 | + <-parallelLimiter |
| 81 | + }() |
| 82 | + |
| 83 | + t.Logf("Running %s", test.ContextURL+"_"+ff.Name) |
| 84 | + |
| 85 | + username := username + ff.Name |
| 86 | + |
| 87 | + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) |
| 88 | + defer cancel() |
| 89 | + |
| 90 | + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) |
| 91 | + defer api.Done(t) |
| 92 | + |
| 93 | + _, stopWs, err := integration.LaunchWorkspaceFromContextURL(t, ctx, test.ContextURL, username, api) |
| 94 | + if err != nil { |
| 95 | + t.Fatal(err) |
| 96 | + } |
| 97 | + |
| 98 | + defer func() { |
| 99 | + sctx, scancel := context.WithTimeout(context.Background(), 10*time.Minute) |
| 100 | + defer scancel() |
| 101 | + |
| 102 | + sapi := integration.NewComponentAPI(sctx, cfg.Namespace(), kubeconfig, cfg.Client()) |
| 103 | + defer sapi.Done(t) |
| 104 | + |
| 105 | + if _, err := stopWs(true, sapi); err != nil { |
| 106 | + t.Fatal(err) |
| 107 | + } |
| 108 | + }() |
| 109 | + }) |
| 110 | + } |
| 111 | + } |
| 112 | + return ctx |
| 113 | + }). |
| 114 | + Feature() |
| 115 | + |
| 116 | + testEnv.Test(t, f) |
| 117 | +} |
0 commit comments