Path: blob/main/test/tests/ide/jetbrains/gateway_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 ide56import (7"context"8_ "embed"9"fmt"10"testing"11"time"1213"sigs.k8s.io/e2e-framework/pkg/envconf"14"sigs.k8s.io/e2e-framework/pkg/features"1516agent "github.com/gitpod-io/gitpod/test/pkg/agent/workspace/api"17"github.com/gitpod-io/gitpod/test/pkg/integration"18)1920func TestGoLand(t *testing.T) {21BaseGuard(t)22t.Parallel()23f := features.New("Start a workspace using GoLand").24WithLabel("component", "IDE").25WithLabel("ide", "GoLand").26Assess("it can let JetBrains Gateway connect", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {27ctx, cancel := context.WithTimeout(testCtx, 30*time.Minute)28defer cancel()29JetBrainsIDETest(ctx, t, cfg, WithIDE("goland"))30return testCtx31}).32Feature()33testEnv.Test(t, f)34}3536func TestIntellij(t *testing.T) {37BaseGuard(t)38t.Parallel()39f := features.New("Start a workspace using Intellij").40WithLabel("component", "IDE").41WithLabel("ide", "Intellij").42Assess("it can let JetBrains Gateway connect", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {43ctx, cancel := context.WithTimeout(testCtx, 30*time.Minute)44defer cancel()4546JetBrainsIDETest(ctx, t, cfg, WithIDE("intellij"))47return testCtx48}).49Feature()50testEnv.Test(t, f)51}5253func TestPhpStorm(t *testing.T) {54BaseGuard(t)55t.Parallel()56f := features.New("Start a workspace using PhpStorm").57WithLabel("component", "IDE").58WithLabel("ide", "PhpStorm").59Assess("it can let JetBrains Gateway connect", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {60ctx, cancel := context.WithTimeout(testCtx, 30*time.Minute)61defer cancel()62JetBrainsIDETest(ctx, t, cfg, WithIDE("phpstorm"))63return testCtx64}).65Feature()66testEnv.Test(t, f)67}6869func TestPyCharm(t *testing.T) {70BaseGuard(t)71t.Parallel()72f := features.New("Start a workspace using Pycharm").73WithLabel("component", "IDE").74WithLabel("ide", "Pycharm").75Assess("it can let JetBrains Gateway connect", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {76ctx, cancel := context.WithTimeout(testCtx, 30*time.Minute)77defer cancel()78JetBrainsIDETest(ctx, t, cfg, WithIDE("pycharm"))79return testCtx80}).81Feature()82testEnv.Test(t, f)83}8485func TestRubyMine(t *testing.T) {86BaseGuard(t)87t.Parallel()88f := features.New("Start a workspace using RubyMine").89WithLabel("component", "IDE").90WithLabel("ide", "RubyMine").91Assess("it can let JetBrains Gateway connect", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {92ctx, cancel := context.WithTimeout(testCtx, 30*time.Minute)93defer cancel()94JetBrainsIDETest(ctx, t, cfg, WithIDE("rubymine"))95return testCtx96}).97Feature()98testEnv.Test(t, f)99}100101func TestWebStorm(t *testing.T) {102BaseGuard(t)103t.Parallel()104f := features.New("Start a workspace using WebStorm").105WithLabel("component", "IDE").106WithLabel("ide", "WebStorm").107Assess("it can let JetBrains Gateway connect", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {108ctx, cancel := context.WithTimeout(testCtx, 30*time.Minute)109defer cancel()110JetBrainsIDETest(ctx, t, cfg, WithIDE("webstorm"))111return testCtx112}).113Feature()114testEnv.Test(t, f)115}116117func TestRider(t *testing.T) {118BaseGuard(t)119t.Parallel()120f := features.New("Start a workspace using Rider").121WithLabel("component", "IDE").122WithLabel("ide", "Rider").123Assess("it can let JetBrains Gateway connect", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {124ctx, cancel := context.WithTimeout(testCtx, 30*time.Minute)125defer cancel()126JetBrainsIDETest(ctx, t, cfg, WithIDE("rider"))127return testCtx128}).129Feature()130testEnv.Test(t, f)131}132133func TestCLion(t *testing.T) {134BaseGuard(t)135t.Parallel()136t.Skip("See EXP-414")137f := features.New("Start a workspace using CLion").138WithLabel("component", "IDE").139WithLabel("ide", "CLion").140Assess("it can let JetBrains Gateway connect", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {141ctx, cancel := context.WithTimeout(testCtx, 30*time.Minute)142defer cancel()143JetBrainsIDETest(ctx, t, cfg, WithIDE("clion"))144return testCtx145}).146Feature()147testEnv.Test(t, f)148}149150func TestRustRover(t *testing.T) {151BaseGuard(t)152t.Parallel()153f := features.New("Start a workspace using RustRover").154WithLabel("component", "IDE").155WithLabel("ide", "RustRover").156Assess("it can let JetBrains Gateway connect", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {157ctx, cancel := context.WithTimeout(testCtx, 30*time.Minute)158defer cancel()159JetBrainsIDETest(ctx, t, cfg, WithIDE("rustrover"))160return testCtx161}).162Feature()163testEnv.Test(t, f)164}165166func TestIntellijNotPreconfiguredRepo(t *testing.T) {167BaseGuard(t)168t.Parallel()169f := features.New("Start a workspace using Intellij with not preconfigured repo").170WithLabel("component", "IDE").171WithLabel("ide", "Intellij").172Assess("it can let JetBrains Gateway connect", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {173ctx, cancel := context.WithTimeout(testCtx, 30*time.Minute)174defer cancel()175// ENT-260176// https://github.com/spring-projects/spring-petclinic is not an option because it will prompt to ask user to select project type177// which will block integration test (UI tests)178JetBrainsIDETest(ctx, t, cfg, WithIDE("intellij"), WithRepo("https://github.com/gitpod-io/empty"))179return testCtx180}).181Feature()182testEnv.Test(t, f)183}184185//go:embed warmup-indexing.sh186var warmupIndexingShell []byte187188func TestIntelliJWarmup(t *testing.T) {189BaseGuard(t)190t.Parallel()191f := features.New("Start a workspace using Intellij and imagebuild to test warmup tasks").192WithLabel("component", "IDE").193WithLabel("ide", "Intellij").194Assess("it can let JetBrains Gateway connect", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {195ctx, cancel := context.WithTimeout(testCtx, 30*time.Minute)196defer cancel()197198testRepo := "https://github.com/gitpod-samples/spring-petclinic"199testRepoBranch := "gp/integration-test"200201api, _, papi, _ := MustConnectToServer(ctx, t, cfg)202t.Logf("get or create team")203teamID, err := api.GetTeam(ctx, papi)204if err != nil {205t.Fatalf("failed to get or create team: %v", err)206}207t.Logf("get or create repository for %s", testRepo)208projectID, err := api.GetProject(ctx, papi, teamID, "petclinic", testRepo, true)209if err != nil {210t.Fatalf("failed to get or create project: %v", err)211}212213triggerAndWaitForPrebuild := func() error {214prebuildID, err := api.TriggerPrebuild(ctx, papi, projectID, testRepoBranch)215if err != nil {216return fmt.Errorf("failed to trigger prebuild: %v", err)217}218t.Logf("prebuild triggered, id: %s", prebuildID)219ok, err := api.WaitForPrebuild(ctx, papi, prebuildID)220if err != nil {221return fmt.Errorf("failed to wait for prebuild: %v", err)222}223if !ok {224return fmt.Errorf("prebuild failed")225}226// EXP-1860227// Prebuild is marked as available before content back-up is completed228if err := api.WaitForPrebuildWorkspaceToStoppedPhase(ctx, prebuildID); err != nil {229return fmt.Errorf("failed to wait for prebuild workspace to be backed-up : %v", err)230}231return nil232}233234t.Logf("trigger prebuild and wait for it")235if err := triggerAndWaitForPrebuild(); err != nil {236t.Fatalf("failed to trigger prebuild: %v", err)237}238t.Logf("prebuild available")239240t.Logf("warmup prebuild prepared, org: %s, repository: %s", teamID, projectID)241242JetBrainsIDETest(ctx, t, cfg, WithIDE("intellij"),243WithRepo(fmt.Sprintf("%s/tree/%s", testRepo, testRepoBranch)),244WithRepositoryID(projectID),245WithAdditionRpcCall(func(rsa *integration.RpcClient, jbCtx *JetBrainsTestCtx) error {246t.Logf("check if it has warmup.log")247var resp agent.ExecResponse248err := rsa.Call("WorkspaceAgent.Exec", &agent.ExecRequest{249Dir: "/",250Command: "bash",251Args: []string{252"-c",253fmt.Sprintf("stat %s/log/warmup/warmup.log", jbCtx.SystemDir),254},255}, &resp)256if err != nil {257return fmt.Errorf("warmup.log not found: %v", err)258}259if resp.ExitCode != 0 {260return fmt.Errorf("warmup.log not found: %s, %d", resp.Stderr, resp.ExitCode)261}262return nil263}),264WithAdditionRpcCall(func(rsa *integration.RpcClient, jbCtx *JetBrainsTestCtx) error {265t.Logf("sleep for 1 minute to wait project open")266var resp agent.ExecResponse267time.Sleep(1 * time.Minute)268t.Logf("checking warmup indexing")269err := rsa.Call("WorkspaceAgent.Exec", &agent.ExecRequest{270Dir: "/",271Command: "bash",272Args: []string{273"-c",274string(warmupIndexingShell),275"--",276jbCtx.SystemDir,277"1",278},279}, &resp)280if err != nil {281return fmt.Errorf("failed to warmup indexing: %v", err)282}283t.Logf("stdout:\n%s", string(resp.Stdout))284if resp.ExitCode != 0 {285return fmt.Errorf("failed to warmup indexing: %s, %d", resp.Stderr, resp.ExitCode)286}287return nil288}))289return testCtx290}).291Feature()292testEnv.Test(t, f)293}294295296