Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the workspace integration tests that need username in DB first #9628

Merged
merged 3 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions test/pkg/integration/common/git-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]"}
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 {
Expand Down
103 changes: 0 additions & 103 deletions test/tests/workspace/common/git-client.go

This file was deleted.

11 changes: 10 additions & 1 deletion test/tests/workspace/contexts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ package workspace
import (
"context"
"fmt"
"os"
"testing"
"time"

"sigs.k8s.io/e2e-framework/pkg/envconf"
"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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions test/tests/workspace/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package workspace

import (
"context"
"os"
"testing"
"time"

Expand All @@ -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 {
Expand All @@ -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)
Expand Down
27 changes: 26 additions & 1 deletion test/tests/workspace/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package workspace
import (
"context"
"net/rpc"
"os"
"testing"
"time"

Expand All @@ -15,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"
)

//
Expand All @@ -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",
Expand All @@ -50,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
Expand Down Expand Up @@ -80,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
Expand Down Expand Up @@ -108,6 +128,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 {
Expand Down