Skip to content

Commit

Permalink
Add integration tests for JetBrains backend plugin (#19665)
Browse files Browse the repository at this point in the history
* Add integration tests and metrics for JetBrains backend plugin

* fix build

* Update product code

* update log format

* Reapply "[JetBrains] Update IDE images to new build version (#19654)" (#19660)

This reverts commit 7946ea6.

* Revert "Reapply "[JetBrains] Update IDE images to new build version (#19654)" (#19660)"

This reverts commit 70a0261.
  • Loading branch information
mustard-mh authored May 6, 2024
1 parent 30d5e2f commit 355c91a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ class GitpodManager : Disposable {
httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString())
if (response.statusCode() == 200) {
val gatewayLink = response.body()
// the output format should be constant (includes `Gitpod gateway link`)
// which will be checked in integration test gateway_test.go
thisLogger().warn(
"\n\n\n*********************************************************\n\n" +
"Gitpod gateway link: $gatewayLink" +
Expand Down
115 changes: 72 additions & 43 deletions test/tests/ide/jetbrains/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io/ioutil"
"net/http"
"os"
"regexp"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -72,7 +73,7 @@ func GetHttpContent(url string, ownerToken string) ([]byte, error) {
return b, err
}

func JetBrainsIDETest(ctx context.Context, t *testing.T, cfg *envconf.Config, ide string, repo string) {
func JetBrainsIDETest(ctx context.Context, t *testing.T, cfg *envconf.Config, ide, productCode, repo string) {
api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
t.Cleanup(func() {
api.Done(t)
Expand Down Expand Up @@ -151,39 +152,6 @@ func JetBrainsIDETest(ctx context.Context, t *testing.T, cfg *envconf.Config, id
t.Fatal(err)
}

if ide == "intellij" {
t.Logf("Check idea.log file correct location")
rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(), integration.WithInstanceID(info.LatestInstance.ID), integration.WithWorkspacekitLift(true))
if err != nil {
t.Fatal(err)
}
defer rsa.Close()
integration.DeferCloser(t, closer)

qualifier := ""
if useLatest {
qualifier = "-latest"
}

var resp agent.ExecResponse
err = rsa.Call("WorkspaceAgent.Exec", &agent.ExecRequest{
Dir: "/",
Command: "bash",
Args: []string{
"-c",
fmt.Sprintf("test -f /workspace/.cache/JetBrains%s/RemoteDev-IU/log/idea.log", qualifier),
},
}, &resp)

if err != nil {
t.Fatal(err)
}

if resp.ExitCode != 0 {
t.Fatal("idea.log file not found in the expected location")
}
}

ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: roboquatToken},
)
Expand Down Expand Up @@ -228,6 +196,67 @@ func JetBrainsIDETest(ctx context.Context, t *testing.T, cfg *envconf.Config, id
if !testStatus {
t.Fatal(ctx.Err())
}

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

fatalMessages := []string{}

checkIDEALogs := func() {
qualifier := ""
if useLatest {
qualifier = "-latest"
}
jbSystemDir := fmt.Sprintf("/workspace/.cache/JetBrains%s/RemoteDev-%s", qualifier, productCode)
ideaLogPath := jbSystemDir + "/log/idea.log"

t.Logf("Check idea.log file correct location")

var resp agent.ExecResponse
err = rsa.Call("WorkspaceAgent.Exec", &agent.ExecRequest{
Dir: "/",
Command: "bash",
Args: []string{
"-c",
fmt.Sprintf("cat %s", ideaLogPath),
},
}, &resp)

t.Logf("checking idea.log")
if err != nil || resp.ExitCode != 0 {
t.Fatal("idea.log file not found in the expected location")
}

pluginLoadedRegex := regexp.MustCompile(`Loaded custom plugins:.* Gitpod Remote`)
pluginStartedRegex := regexp.MustCompile(`Gitpod gateway link`)
pluginIncompatibleRegex := regexp.MustCompile(`Plugin 'Gitpod Remote' .* is not compatible`)

ideaLogs := []byte(resp.Stdout)
if pluginLoadedRegex.Match(ideaLogs) {
t.Logf("backend-plugin loaded")
} else {
fatalMessages = append(fatalMessages, "backend-plugin not loaded")
}
if pluginStartedRegex.Match(ideaLogs) {
t.Logf("backend-plugin started")
} else {
fatalMessages = append(fatalMessages, "backend-plugin not started")
}
if pluginIncompatibleRegex.Match(ideaLogs) {
fatalMessages = append(fatalMessages, "backend-plugin is incompatible")
} else {
t.Logf("backend-plugin maybe compatible")
}
}
checkIDEALogs()

if len(fatalMessages) > 0 {
t.Fatalf("[error] tests fail: \n%s", strings.Join(fatalMessages, "\n"))
}
}

func resolveDesktopIDELink(info *protocol.WorkspaceInfo, ide string, ownerToken string, t *testing.T) (string, error) {
Expand Down Expand Up @@ -288,7 +317,7 @@ func TestGoLand(t *testing.T) {
Assess("it can let JetBrains Gateway connect", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
ctx, cancel := context.WithTimeout(testCtx, 30*time.Minute)
defer cancel()
JetBrainsIDETest(ctx, t, cfg, "goland", "https://github.com/gitpod-samples/template-golang-cli")
JetBrainsIDETest(ctx, t, cfg, "goland", "GO", "https://github.com/gitpod-samples/template-golang-cli")
return testCtx
}).
Feature()
Expand All @@ -307,7 +336,7 @@ func TestIntellij(t *testing.T) {
Assess("it can let JetBrains Gateway connect", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
ctx, cancel := context.WithTimeout(testCtx, 30*time.Minute)
defer cancel()
JetBrainsIDETest(ctx, t, cfg, "intellij", "https://github.com/jeanp413/spring-petclinic")
JetBrainsIDETest(ctx, t, cfg, "intellij", "IU", "https://github.com/jeanp413/spring-petclinic")
return testCtx
}).
Feature()
Expand All @@ -326,7 +355,7 @@ func TestPhpStorm(t *testing.T) {
Assess("it can let JetBrains Gateway connect", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
ctx, cancel := context.WithTimeout(testCtx, 30*time.Minute)
defer cancel()
JetBrainsIDETest(ctx, t, cfg, "phpstorm", "https://github.com/gitpod-samples/template-php-laravel-mysql")
JetBrainsIDETest(ctx, t, cfg, "phpstorm", "PS", "https://github.com/gitpod-samples/template-php-laravel-mysql")
return testCtx
}).
Feature()
Expand All @@ -345,7 +374,7 @@ func TestPyCharm(t *testing.T) {
Assess("it can let JetBrains Gateway connect", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
ctx, cancel := context.WithTimeout(testCtx, 30*time.Minute)
defer cancel()
JetBrainsIDETest(ctx, t, cfg, "pycharm", "https://github.com/gitpod-samples/template-python-django")
JetBrainsIDETest(ctx, t, cfg, "pycharm", "PY", "https://github.com/gitpod-samples/template-python-django")
return testCtx
}).
Feature()
Expand All @@ -365,8 +394,8 @@ func TestRubyMine(t *testing.T) {
ctx, cancel := context.WithTimeout(testCtx, 30*time.Minute)
defer cancel()
// TODO: open comment after https://github.com/gitpod-io/gitpod/issues/16302 resolved
// JetBrainsIDETest(ctx, t, cfg, "rubymine", "https://github.com/gitpod-samples/template-ruby-on-rails-postgres")
JetBrainsIDETest(ctx, t, cfg, "rubymine", "https://github.com/gitpod-io/Gitpod-Ruby-On-Rails")
// JetBrainsIDETest(ctx, t, cfg, "rubymine", "RM", "https://github.com/gitpod-samples/template-ruby-on-rails-postgres")
JetBrainsIDETest(ctx, t, cfg, "rubymine", "RM", "https://github.com/gitpod-io/Gitpod-Ruby-On-Rails")
return testCtx
}).
Feature()
Expand All @@ -385,7 +414,7 @@ func TestWebStorm(t *testing.T) {
Assess("it can let JetBrains Gateway connect", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
ctx, cancel := context.WithTimeout(testCtx, 30*time.Minute)
defer cancel()
JetBrainsIDETest(ctx, t, cfg, "webstorm", "https://github.com/gitpod-samples/template-typescript-react")
JetBrainsIDETest(ctx, t, cfg, "webstorm", "WS", "https://github.com/gitpod-samples/template-typescript-react")
return testCtx
}).
Feature()
Expand All @@ -404,7 +433,7 @@ func TestRider(t *testing.T) {
Assess("it can let JetBrains Gateway connect", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
ctx, cancel := context.WithTimeout(testCtx, 30*time.Minute)
defer cancel()
JetBrainsIDETest(ctx, t, cfg, "rider", "https://github.com/gitpod-samples/template-dotnet-core-cli-csharp")
JetBrainsIDETest(ctx, t, cfg, "rider", "RD", "https://github.com/gitpod-samples/template-dotnet-core-cli-csharp")
return testCtx
}).
Feature()
Expand All @@ -424,7 +453,7 @@ func TestCLion(t *testing.T) {
Assess("it can let JetBrains Gateway connect", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
ctx, cancel := context.WithTimeout(testCtx, 30*time.Minute)
defer cancel()
JetBrainsIDETest(ctx, t, cfg, "clion", "https://github.com/gitpod-samples/template-cpp")
JetBrainsIDETest(ctx, t, cfg, "clion", "CL", "https://github.com/gitpod-samples/template-cpp")
return testCtx
}).
Feature()
Expand Down

0 comments on commit 355c91a

Please sign in to comment.