Path: blob/main/test/tests/components/ws-manager/additional_repositories_test.go
2500 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package wsmanager56import (7"context"8"fmt"9"strings"10"testing"11"time"1213"sigs.k8s.io/e2e-framework/pkg/envconf"14"sigs.k8s.io/e2e-framework/pkg/features"1516csapi "github.com/gitpod-io/gitpod/content-service/api"17agent "github.com/gitpod-io/gitpod/test/pkg/agent/workspace/api"18"github.com/gitpod-io/gitpod/test/pkg/integration"19wsmanapi "github.com/gitpod-io/gitpod/ws-manager/api"20)2122func TestAdditionalRepositories(t *testing.T) {23f := features.New("additional-repositories").24WithLabel("component", "ws-manager").25Assess("can open a workspace using the additionalRepositories property", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {26tests := []struct {27Name string28ContextURL string29CloneTaget string30}{31{32Name: "workspace with additionalRepositories using a branch",33ContextURL: "https://github.com/gitpod-io/gitpod-test-repo",34CloneTaget: "aledbf/test-additional-repositories",35},36{37Name: "workspace with additionalRepositories also using a branch in one of the additionalRepositories",38ContextURL: "https://github.com/gitpod-io/gitpod-test-repo",39CloneTaget: "aledbf/test-additional-repositories-with-branches",40},41}4243for _, test := range tests {44test := test45t.Run(test.Name, func(t *testing.T) {46t.Parallel()4748ctx, cancel := context.WithTimeout(testCtx, time.Duration(5*len(tests))*time.Minute)49defer cancel()5051api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())52t.Cleanup(func() {53api.Done(t)54})5556testRepoName := "gitpod-test-repo"57ws, stopWs, err := integration.LaunchWorkspaceDirectly(t, ctx, api, integration.WithRequestModifier(func(req *wsmanapi.StartWorkspaceRequest) error {58req.Spec.WorkspaceLocation = testRepoName59req.Spec.Initializer = &csapi.WorkspaceInitializer{60Spec: &csapi.WorkspaceInitializer_Git{61Git: &csapi.GitInitializer{62RemoteUri: test.ContextURL,63CloneTaget: test.CloneTaget,64Config: &csapi.GitConfig{},65TargetMode: csapi.CloneTargetMode_REMOTE_BRANCH,66CheckoutLocation: testRepoName,67},68},69}7071return nil72}))73if err != nil {74t.Fatal(err)75}7677t.Cleanup(func() {78// stop workspace in defer function to prevent we forget to stop the workspace79if err := stopWorkspace(t, cfg, stopWs); err != nil {80t.Errorf("cannot stop workspace: %q", err)81}82})8384rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(),85integration.WithInstanceID(ws.Req.Id),86)87if err != nil {88t.Fatal(err)89}9091integration.DeferCloser(t, closer)92defer rsa.Close()9394var gitOut agent.ExecResponse95err = rsa.Call("WorkspaceAgent.Exec", &agent.ExecRequest{96Dir: fmt.Sprintf("/workspace/%v", testRepoName),97Command: "bash",98Args: []string{99"-c",100"git symbolic-ref --short HEAD",101},102}, &gitOut)103if err != nil {104t.Fatal(err)105}106107out := strings.TrimSpace(gitOut.Stdout)108if test.CloneTaget != out {109t.Errorf("returned branch %v is not %v", out, test.CloneTaget)110}111})112}113114return testCtx115}).116Feature()117118testEnv.Test(t, f)119}120121122