-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathgit_hooks_test.go
141 lines (114 loc) · 3.58 KB
/
git_hooks_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.
package workspace
import (
"context"
"os"
"testing"
"time"
"sigs.k8s.io/e2e-framework/pkg/envconf"
"sigs.k8s.io/e2e-framework/pkg/features"
agent "github.com/gitpod-io/gitpod/test/pkg/agent/workspace/api"
"github.com/gitpod-io/gitpod/test/pkg/integration"
)
const (
FILE_CREATED_HOOKS = "output.txt"
)
type GitHooksTestCase struct {
Name string
ContextURL string
WorkspaceRoot string
}
func TestGitHooks(t *testing.T) {
userToken, _ := os.LookupEnv("USER_TOKEN")
integration.SkipWithoutUsername(t, username)
integration.SkipWithoutUserToken(t, userToken)
parallelLimiter := make(chan struct{}, 2)
tests := []GitHooksTestCase{
{
Name: "husky",
ContextURL: "https://github.com/gitpod-io/gitpod-test-repo/tree/husky",
WorkspaceRoot: "/workspace/gitpod-test-repo",
},
}
f := features.New("git hooks").
WithLabel("component", "server").
Assess("should run git hooks tests", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
ffs := []struct {
Name string
FF string
}{
{Name: "classic"},
{Name: "pvc", FF: "persistent_volume_claim"},
}
for _, ff := range ffs {
func() {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
defer api.Done(t)
username := username + ff.Name
userId, err := api.CreateUser(username, userToken)
if err != nil {
t.Fatal(err)
}
if err := api.UpdateUserFeatureFlag(userId, ff.FF); err != nil {
t.Fatal(err)
}
}()
}
for _, ff := range ffs {
for _, test := range tests {
t.Run(test.ContextURL+"_"+ff.Name, func(t *testing.T) {
t.Parallel()
t.Logf("Waiting %s", test.ContextURL+"_"+ff.Name)
parallelLimiter <- struct{}{}
defer func() {
<-parallelLimiter
}()
t.Logf("Running %s", test.ContextURL+"_"+ff.Name)
username := username + ff.Name
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
defer api.Done(t)
wsInfo, stopWs, err := integration.LaunchWorkspaceFromContextURL(t, ctx, test.ContextURL, username, api)
if err != nil {
t.Fatal(err)
}
defer func() {
sctx, scancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer scancel()
sapi := integration.NewComponentAPI(sctx, cfg.Namespace(), kubeconfig, cfg.Client())
defer sapi.Done(t)
if _, err := stopWs(true, sapi); err != nil {
t.Fatal(err)
}
}()
rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(), integration.WithInstanceID(wsInfo.LatestInstance.ID))
if err != nil {
t.Fatal(err)
}
defer rsa.Close()
integration.DeferCloser(t, closer)
var ls agent.ListDirResponse
err = rsa.Call("WorkspaceAgent.ListDir", &agent.ListDirRequest{
Dir: test.WorkspaceRoot,
}, &ls)
if err != nil {
t.Fatal(err)
}
for _, f := range ls.Files {
if f == FILE_CREATED_HOOKS {
t.Fatal("Checkout hooks are executed")
}
}
})
}
}
return ctx
}).
Feature()
testEnv.Test(t, f)
}