Skip to content

PVC integration tests: TestGitHubContexts and TestGitActions and TestGitLFSSupport #12650

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

Merged
merged 4 commits into from
Sep 5, 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
19 changes: 18 additions & 1 deletion test/pkg/integration/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,22 @@ func (c *ComponentAPI) GetUserId(user string) (userId string, err error) {
return id, nil
}

func (c *ComponentAPI) UpdateUserFeatureFlag(userId, featureFlag string) error {
db, err := c.DB()
if err != nil {
return err
}

if _, err = db.Exec("SELECT id FROM d_b_user WHERE id = ?", userId); err != nil {
return err
}

if _, err = db.Exec("UPDATE d_b_user SET featureFlags=? WHERE id = ?", fmt.Sprintf("{\"permanentWSFeatureFlags\":[%q]}", featureFlag), userId); err != nil {
return err
}
return nil
}

func (c *ComponentAPI) CreateUser(username string, token string) (string, error) {
dbConfig, err := FindDBConfigFromPodEnv("server", c.namespace, c.client)
if err != nil {
Expand All @@ -425,12 +441,13 @@ func (c *ComponentAPI) CreateUser(username string, token string) (string, error)
}

userId = userUuid.String()
_, err = db.Exec(`INSERT IGNORE INTO d_b_user (id, creationDate, avatarUrl, name, fullName) VALUES (?, ?, ?, ?, ?)`,
_, err = db.Exec(`INSERT IGNORE INTO d_b_user (id, creationDate, avatarUrl, name, fullName, featureFlags) VALUES (?, ?, ?, ?, ?, ?)`,
userId,
time.Now().Format(time.RFC3339),
"",
username,
username,
"{\"permanentWSFeatureFlags\":[]}",
)
if err != nil {
return "", err
Expand Down
117 changes: 66 additions & 51 deletions test/tests/workspace/contexts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,59 +102,74 @@ func runContextTests(t *testing.T, tests []ContextTest) {
f := features.New("context").
WithLabel("component", "server").
Assess("should run context tests", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
for _, test := range tests {
t.Run(test.ContextURL, func(t *testing.T) {
if test.Skip {
t.SkipNow()
}

// t.Parallel()

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Minute)
defer cancel()

api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
t.Cleanup(func() {
api.Done(t)
})

ffs := []struct {
Name string
FF string
}{
{Name: "classic"},
{Name: "pvc", FF: "persistent_volume_claim"},
}

api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
t.Cleanup(func() {
api.Done(t)
for _, ff := range ffs {
for _, test := range tests {
t.Run(test.ContextURL+"_"+ff.Name, func(t *testing.T) {
if test.Skip {
t.SkipNow()
}

username := username + ff.Name
userId, err := api.CreateUser(username, userToken)
if err != nil {
t.Fatal(err)
}

if err := api.UpdateUserFeatureFlag(userId, ff.FF); err != nil {
t.Fatal(err)
}

nfo, stopWS, err := integration.LaunchWorkspaceFromContextURL(ctx, test.ContextURL, username, api)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
stopWS(true)
})

rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(), integration.WithInstanceID(nfo.LatestInstance.ID))
if err != nil {
t.Fatal(err)
}
defer rsa.Close()
integration.DeferCloser(t, closer)

// get actual from workspace
git := common.Git(rsa)
err = git.ConfigSafeDirectory()
if err != nil {
t.Fatal(err)
}
actBranch, err := git.GetBranch(test.WorkspaceRoot)
if err != nil {
t.Fatal(err)
}

expectedBranch := test.ExpectedBranch
if test.ExpectedBranchFunc != nil {
expectedBranch = test.ExpectedBranchFunc(username)
}
if actBranch != expectedBranch {
t.Fatalf("expected branch '%s', got '%s'!", expectedBranch, actBranch)
}
})

_, 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)
}
defer stopWS(true)

rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(), integration.WithInstanceID(nfo.LatestInstance.ID))
if err != nil {
t.Fatal(err)
}
defer rsa.Close()
integration.DeferCloser(t, closer)

// get actual from workspace
git := common.Git(rsa)
err = git.ConfigSafeDirectory()
if err != nil {
t.Fatal(err)
}
actBranch, err := git.GetBranch(test.WorkspaceRoot)
if err != nil {
t.Fatal(err)
}

expectedBranch := test.ExpectedBranch
if test.ExpectedBranchFunc != nil {
expectedBranch = test.ExpectedBranchFunc(username)
}
if actBranch != expectedBranch {
t.Fatalf("expected branch '%s', got '%s'!", expectedBranch, actBranch)
}
})
}
}
return ctx
}).
Expand Down
116 changes: 75 additions & 41 deletions test/tests/workspace/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,49 +123,64 @@ func TestGitActions(t *testing.T) {
}

f := features.New("GitActions").
WithLabel("component", "server").
WithLabel("component", "workspace").
Assess("it can run git actions", func(_ context.Context, t *testing.T, cfg *envconf.Config) context.Context {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
defer cancel()

api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
t.Cleanup(func() {
api.Done(t)
})

_, err := api.CreateUser(username, userToken)
if err != nil {
t.Fatal(err)
ffs := []struct {
Name string
FF string
}{
{Name: "classic"},
{Name: "pvc", FF: "persistent_volume_claim"},
}

for _, test := range tests {
t.Run(test.ContextURL, func(t *testing.T) {
if test.Skip {
t.SkipNow()
}

nfo, stopWS, err := integration.LaunchWorkspaceFromContextURL(ctx, test.ContextURL, username, api)
if err != nil {
t.Fatal(err)
}

defer stopWS(false)

rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(), integration.WithInstanceID(nfo.LatestInstance.ID))
if err != nil {
t.Fatal(err)
}
defer rsa.Close()
integration.DeferCloser(t, closer)

git := common.Git(rsa)
err = test.Action(rsa, git, test.WorkspaceRoot)
if err != nil {
t.Fatal(err)
}
})
for _, ff := range ffs {
for _, test := range tests {
t.Run(test.ContextURL+"_"+ff.Name, func(t *testing.T) {
if test.Skip {
t.SkipNow()
}

username := username + ff.Name
userId, err := api.CreateUser(username, userToken)
if err != nil {
t.Fatal(err)
}

if err := api.UpdateUserFeatureFlag(userId, ff.FF); err != nil {
t.Fatal(err)
}

nfo, stopWS, err := integration.LaunchWorkspaceFromContextURL(ctx, test.ContextURL, username, api)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
stopWS(true)
})

rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(), integration.WithInstanceID(nfo.LatestInstance.ID))
if err != nil {
t.Fatal(err)
}
defer rsa.Close()
integration.DeferCloser(t, closer)

git := common.Git(rsa)
err = test.Action(rsa, git, test.WorkspaceRoot)
if err != nil {
t.Fatal(err)
}
})
}
}

return ctx
}).
Feature()
Expand All @@ -179,7 +194,7 @@ func TestGitLFSSupport(t *testing.T) {
integration.SkipWithoutUserToken(t, userToken)

f := features.New("GitLFSSupport").
WithLabel("component", "server").
WithLabel("component", "workspace").
Assess("it can open a repo with Git LFS support", func(_ context.Context, t *testing.T, cfg *envconf.Config) context.Context {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
Expand All @@ -189,17 +204,36 @@ func TestGitLFSSupport(t *testing.T) {
api.Done(t)
})

_, err := api.CreateUser(username, userToken)
if err != nil {
t.Fatal(err)
ffs := []struct {
Name string
FF string
}{
{Name: "classic"},
{Name: "pvc", FF: "persistent_volume_claim"},
}

_, stopWs, err := integration.LaunchWorkspaceFromContextURL(ctx, "github.com/atduarte/lfs-test", username, api)
if err != nil {
t.Fatal(err)
}
defer stopWs(true)
for _, ff := range ffs {
t.Run(ff.Name, func(t *testing.T) {
username := username + ff.Name
userId, err := api.CreateUser(username, userToken)
if err != nil {
t.Fatal(err)
}

if err := api.UpdateUserFeatureFlag(userId, ff.FF); err != nil {
t.Fatal(err)
}

_, stopWS, err := integration.LaunchWorkspaceFromContextURL(ctx, "github.com/atduarte/lfs-test", username, api)
if err != nil {
t.Fatal(err)
}

t.Cleanup(func() {
stopWS(true)
})
})
}
return ctx
}).
Feature()
Expand Down