Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/test/tests/workspace/git_hooks_test.go
2498 views
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
agent "github.com/gitpod-io/gitpod/test/pkg/agent/workspace/api"
17
"github.com/gitpod-io/gitpod/test/pkg/integration"
18
)
19
20
const (
21
FILE_CREATED_HOOKS = "output.txt"
22
)
23
24
type GitHooksTestCase struct {
25
Name string
26
ContextURL string
27
WorkspaceRoot string
28
}
29
30
func TestGitHooks(t *testing.T) {
31
userToken, _ := os.LookupEnv("USER_TOKEN")
32
integration.SkipWithoutUsername(t, username)
33
integration.SkipWithoutUserToken(t, userToken)
34
35
tests := []GitHooksTestCase{
36
{
37
Name: "husky",
38
ContextURL: "https://github.com/gitpod-io/gitpod-test-repo/tree/husky",
39
WorkspaceRoot: "/workspace/gitpod-test-repo",
40
},
41
}
42
43
f := features.New("git hooks").
44
WithLabel("component", "server").
45
Assess("should run git hooks tests", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
46
ffs := []struct {
47
Name string
48
FF string
49
}{
50
{Name: "classic"},
51
}
52
53
for _, ff := range ffs {
54
func() {
55
ctx, cancel := context.WithTimeout(testCtx, 10*time.Minute)
56
defer cancel()
57
58
api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
59
defer api.Done(t)
60
61
username := username + ff.Name
62
userId, err := api.CreateUser(username, userToken)
63
if err != nil {
64
t.Fatal(err)
65
}
66
67
if err := api.UpdateUserFeatureFlag(userId, ff.FF); err != nil {
68
t.Fatal(err)
69
}
70
}()
71
}
72
73
for _, ff := range ffs {
74
for _, test := range tests {
75
test := test
76
t.Run(test.ContextURL+"_"+ff.Name, func(t *testing.T) {
77
t.Parallel()
78
79
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(5*len(tests)*len(ffs))*time.Minute)
80
defer cancel()
81
82
username := username + ff.Name
83
84
api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
85
defer api.Done(t)
86
87
wsInfo, stopWs, err := integration.LaunchWorkspaceFromContextURL(t, ctx, test.ContextURL, username, api)
88
if err != nil {
89
t.Fatal(err)
90
}
91
92
t.Cleanup(func() {
93
sctx, scancel := context.WithTimeout(context.Background(), 10*time.Minute)
94
defer scancel()
95
96
sapi := integration.NewComponentAPI(sctx, cfg.Namespace(), kubeconfig, cfg.Client())
97
defer sapi.Done(t)
98
99
if _, err := stopWs(true, sapi); err != nil {
100
t.Fatal(err)
101
}
102
})
103
rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(), integration.WithInstanceID(wsInfo.LatestInstance.ID))
104
if err != nil {
105
t.Fatal(err)
106
}
107
defer rsa.Close()
108
integration.DeferCloser(t, closer)
109
110
var ls agent.ListDirResponse
111
err = rsa.Call("WorkspaceAgent.ListDir", &agent.ListDirRequest{
112
Dir: test.WorkspaceRoot,
113
}, &ls)
114
if err != nil {
115
t.Fatal(err)
116
}
117
for _, f := range ls.Files {
118
if f == FILE_CREATED_HOOKS {
119
t.Fatal("Checkout hooks are executed")
120
}
121
}
122
})
123
}
124
}
125
return testCtx
126
}).
127
Feature()
128
129
testEnv.Test(t, f)
130
}
131
132