Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/test/tests/components/ws-manager/additional_repositories_test.go
2500 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 wsmanager
6
7
import (
8
"context"
9
"fmt"
10
"strings"
11
"testing"
12
"time"
13
14
"sigs.k8s.io/e2e-framework/pkg/envconf"
15
"sigs.k8s.io/e2e-framework/pkg/features"
16
17
csapi "github.com/gitpod-io/gitpod/content-service/api"
18
agent "github.com/gitpod-io/gitpod/test/pkg/agent/workspace/api"
19
"github.com/gitpod-io/gitpod/test/pkg/integration"
20
wsmanapi "github.com/gitpod-io/gitpod/ws-manager/api"
21
)
22
23
func TestAdditionalRepositories(t *testing.T) {
24
f := features.New("additional-repositories").
25
WithLabel("component", "ws-manager").
26
Assess("can open a workspace using the additionalRepositories property", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
27
tests := []struct {
28
Name string
29
ContextURL string
30
CloneTaget string
31
}{
32
{
33
Name: "workspace with additionalRepositories using a branch",
34
ContextURL: "https://github.com/gitpod-io/gitpod-test-repo",
35
CloneTaget: "aledbf/test-additional-repositories",
36
},
37
{
38
Name: "workspace with additionalRepositories also using a branch in one of the additionalRepositories",
39
ContextURL: "https://github.com/gitpod-io/gitpod-test-repo",
40
CloneTaget: "aledbf/test-additional-repositories-with-branches",
41
},
42
}
43
44
for _, test := range tests {
45
test := test
46
t.Run(test.Name, func(t *testing.T) {
47
t.Parallel()
48
49
ctx, cancel := context.WithTimeout(testCtx, time.Duration(5*len(tests))*time.Minute)
50
defer cancel()
51
52
api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
53
t.Cleanup(func() {
54
api.Done(t)
55
})
56
57
testRepoName := "gitpod-test-repo"
58
ws, stopWs, err := integration.LaunchWorkspaceDirectly(t, ctx, api, integration.WithRequestModifier(func(req *wsmanapi.StartWorkspaceRequest) error {
59
req.Spec.WorkspaceLocation = testRepoName
60
req.Spec.Initializer = &csapi.WorkspaceInitializer{
61
Spec: &csapi.WorkspaceInitializer_Git{
62
Git: &csapi.GitInitializer{
63
RemoteUri: test.ContextURL,
64
CloneTaget: test.CloneTaget,
65
Config: &csapi.GitConfig{},
66
TargetMode: csapi.CloneTargetMode_REMOTE_BRANCH,
67
CheckoutLocation: testRepoName,
68
},
69
},
70
}
71
72
return nil
73
}))
74
if err != nil {
75
t.Fatal(err)
76
}
77
78
t.Cleanup(func() {
79
// stop workspace in defer function to prevent we forget to stop the workspace
80
if err := stopWorkspace(t, cfg, stopWs); err != nil {
81
t.Errorf("cannot stop workspace: %q", err)
82
}
83
})
84
85
rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(),
86
integration.WithInstanceID(ws.Req.Id),
87
)
88
if err != nil {
89
t.Fatal(err)
90
}
91
92
integration.DeferCloser(t, closer)
93
defer rsa.Close()
94
95
var gitOut agent.ExecResponse
96
err = rsa.Call("WorkspaceAgent.Exec", &agent.ExecRequest{
97
Dir: fmt.Sprintf("/workspace/%v", testRepoName),
98
Command: "bash",
99
Args: []string{
100
"-c",
101
"git symbolic-ref --short HEAD",
102
},
103
}, &gitOut)
104
if err != nil {
105
t.Fatal(err)
106
}
107
108
out := strings.TrimSpace(gitOut.Stdout)
109
if test.CloneTaget != out {
110
t.Errorf("returned branch %v is not %v", out, test.CloneTaget)
111
}
112
})
113
}
114
115
return testCtx
116
}).
117
Feature()
118
119
testEnv.Test(t, f)
120
}
121
122