From 0a499f0950a24cd6f0028ed78da17f9e7670a4d2 Mon Sep 17 00:00:00 2001 From: JenTing Hsiao Date: Sun, 1 May 2022 15:51:21 +0800 Subject: [PATCH 1/3] Create user in DB if not present Signed-off-by: JenTing Hsiao --- test/tests/workspace/contexts_test.go | 9 +++++++++ test/tests/workspace/example_test.go | 9 +++++++++ test/tests/workspace/git_test.go | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/test/tests/workspace/contexts_test.go b/test/tests/workspace/contexts_test.go index 48d8e0c84e2764..e8482cd4445f90 100644 --- a/test/tests/workspace/contexts_test.go +++ b/test/tests/workspace/contexts_test.go @@ -7,6 +7,7 @@ package workspace import ( "context" "fmt" + "os" "testing" "time" @@ -94,7 +95,10 @@ func TestGitLabContexts(t *testing.T) { } func runContextTests(t *testing.T, tests []ContextTest) { + userToken, _ := os.LookupEnv("USER_TOKEN") integration.SkipWithoutUsername(t, username) + integration.SkipWithoutUserToken(t, userToken) + f := features.New("context"). WithLabel("component", "server"). Assess("should run context tests", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { @@ -114,6 +118,11 @@ func runContextTests(t *testing.T, tests []ContextTest) { api.Done(t) }) + _, err := api.CreateUser(username, userToken) + if err != nil { + t.Fatal(err) + } + nfo, stopWS, err := integration.LaunchWorkspaceFromContextURL(ctx, test.ContextURL, username, api) if err != nil { t.Fatal(err) diff --git a/test/tests/workspace/example_test.go b/test/tests/workspace/example_test.go index f8c6bed1ea3694..e34dcecb7bfd8b 100644 --- a/test/tests/workspace/example_test.go +++ b/test/tests/workspace/example_test.go @@ -6,6 +6,7 @@ package workspace import ( "context" + "os" "testing" "time" @@ -17,7 +18,10 @@ import ( ) func TestWorkspaceInstrumentation(t *testing.T) { + userToken, _ := os.LookupEnv("USER_TOKEN") integration.SkipWithoutUsername(t, username) + integration.SkipWithoutUserToken(t, userToken) + f := features.New("instrumentation"). WithLabel("component", "server"). Assess("it can instrument a workspace", func(_ context.Context, t *testing.T, cfg *envconf.Config) context.Context { @@ -29,6 +33,11 @@ func TestWorkspaceInstrumentation(t *testing.T) { api.Done(t) }) + _, err := api.CreateUser(username, userToken) + if err != nil { + t.Fatal(err) + } + nfo, stopWs, err := integration.LaunchWorkspaceFromContextURL(ctx, "github.com/gitpod-io/gitpod", username, api) if err != nil { t.Fatal(err) diff --git a/test/tests/workspace/git_test.go b/test/tests/workspace/git_test.go index c18491fa2a59b4..0cf79441eccced 100644 --- a/test/tests/workspace/git_test.go +++ b/test/tests/workspace/git_test.go @@ -7,6 +7,7 @@ package workspace import ( "context" "net/rpc" + "os" "testing" "time" @@ -30,7 +31,10 @@ type GitTest struct { type GitFunc func(rsa *rpc.Client, git common.GitClient, workspaceRoot string) error func TestGitActions(t *testing.T) { + userToken, _ := os.LookupEnv("USER_TOKEN") integration.SkipWithoutUsername(t, username) + integration.SkipWithoutUserToken(t, userToken) + tests := []GitTest{ { Name: "create, add and commit", @@ -108,6 +112,11 @@ func TestGitActions(t *testing.T) { api.Done(t) }) + _, err := api.CreateUser(username, userToken) + if err != nil { + t.Fatal(err) + } + for _, test := range tests { t.Run(test.ContextURL, func(t *testing.T) { if test.Skip { From 0ca9b3767cb0de51ea6eb33a3fb29735f97f2133 Mon Sep 17 00:00:00 2001 From: JenTing Hsiao Date: Thu, 28 Apr 2022 13:16:22 +0000 Subject: [PATCH 2/3] Remove duplicated file git-client.go Signed-off-by: JenTing Hsiao --- test/tests/workspace/common/git-client.go | 103 ---------------------- test/tests/workspace/contexts_test.go | 2 +- test/tests/workspace/git_test.go | 2 +- 3 files changed, 2 insertions(+), 105 deletions(-) delete mode 100644 test/tests/workspace/common/git-client.go diff --git a/test/tests/workspace/common/git-client.go b/test/tests/workspace/common/git-client.go deleted file mode 100644 index 993e27d4b4b38d..00000000000000 --- a/test/tests/workspace/common/git-client.go +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (c) 2020 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 common - -import ( - "net/rpc" - "strings" - - "golang.org/x/xerrors" - - agent "github.com/gitpod-io/gitpod/test/pkg/agent/workspace/api" -) - -type GitClient struct { - *rpc.Client -} - -func Git(rsa *rpc.Client) GitClient { - return GitClient{rsa} -} - -func (g GitClient) GetBranch(workspaceRoot string) (string, error) { - var resp agent.ExecResponse - err := g.Call("WorkspaceAgent.Exec", &agent.ExecRequest{ - Dir: workspaceRoot, - Command: "git", - Args: []string{"rev-parse", "--abbrev-ref", "HEAD"}, - }, &resp) - if err != nil { - return "", xerrors.Errorf("getBranch error: %w", err) - } - if resp.ExitCode != 0 { - return "", xerrors.Errorf("getBranch rc!=0: %d", resp.ExitCode) - } - return strings.Trim(resp.Stdout, " \t\n"), nil -} - -func (g GitClient) Add(dir string, files ...string) error { - args := []string{"add"} - if files == nil { - args = append(args, ".") - } else { - args = append(args, files...) - } - var resp agent.ExecResponse - err := g.Call("WorkspaceAgent.Exec", &agent.ExecRequest{ - Dir: dir, - Command: "git", - Args: args, - }, &resp) - if err != nil { - return err - } - if resp.ExitCode != 0 { - return xerrors.Errorf("commit returned rc: %d", resp.ExitCode) - } - return nil -} - -func (g GitClient) Commit(dir string, message string, all bool) error { - args := []string{"commit", "-m", message} - if all { - args = append(args, "--all") - } - var resp agent.ExecResponse - err := g.Call("WorkspaceAgent.Exec", &agent.ExecRequest{ - Dir: dir, - Command: "git", - Args: args, - }, &resp) - if err != nil { - return err - } - if resp.ExitCode != 0 { - return xerrors.Errorf("commit returned rc: %d", resp.ExitCode) - } - return nil -} - -func (g GitClient) Push(dir string, force bool, moreArgs ...string) error { - args := []string{"push"} - if moreArgs != nil { - args = append(args, moreArgs...) - } - if force { - args = append(args, "--force") - } - var resp agent.ExecResponse - err := g.Call("WorkspaceAgent.Exec", &agent.ExecRequest{ - Dir: dir, - Command: "git", - Args: args, - }, &resp) - if err != nil { - return err - } - if resp.ExitCode != 0 { - return xerrors.Errorf("commit returned rc: %d", resp.ExitCode) - } - return nil -} diff --git a/test/tests/workspace/contexts_test.go b/test/tests/workspace/contexts_test.go index e8482cd4445f90..5ac5c3cd346ffc 100644 --- a/test/tests/workspace/contexts_test.go +++ b/test/tests/workspace/contexts_test.go @@ -15,7 +15,7 @@ import ( "sigs.k8s.io/e2e-framework/pkg/features" "github.com/gitpod-io/gitpod/test/pkg/integration" - "github.com/gitpod-io/gitpod/test/tests/workspace/common" + "github.com/gitpod-io/gitpod/test/pkg/integration/common" ) type ContextTest struct { diff --git a/test/tests/workspace/git_test.go b/test/tests/workspace/git_test.go index 0cf79441eccced..1eec27be14f965 100644 --- a/test/tests/workspace/git_test.go +++ b/test/tests/workspace/git_test.go @@ -16,7 +16,7 @@ import ( agent "github.com/gitpod-io/gitpod/test/pkg/agent/workspace/api" "github.com/gitpod-io/gitpod/test/pkg/integration" - "github.com/gitpod-io/gitpod/test/tests/workspace/common" + "github.com/gitpod-io/gitpod/test/pkg/integration/common" ) // From 58cdcd79ed8c1f561a882cfb82297113e4193f43 Mon Sep 17 00:00:00 2001 From: JenTing Hsiao Date: Thu, 28 Apr 2022 13:16:48 +0000 Subject: [PATCH 3/3] Git config user.name and user.email locally Git config --user.name and git config --user.email, otherwise, git commit would fail. Signed-off-by: JenTing Hsiao --- test/pkg/integration/common/git-client.go | 34 +++++++++++++++++++++++ test/tests/workspace/git_test.go | 16 +++++++++++ 2 files changed, 50 insertions(+) diff --git a/test/pkg/integration/common/git-client.go b/test/pkg/integration/common/git-client.go index 993e27d4b4b38d..d6bf452b782975 100644 --- a/test/pkg/integration/common/git-client.go +++ b/test/pkg/integration/common/git-client.go @@ -59,6 +59,40 @@ func (g GitClient) Add(dir string, files ...string) error { return nil } +func (g GitClient) ConfigUserName(dir string) error { + args := []string{"config", "--local", "user.name", "integration-test"} + var resp agent.ExecResponse + err := g.Call("WorkspaceAgent.Exec", &agent.ExecRequest{ + Dir: dir, + Command: "git", + Args: args, + }, &resp) + if err != nil { + return err + } + if resp.ExitCode != 0 { + return xerrors.Errorf("config user name returned rc: %d", resp.ExitCode) + } + return nil +} + +func (g GitClient) ConfigUserEmail(dir string, files ...string) error { + args := []string{"config", "--local", "user.email", "integration-test@gitpod.io"} + var resp agent.ExecResponse + err := g.Call("WorkspaceAgent.Exec", &agent.ExecRequest{ + Dir: dir, + Command: "git", + Args: args, + }, &resp) + if err != nil { + return err + } + if resp.ExitCode != 0 { + return xerrors.Errorf("config user email returned rc: %d", resp.ExitCode) + } + return nil +} + func (g GitClient) Commit(dir string, message string, all bool) error { args := []string{"commit", "-m", message} if all { diff --git a/test/tests/workspace/git_test.go b/test/tests/workspace/git_test.go index 1eec27be14f965..694f93a294bc3f 100644 --- a/test/tests/workspace/git_test.go +++ b/test/tests/workspace/git_test.go @@ -54,6 +54,14 @@ func TestGitActions(t *testing.T) { if err != nil { return err } + err = git.ConfigUserName(workspaceRoot) + if err != nil { + return err + } + err = git.ConfigUserEmail(workspaceRoot) + if err != nil { + return err + } err = git.Add(workspaceRoot) if err != nil { return err @@ -84,6 +92,14 @@ func TestGitActions(t *testing.T) { if err != nil { return err } + err = git.ConfigUserName(workspaceRoot) + if err != nil { + return err + } + err = git.ConfigUserEmail(workspaceRoot) + if err != nil { + return err + } err = git.Add(workspaceRoot) if err != nil { return err