Skip to content

Commit 108ad9a

Browse files
committed
Add integration tests for additionalRepositories
1 parent c6a3647 commit 108ad9a

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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 wsmanager
6+
7+
import (
8+
"context"
9+
"testing"
10+
"time"
11+
12+
"sigs.k8s.io/e2e-framework/pkg/envconf"
13+
"sigs.k8s.io/e2e-framework/pkg/features"
14+
15+
csapi "github.com/gitpod-io/gitpod/content-service/api"
16+
"github.com/gitpod-io/gitpod/test/pkg/integration"
17+
wsmanapi "github.com/gitpod-io/gitpod/ws-manager/api"
18+
)
19+
20+
func TestAdditionalRepositories(t *testing.T) {
21+
f := features.New("additional-repositories").
22+
WithLabel("component", "ws-manager").
23+
Assess("can open a workspace using the additionalRepositories property", func(_ context.Context, t *testing.T, cfg *envconf.Config) context.Context {
24+
tests := []struct {
25+
Name string
26+
ContextURL string
27+
CloneTaget string
28+
}{
29+
{
30+
Name: "workspace with additionalRepositories using a branch",
31+
ContextURL: "https://github.com/gitpod-io/gitpod-test-repo",
32+
CloneTaget: "aledbf/test-additional-repositories",
33+
},
34+
{
35+
Name: "workspace with additionalRepositories also using a branch in one of the additionalRepositories",
36+
ContextURL: "https://github.com/gitpod-io/gitpod-test-repo",
37+
CloneTaget: "aledbf/test-additional-repositories-with-branches",
38+
},
39+
}
40+
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(5*len(tests))*time.Minute)
41+
defer cancel()
42+
43+
for _, test := range tests {
44+
t.Run(test.Name, func(t *testing.T) {
45+
api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
46+
t.Cleanup(func() {
47+
api.Done(t)
48+
})
49+
50+
ws, stopWs, err := integration.LaunchWorkspaceDirectly(t, ctx, api, integration.WithRequestModifier(func(req *wsmanapi.StartWorkspaceRequest) error {
51+
testRepoName := "gitpod-test-repo"
52+
req.Spec.WorkspaceLocation = testRepoName
53+
req.Spec.Initializer = &csapi.WorkspaceInitializer{
54+
Spec: &csapi.WorkspaceInitializer_Git{
55+
Git: &csapi.GitInitializer{
56+
RemoteUri: test.ContextURL,
57+
CloneTaget: test.CloneTaget,
58+
Config: &csapi.GitConfig{},
59+
TargetMode: csapi.CloneTargetMode_REMOTE_BRANCH,
60+
},
61+
},
62+
}
63+
64+
return nil
65+
}))
66+
if err != nil {
67+
t.Fatal(err)
68+
}
69+
70+
defer func() {
71+
// stop workspace in defer function to prevent we forget to stop the workspace
72+
if err := stopWorkspace(t, cfg, stopWs); err != nil {
73+
t.Errorf("cannot stop workspace: %q", err)
74+
}
75+
}()
76+
77+
rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(),
78+
integration.WithInstanceID(ws.Req.Id),
79+
)
80+
if err != nil {
81+
t.Fatal(err)
82+
}
83+
84+
integration.DeferCloser(t, closer)
85+
defer rsa.Close()
86+
})
87+
}
88+
89+
return ctx
90+
}).
91+
Feature()
92+
93+
testEnv.Test(t, f)
94+
}

0 commit comments

Comments
 (0)