diff --git a/test/README.md b/test/README.md index 19445c8716e135..6d79a31a27e7ed 100644 --- a/test/README.md +++ b/test/README.md @@ -40,33 +40,34 @@ You may want to run tests to assert whether a Gitpod installation is successfull Best for when you want to validate an environment. -1. Create a service account, role, and role-binding for integration testing. +1. Update image name in `integration.yaml` for job `integration-job` to latest built by werft. +2. Optionally add your username in that job argument or any other additional params. +2. Apply yaml file that will add all necessary permissions and create a job that will run tests. * [`kubectl apply -f ./integration.yaml`](./integration.yaml) -2. Run a pod to execute the tests like so: - ```bash - # Replace , , and with meaningful values - kubectl run --image=eu.gcr.io/gitpod-core-dev/build/integration-tests:main. \ - integ-tests --serviceaccount=integration-svc \ - --restart=Never \ - --requests='cpu=2,memory=4Gi' \ - -- /bin/sh -namespace= -username= - ``` -3. Check logs to inspect test results like so `kubectl logs -f integ-tests`. -4. Tear down the integration user and pod when testing is done. +3. Check logs to inspect test results like so `kubectl logs -f jobs/integration-job`. +4. Tear down the integration user and job when testing is done. * [`kubectl delete -f ./integration.yaml`](./integration.yaml) - * `kubectl delete pod integ-user` #### Go test Best for when you're actively developing Gitpod. - -1. Set your kubectl context to the cluster you want to test -2. Integrate the Gitpod installation with OAuth for Github and/or Gitlab, otherwise related tests may fail -3. Clone this repo, and `cd` to `./gitpod/test` -4. Run the tests like so +Test will work if images that they use are already cached by gitpod instnance. If not, they might fail if it takes too long to pull an image. +There are 4 different types of tests: +1. Enterprise specific, that require valid license to be installed. Run those with `-enterprise=true` +2. Tests that require correct user (user should have github OAuth integration setup with gitpod). Run those with `-username=`. Make sure to load https://github.com/gitpod-io/gitpod-test-repo and https://github.com/gitpod-io/gitpod workspaces inside your gitpod that you are testing to preload those images onto your node. Wait for it to finish pulling those image, this will ensure that test will not fail due to timeout while waiting to pull an image for the first time. +3. To test gitlab integration, add `-gitlab=true` +4. All other tests. + +To run the tests: +1. Clone this repo (`git clone git@github.com:gitpod-io/gitpod.git`), and `cd` to `./gitpod/test` +2. Run the tests like so ```bash go test -v ./... \ -kubeconfig= \ -namespace= \ - -username= + -username= \ + -enterprise= \ + -gitlab= ``` +3. Tests `TestUploadDownloadBlob` and `TestUploadDownloadBlobViaServer` will fail when testing locally, as they are trying to connect to cluster local resources directly. To test them use docker image instead that runs within the cluster. +4. If you want to run specific test, add `-run ` before `-kubeconfig` parameter. \ No newline at end of file diff --git a/test/integration.yaml b/test/integration.yaml index e1f230713fd15e..da42ea73b84493 100644 --- a/test/integration.yaml +++ b/test/integration.yaml @@ -15,6 +15,7 @@ rules: - 'secrets' - 'services' - 'configmaps' + - 'endpoints' verbs: - 'list' - 'get' @@ -22,9 +23,9 @@ rules: - '' resources: - 'pods/portforward' + - 'pods/exec' verbs: - 'create' - --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding @@ -37,3 +38,25 @@ roleRef: kind: Role name: integration-role apiGroup: rbac.authorization.k8s.io +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: integration-job +spec: + template: + spec: + serviceAccountName: integration-svc + containers: + - name: tests + image: eu.gcr.io/gitpod-core-dev/build/integration-tests:kyleb-installer-integration.24 + imagePullPolicy: Always + #args: ["-username=sagor999"] + #args: ["-enterprise=true"] + #args: ["-gitlab=true"] + resources: + requests: + cpu: 2 + memory: 4Gi + restartPolicy: Never + backoffLimit: 0 diff --git a/test/pkg/integration/apis.go b/test/pkg/integration/apis.go index c22f13f78fd2bf..3994ece0254d3c 100644 --- a/test/pkg/integration/apis.go +++ b/test/pkg/integration/apis.go @@ -46,10 +46,11 @@ import ( ) // API provides access to the individual component's API -func NewComponentAPI(ctx context.Context, namespace string, client klient.Client) *ComponentAPI { +func NewComponentAPI(ctx context.Context, namespace string, kubeconfig string, client klient.Client) *ComponentAPI { return &ComponentAPI{ - namespace: namespace, - client: client, + namespace: namespace, + kubeconfig: kubeconfig, + client: client, closerMutex: sync.Mutex{}, @@ -71,8 +72,9 @@ type serverStatus struct { // ComponentAPI provides access to the individual component's API type ComponentAPI struct { - namespace string - client klient.Client + namespace string + kubeconfig string + client klient.Client closer []func() error closerMutex sync.Mutex @@ -170,7 +172,7 @@ func (c *ComponentAPI) Supervisor(instanceID string) (grpc.ClientConnInterface, } ctx, cancel := context.WithCancel(context.Background()) - ready, errc := common.ForwardPort(ctx, c.client.RESTConfig(), c.namespace, pod, fmt.Sprintf("%d:22999", localPort)) + ready, errc := common.ForwardPort(ctx, c.kubeconfig, c.namespace, pod, fmt.Sprintf("%d:22999", localPort)) select { case err = <-errc: cancel() @@ -483,7 +485,7 @@ func (c *ComponentAPI) WorkspaceManager() (wsmanapi.WorkspaceManagerClient, erro } ctx, cancel := context.WithCancel(context.Background()) - ready, errc := common.ForwardPort(ctx, c.client.RESTConfig(), c.namespace, pod, fmt.Sprintf("%d:8080", localPort)) + ready, errc := common.ForwardPort(ctx, c.kubeconfig, c.namespace, pod, fmt.Sprintf("%d:8080", localPort)) select { case err := <-errc: cancel() @@ -556,7 +558,7 @@ func (c *ComponentAPI) BlobService() (csapi.BlobServiceClient, error) { } ctx, cancel := context.WithCancel(context.Background()) - ready, errc := common.ForwardPort(ctx, c.client.RESTConfig(), c.namespace, pod, fmt.Sprintf("%d:8080", localPort)) + ready, errc := common.ForwardPort(ctx, c.kubeconfig, c.namespace, pod, fmt.Sprintf("%d:8080", localPort)) select { case err := <-errc: cancel() @@ -609,7 +611,7 @@ func (c *ComponentAPI) DB(options ...DBOpt) (*sql.DB, error) { // if configured: setup local port-forward to DB pod if config.ForwardPort != nil { ctx, cancel := context.WithCancel(context.Background()) - ready, errc := common.ForwardPort(ctx, c.client.RESTConfig(), c.namespace, config.ForwardPort.PodName, fmt.Sprintf("%d:%d", config.Port, config.ForwardPort.RemotePort)) + ready, errc := common.ForwardPort(ctx, c.kubeconfig, c.namespace, config.ForwardPort.PodName, fmt.Sprintf("%d:%d", config.Port, config.ForwardPort.RemotePort)) select { case err := <-errc: cancel() @@ -855,7 +857,7 @@ func (c *ComponentAPI) ImageBuilder(opts ...APIImageBuilderOpt) (imgbldr.ImageBu } ctx, cancel := context.WithCancel(context.Background()) - ready, errc := common.ForwardPort(ctx, c.client.RESTConfig(), c.namespace, pod, fmt.Sprintf("%d:8080", localPort)) + ready, errc := common.ForwardPort(ctx, c.kubeconfig, c.namespace, pod, fmt.Sprintf("%d:8080", localPort)) select { case err = <-errc: cancel() @@ -904,7 +906,7 @@ func (c *ComponentAPI) ContentService() (ContentService, error) { } ctx, cancel := context.WithCancel(context.Background()) - ready, errc := common.ForwardPort(ctx, c.client.RESTConfig(), c.namespace, pod, fmt.Sprintf("%d:8080", localPort)) + ready, errc := common.ForwardPort(ctx, c.kubeconfig, c.namespace, pod, fmt.Sprintf("%d:8080", localPort)) select { case err := <-errc: cancel() diff --git a/test/pkg/integration/common/port_forward.go b/test/pkg/integration/common/port_forward.go index 6e7279e1897a85..c4a9132f27b3e3 100644 --- a/test/pkg/integration/common/port_forward.go +++ b/test/pkg/integration/common/port_forward.go @@ -13,12 +13,12 @@ import ( "time" "golang.org/x/xerrors" - "k8s.io/client-go/rest" ) // ForwardPort establishes a TCP port forwarding to a Kubernetes pod // Uses kubectl instead of Go to use a local process that can reproduce the same behavior outside the tests -func ForwardPort(ctx context.Context, config *rest.Config, namespace, pod, port string) (readychan chan struct{}, errchan chan error) { +// Since we are using kubectl directly we need to pass kubeconfig explicetly +func ForwardPort(ctx context.Context, kubeconfig string, namespace, pod, port string) (readychan chan struct{}, errchan chan error) { errchan = make(chan error, 1) readychan = make(chan struct{}, 1) @@ -28,18 +28,19 @@ func ForwardPort(ctx context.Context, config *rest.Config, namespace, pod, port "--address=0.0.0.0", fmt.Sprintf("pod/%v", pod), fmt.Sprintf("--namespace=%v", namespace), + fmt.Sprintf("--kubeconfig=%v", kubeconfig), port, } command := exec.CommandContext(ctx, "kubectl", args...) err := command.Start() if err != nil { - errchan <- xerrors.Errorf("unexpected error starting port-forward: %w", err) + errchan <- xerrors.Errorf("unexpected error starting port-forward: %w, args: %v", err, args) } err = command.Wait() if err != nil { - errchan <- xerrors.Errorf("unexpected error running port-forward: %w", err) + errchan <- xerrors.Errorf("unexpected error running port-forward: %w, args: %v", err, args) } }() diff --git a/test/pkg/integration/integration.go b/test/pkg/integration/integration.go index 15e6eca920f11f..56b76916d2dbb5 100644 --- a/test/pkg/integration/integration.go +++ b/test/pkg/integration/integration.go @@ -135,7 +135,7 @@ func WithWorkspacekitLift(lift bool) InstrumentOption { // If there isn't, we attempt to build `_agent/main.go`. // The binary is copied to the destination pod, started and port-forwarded. Then we // create an RPC client. -func Instrument(component ComponentType, agentName string, namespace string, client klient.Client, opts ...InstrumentOption) (*rpc.Client, []func() error, error) { +func Instrument(component ComponentType, agentName string, namespace string, kubeconfig string, client klient.Client, opts ...InstrumentOption) (*rpc.Client, []func() error, error) { var closer []func() error options := instrumentOptions{ @@ -188,7 +188,7 @@ func Instrument(component ComponentType, agentName string, namespace string, cli execErrs := make(chan error, 1) go func() { defer close(execErrs) - execErr := executeAgent(cmd, podName, containerName, namespace, client) + execErr := executeAgent(cmd, podName, containerName, namespace, kubeconfig, client) if execErr != nil { execErrs <- execErr } @@ -214,7 +214,7 @@ func Instrument(component ComponentType, agentName string, namespace string, cli } }() - fwdReady, fwdErr := common.ForwardPort(ctx, client.RESTConfig(), namespace, podName, strconv.Itoa(localAgentPort)) + fwdReady, fwdErr := common.ForwardPort(ctx, kubeconfig, namespace, podName, strconv.Itoa(localAgentPort)) select { case <-fwdReady: case err := <-execErrs: @@ -274,8 +274,9 @@ func getFreePort() (int, error) { return result.Port, nil } -func executeAgent(cmd []string, pod, container string, namespace string, client klient.Client) error { - args := []string{"exec", pod, fmt.Sprintf("--namespace=%v", namespace)} +func executeAgent(cmd []string, pod, container string, namespace string, kubeconfig string, client klient.Client) error { + // since we are self signing certs for gitpod components, pass insecure flag + args := []string{"exec", pod, fmt.Sprintf("--namespace=%v", namespace), "--insecure-skip-tls-verify=true", fmt.Sprintf("--kubeconfig=%v", kubeconfig)} if len(container) > 0 { args = append(args, fmt.Sprintf("--container=%s", container)) } @@ -285,7 +286,7 @@ func executeAgent(cmd []string, pod, container string, namespace string, client command := exec.Command("kubectl", args...) out, err := command.CombinedOutput() if err != nil { - return xerrors.Errorf("cannot run kubectl command: %w\n%v", err, string(out)) + return xerrors.Errorf("cannot run kubectl command: %w\n%v\nargs:%v", err, string(out), args) } return nil @@ -431,12 +432,16 @@ func GetServerConfig(namespace string, client klient.Client) (*ServerConfigParti // ServerIDEConfigPartial is the subset of server IDE config we're using for integration tests. // NOTE: keep in sync with chart/templates/server-ide-configmap.yaml type ServerIDEConfigPartial struct { - IDEVersion string `json:"ideVersion"` - IDEImageRepo string `json:"ideImageRepo"` - IDEImageAliases struct { - Code string `json:"code"` - CodeLatest string `json:"code-latest"` - } `json:"ideImageAliases"` + IDEOptions struct { + Options struct { + Code struct { + Image string `json:"image"` + } `json:"code"` + CodeLatest struct { + Image string `json:"image"` + } `json:"code-latest"` + } `json:"options"` + } `json:"ideOptions"` } func GetServerIDEConfig(namespace string, client klient.Client) (*ServerIDEConfigPartial, error) { diff --git a/test/pkg/integration/setup.go b/test/pkg/integration/setup.go index c883cbde86ba1c..211f070cb99e77 100644 --- a/test/pkg/integration/setup.go +++ b/test/pkg/integration/setup.go @@ -8,6 +8,7 @@ import ( "context" "flag" "fmt" + "math/rand" "os" "testing" "time" @@ -29,9 +30,40 @@ func SkipWithoutUsername(t *testing.T, username string) { t.Skip("Skipping because requires a username") } } -func Setup(ctx context.Context) (string, string, env.Environment) { + +func SkipWithoutEnterpriseLicense(t *testing.T, enterpise bool) { + if !enterpise { + t.Skip("Skipping because requires enterprise license") + } +} + +func EnsureUserExists(t *testing.T, username string, api *ComponentAPI) string { + if username == "" { + t.Logf("no username provided, creating temporary one") + rand.Seed(time.Now().UnixNano()) + randN := rand.Intn(1000) + newUser := fmt.Sprintf("johndoe%d", randN) + userId, err := CreateUser(newUser, false, api) + if err != nil { + t.Fatalf("cannot create user: %q", err) + } + t.Cleanup(func() { + err := DeleteUser(userId, api) + if err != nil { + t.Fatalf("error deleting user %q", err) + } + }) + t.Logf("user '%s' with ID %s created", newUser, userId) + return newUser + } + return username +} + +func Setup(ctx context.Context) (string, string, env.Environment, bool, string, bool) { var ( username string + enterprise bool + gitlab bool waitGitpodReady time.Duration namespace string @@ -46,6 +78,8 @@ func Setup(ctx context.Context) (string, string, env.Environment) { klog.InitFlags(flagset) flagset.StringVar(&username, "username", "", "username to execute the tests with. Chooses one automatically if left blank.") + flagset.BoolVar(&enterprise, "enterprise", false, "whether to test enterprise features. requires enterprise lisence installed.") + flagset.BoolVar(&gitlab, "gitlab", false, "whether to test gitlab integration.") flagset.DurationVar(&waitGitpodReady, "wait-gitpod-timeout", 5*time.Minute, `wait time for Gitpod components before starting integration test`) flagset.StringVar(&namespace, "namespace", "", "Kubernetes cluster namespaces to use") flagset.StringVar(&kubeconfig, "kubeconfig", "", "The path to the kubeconfig file") @@ -90,7 +124,7 @@ func Setup(ctx context.Context) (string, string, env.Environment) { waitOnGitpodRunning(e.Namespace(), waitGitpodReady), ) - return username, e.Namespace(), testenv + return username, e.Namespace(), testenv, enterprise, kubeconfig, gitlab } func waitOnGitpodRunning(namespace string, waitTimeout time.Duration) env.Func { diff --git a/test/pkg/integration/workspace.go b/test/pkg/integration/workspace.go index 32f2068eba74d1..4d0a58fc382703 100644 --- a/test/pkg/integration/workspace.go +++ b/test/pkg/integration/workspace.go @@ -136,7 +136,7 @@ func LaunchWorkspaceDirectly(ctx context.Context, api *ComponentAPI, opts ...Lau if err != nil { return nil, xerrors.Errorf("cannot find server IDE config: %q", err) } - ideImage = cfg.IDEImageAliases.Code + ideImage = cfg.IDEOptions.Options.Code.Image if ideImage == "" { return nil, xerrors.Errorf("cannot start workspaces without an IDE image (required by registry-facade resolver)") } diff --git a/test/tests/components/content-service/content-service_test.go b/test/tests/components/content-service/content-service_test.go index 7e4e801b162772..98b13f9de16ade 100644 --- a/test/tests/components/content-service/content-service_test.go +++ b/test/tests/components/content-service/content-service_test.go @@ -68,7 +68,7 @@ func TestUploadUrl(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) @@ -128,7 +128,7 @@ func TestDownloadUrl(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) @@ -174,7 +174,7 @@ func TestUploadDownloadBlob(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) @@ -217,14 +217,13 @@ func TestUploadDownloadBlob(t *testing.T) { // TestUploadDownloadBlobViaServer uploads a blob via server → content-server and downloads it afterwards func TestUploadDownloadBlobViaServer(t *testing.T) { integration.SkipWithoutUsername(t, username) - f := features.New("UploadDownloadBlobViaServer"). WithLabel("component", "content-server"). Assess("it should uploads a blob via server → content-server and downloads it afterwards", func(_ context.Context, t *testing.T, cfg *envconf.Config) context.Context { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) diff --git a/test/tests/components/content-service/main_test.go b/test/tests/components/content-service/main_test.go index 09a86de89cebb2..58a0b9dace7d2b 100644 --- a/test/tests/components/content-service/main_test.go +++ b/test/tests/components/content-service/main_test.go @@ -14,12 +14,13 @@ import ( ) var ( - testEnv env.Environment - username string - namespace string + testEnv env.Environment + username string + namespace string + kubeconfig string ) func TestMain(m *testing.M) { - username, namespace, testEnv = integration.Setup(context.Background()) + username, namespace, testEnv, _, kubeconfig, _ = integration.Setup(context.Background()) os.Exit(testEnv.Run(m)) } diff --git a/test/tests/components/database/db_test.go b/test/tests/components/database/db_test.go index 9ef9044c43a617..77c579601439bd 100644 --- a/test/tests/components/database/db_test.go +++ b/test/tests/components/database/db_test.go @@ -22,7 +22,7 @@ func TestBuiltinUserExists(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) diff --git a/test/tests/components/database/main_test.go b/test/tests/components/database/main_test.go index 0c82905d746d0b..10a26c1a6d4c5d 100644 --- a/test/tests/components/database/main_test.go +++ b/test/tests/components/database/main_test.go @@ -14,12 +14,13 @@ import ( ) var ( - testEnv env.Environment - username string - namespace string + testEnv env.Environment + username string + namespace string + kubeconfig string ) func TestMain(m *testing.M) { - username, namespace, testEnv = integration.Setup(context.Background()) + username, namespace, testEnv, _, kubeconfig, _ = integration.Setup(context.Background()) os.Exit(testEnv.Run(m)) } diff --git a/test/tests/components/image-builder/builder_test.go b/test/tests/components/image-builder/builder_test.go index 0482e105588217..6066e6a0f9201e 100644 --- a/test/tests/components/image-builder/builder_test.go +++ b/test/tests/components/image-builder/builder_test.go @@ -28,7 +28,7 @@ func TestBaseImageBuild(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) @@ -44,12 +44,12 @@ func TestBaseImageBuild(t *testing.T) { From: &imgapi.BuildSource_File{ File: &imgapi.BuildSourceDockerfile{ DockerfileVersion: "some-version", - DockerfilePath: ".gitpod.Dockerfile", + DockerfilePath: "test/tests/components/image-builder/test.Dockerfile", ContextPath: ".", Source: &csapi.WorkspaceInitializer{ Spec: &csapi.WorkspaceInitializer_Git{ Git: &csapi.GitInitializer{ - RemoteUri: "https://github.com/gitpod-io/dazzle.git", + RemoteUri: "https://github.com/gitpod-io/gitpod.git", TargetMode: csapi.CloneTargetMode_REMOTE_BRANCH, CloneTaget: "main", Config: &csapi.GitConfig{ @@ -104,7 +104,7 @@ func TestParallelBaseImageBuild(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) @@ -120,12 +120,12 @@ func TestParallelBaseImageBuild(t *testing.T) { From: &imgapi.BuildSource_File{ File: &imgapi.BuildSourceDockerfile{ DockerfileVersion: "some-version", - DockerfilePath: ".gitpod.Dockerfile", + DockerfilePath: "test/tests/components/image-builder/test.Dockerfile", ContextPath: ".", Source: &csapi.WorkspaceInitializer{ Spec: &csapi.WorkspaceInitializer_Git{ Git: &csapi.GitInitializer{ - RemoteUri: "https://github.com/gitpod-io/dazzle.git", + RemoteUri: "https://github.com/gitpod-io/gitpod.git", TargetMode: csapi.CloneTargetMode_REMOTE_BRANCH, CloneTaget: "main", Config: &csapi.GitConfig{ diff --git a/test/tests/components/image-builder/main_test.go b/test/tests/components/image-builder/main_test.go index 782508fbf354c1..e12e1cbb3e4fd3 100644 --- a/test/tests/components/image-builder/main_test.go +++ b/test/tests/components/image-builder/main_test.go @@ -14,12 +14,13 @@ import ( ) var ( - testEnv env.Environment - username string - namespace string + testEnv env.Environment + username string + namespace string + kubeconfig string ) func TestMain(m *testing.M) { - username, namespace, testEnv = integration.Setup(context.Background()) + username, namespace, testEnv, _, kubeconfig, _ = integration.Setup(context.Background()) os.Exit(testEnv.Run(m)) } diff --git a/test/tests/components/server/blockuser_test.go b/test/tests/components/server/blockuser_test.go index d6b76d4e9e7a5f..8c54dd338a8869 100644 --- a/test/tests/components/server/blockuser_test.go +++ b/test/tests/components/server/blockuser_test.go @@ -19,13 +19,14 @@ import ( ) func TestAdminBlockUser(t *testing.T) { + integration.SkipWithoutEnterpriseLicense(t, enterprise) f := features.New("block user"). WithLabel("component", "server"). Assess("it should block new created user", func(_ context.Context, t *testing.T, cfg *envconf.Config) context.Context { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) diff --git a/test/tests/components/server/main_test.go b/test/tests/components/server/main_test.go index 7dd0e68d2a9688..101f01289ba4c8 100644 --- a/test/tests/components/server/main_test.go +++ b/test/tests/components/server/main_test.go @@ -14,12 +14,14 @@ import ( ) var ( - testEnv env.Environment - username string - namespace string + testEnv env.Environment + username string + namespace string + enterprise bool + kubeconfig string ) func TestMain(m *testing.M) { - username, namespace, testEnv = integration.Setup(context.Background()) + username, namespace, testEnv, enterprise, kubeconfig, _ = integration.Setup(context.Background()) os.Exit(testEnv.Run(m)) } diff --git a/test/tests/components/server/server_test.go b/test/tests/components/server/server_test.go index 97d69bd54e4c54..031f594f3f3042 100644 --- a/test/tests/components/server/server_test.go +++ b/test/tests/components/server/server_test.go @@ -23,11 +23,13 @@ func TestServerAccess(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) + username := integration.EnsureUserExists(t, username, api) + server, err := api.GitpodServer(integration.WithGitpodUser(username)) if err != nil { t.Fatalf("cannot get GitpodServer: %q", err) @@ -54,7 +56,7 @@ func TestStartWorkspace(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) diff --git a/test/tests/components/ws-daemon/main_test.go b/test/tests/components/ws-daemon/main_test.go index 8f3e6e819e960a..324652dc80f5ad 100644 --- a/test/tests/components/ws-daemon/main_test.go +++ b/test/tests/components/ws-daemon/main_test.go @@ -14,12 +14,13 @@ import ( ) var ( - testEnv env.Environment - username string - namespace string + testEnv env.Environment + username string + namespace string + kubeconfig string ) func TestMain(m *testing.M) { - username, namespace, testEnv = integration.Setup(context.Background()) + username, namespace, testEnv, _, kubeconfig, _ = integration.Setup(context.Background()) os.Exit(testEnv.Run(m)) } diff --git a/test/tests/components/ws-daemon/storage_test.go b/test/tests/components/ws-daemon/storage_test.go index d869aa3ba3e7bc..f741e6569ad77f 100644 --- a/test/tests/components/ws-daemon/storage_test.go +++ b/test/tests/components/ws-daemon/storage_test.go @@ -24,7 +24,7 @@ func TestCreateBucket(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - rsa, closer, err := integration.Instrument(integration.ComponentWorkspaceDaemon, "daemon", cfg.Namespace(), cfg.Client(), + rsa, closer, err := integration.Instrument(integration.ComponentWorkspaceDaemon, "daemon", cfg.Namespace(), kubeconfig, cfg.Client(), integration.WithWorkspacekitLift(false), integration.WithContainer("ws-daemon"), ) diff --git a/test/tests/components/ws-manager/content_test.go b/test/tests/components/ws-manager/content_test.go index 0a99a0a3c06471..cece09f5bdbd7c 100644 --- a/test/tests/components/ws-manager/content_test.go +++ b/test/tests/components/ws-manager/content_test.go @@ -26,7 +26,7 @@ func TestBackup(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) @@ -41,7 +41,7 @@ func TestBackup(t *testing.T) { t.Fatal(err) } - rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), cfg.Client(), + rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(), integration.WithInstanceID(ws.Req.Id), integration.WithContainer("workspace"), integration.WithWorkspacekitLift(true), @@ -87,7 +87,7 @@ func TestBackup(t *testing.T) { t.Fatal(err) } - rsa, closer, err = integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), cfg.Client(), + rsa, closer, err = integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(), integration.WithInstanceID(ws.Req.Id), ) if err != nil { @@ -141,7 +141,7 @@ func TestMissingBackup(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) diff --git a/test/tests/components/ws-manager/main_test.go b/test/tests/components/ws-manager/main_test.go index 5ef48037d17a5a..4c816cb492d84a 100644 --- a/test/tests/components/ws-manager/main_test.go +++ b/test/tests/components/ws-manager/main_test.go @@ -14,12 +14,13 @@ import ( ) var ( - testEnv env.Environment - username string - namespace string + testEnv env.Environment + username string + namespace string + kubeconfig string ) func TestMain(m *testing.M) { - username, namespace, testEnv = integration.Setup(context.Background()) + username, namespace, testEnv, _, kubeconfig, _ = integration.Setup(context.Background()) os.Exit(testEnv.Run(m)) } diff --git a/test/tests/components/ws-manager/prebuild_test.go b/test/tests/components/ws-manager/prebuild_test.go index 9f3391d9803d7a..a997e7c74ea0e0 100644 --- a/test/tests/components/ws-manager/prebuild_test.go +++ b/test/tests/components/ws-manager/prebuild_test.go @@ -23,7 +23,7 @@ func TestPrebuildWorkspaceTaskSuccess(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) @@ -60,7 +60,7 @@ func TestPrebuildWorkspaceTaskFail(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) diff --git a/test/tests/components/ws-manager/tasks_test.go b/test/tests/components/ws-manager/tasks_test.go index ac24998fafddad..f150127d6dc534 100644 --- a/test/tests/components/ws-manager/tasks_test.go +++ b/test/tests/components/ws-manager/tasks_test.go @@ -52,7 +52,7 @@ func TestRegularWorkspaceTasks(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) @@ -113,7 +113,7 @@ func TestRegularWorkspaceTasks(t *testing.T) { } } - rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), cfg.Client(), integration.WithInstanceID(nfo.Req.Id)) + rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(), integration.WithInstanceID(nfo.Req.Id)) if err != nil { t.Fatalf("unexpected error instrumenting workspace: %v", err) } diff --git a/test/tests/components/ws-manager/wsmanager_test.go b/test/tests/components/ws-manager/wsmanager_test.go index c48dfffb5d6ec6..b14d7d5a48c1b0 100644 --- a/test/tests/components/ws-manager/wsmanager_test.go +++ b/test/tests/components/ws-manager/wsmanager_test.go @@ -23,7 +23,7 @@ func TestGetWorkspaces(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) diff --git a/test/tests/ide/main_test.go b/test/tests/ide/main_test.go index 597c112a43955f..2055b74f64e66b 100644 --- a/test/tests/ide/main_test.go +++ b/test/tests/ide/main_test.go @@ -14,12 +14,13 @@ import ( ) var ( - testEnv env.Environment - username string - namespace string + testEnv env.Environment + username string + namespace string + kubeconfig string ) func TestMain(m *testing.M) { - username, namespace, testEnv = integration.Setup(context.Background()) + username, namespace, testEnv, _, kubeconfig, _ = integration.Setup(context.Background()) os.Exit(testEnv.Run(m)) } diff --git a/test/tests/ide/python_ws_test.go b/test/tests/ide/python_ws_test.go index 348b5a9fc04f54..53042797157301 100644 --- a/test/tests/ide/python_ws_test.go +++ b/test/tests/ide/python_ws_test.go @@ -39,13 +39,14 @@ func poolTask(task func() (bool, error)) (bool, error) { } func TestPythonExtWorkspace(t *testing.T) { + integration.SkipWithoutUsername(t, username) f := features.New("PythonExtensionWorkspace"). WithLabel("component", "server"). Assess("it can run python extension in a workspace", func(_ context.Context, t *testing.T, cfg *envconf.Config) context.Context { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) @@ -80,7 +81,7 @@ func TestPythonExtWorkspace(t *testing.T) { t.Fatal(err) } - rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), cfg.Client(), integration.WithInstanceID(nfo.LatestInstance.ID), integration.WithWorkspacekitLift(true)) + rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(), integration.WithInstanceID(nfo.LatestInstance.ID), integration.WithWorkspacekitLift(true)) if err != nil { t.Fatal(err) } diff --git a/test/tests/workspace/contexts_test.go b/test/tests/workspace/contexts_test.go index 881942b825a016..48d8e0c84e2764 100644 --- a/test/tests/workspace/contexts_test.go +++ b/test/tests/workspace/contexts_test.go @@ -59,8 +59,9 @@ func TestGitHubContexts(t *testing.T) { } func TestGitLabContexts(t *testing.T) { - integration.SkipWithoutUsername(t, username) - + if !gitlab { + t.Skip("Skipping gitlab integration tests") + } tests := []ContextTest{ { Name: "open repository", @@ -93,6 +94,7 @@ func TestGitLabContexts(t *testing.T) { } func runContextTests(t *testing.T, tests []ContextTest) { + integration.SkipWithoutUsername(t, username) f := features.New("context"). WithLabel("component", "server"). Assess("should run context tests", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { @@ -107,15 +109,11 @@ func runContextTests(t *testing.T, tests []ContextTest) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) - if username == "" && test.ExpectedBranchFunc != nil { - t.Skipf("skipping '%s' because there is not username configured", test.Name) - } - nfo, stopWS, err := integration.LaunchWorkspaceFromContextURL(ctx, test.ContextURL, username, api) if err != nil { t.Fatal(err) @@ -127,7 +125,7 @@ func runContextTests(t *testing.T, tests []ContextTest) { t.Fatal(err) } - rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), cfg.Client(), integration.WithInstanceID(nfo.LatestInstance.ID)) + rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(), integration.WithInstanceID(nfo.LatestInstance.ID)) if err != nil { t.Fatal(err) } diff --git a/test/tests/workspace/docker_test.go b/test/tests/workspace/docker_test.go index f22ffb22474b72..3cc4fa494bb2d2 100644 --- a/test/tests/workspace/docker_test.go +++ b/test/tests/workspace/docker_test.go @@ -23,7 +23,7 @@ func TestRunDocker(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) @@ -33,7 +33,7 @@ func TestRunDocker(t *testing.T) { t.Fatal(err) } - rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), cfg.Client(), integration.WithInstanceID(ws.Req.Id), integration.WithWorkspacekitLift(true)) + rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(), integration.WithInstanceID(ws.Req.Id), integration.WithWorkspacekitLift(true)) if err != nil { t.Fatalf("unexpected error instrumenting workspace: %v", err) } diff --git a/test/tests/workspace/example_test.go b/test/tests/workspace/example_test.go index 7557b5a71345e5..f8c6bed1ea3694 100644 --- a/test/tests/workspace/example_test.go +++ b/test/tests/workspace/example_test.go @@ -17,13 +17,14 @@ import ( ) func TestWorkspaceInstrumentation(t *testing.T) { + integration.SkipWithoutUsername(t, username) f := features.New("instrumentation"). WithLabel("component", "server"). Assess("it can instrument a workspace", func(_ context.Context, t *testing.T, cfg *envconf.Config) context.Context { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) @@ -34,7 +35,7 @@ func TestWorkspaceInstrumentation(t *testing.T) { } defer stopWs(true) - rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), cfg.Client(), integration.WithInstanceID(nfo.LatestInstance.ID)) + rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(), integration.WithInstanceID(nfo.LatestInstance.ID)) if err != nil { t.Fatal(err) } @@ -66,7 +67,7 @@ func TestLaunchWorkspaceDirectly(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) diff --git a/test/tests/workspace/ghost_test.go b/test/tests/workspace/ghost_test.go index 3ea4359ac5e9cb..788e767328dbc0 100644 --- a/test/tests/workspace/ghost_test.go +++ b/test/tests/workspace/ghost_test.go @@ -23,7 +23,7 @@ func TestGhostWorkspace(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) diff --git a/test/tests/workspace/git_test.go b/test/tests/workspace/git_test.go index ea17dc7a80647b..c18491fa2a59b4 100644 --- a/test/tests/workspace/git_test.go +++ b/test/tests/workspace/git_test.go @@ -30,6 +30,7 @@ type GitTest struct { type GitFunc func(rsa *rpc.Client, git common.GitClient, workspaceRoot string) error func TestGitActions(t *testing.T) { + integration.SkipWithoutUsername(t, username) tests := []GitTest{ { Name: "create, add and commit", @@ -102,7 +103,7 @@ func TestGitActions(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - api := integration.NewComponentAPI(ctx, cfg.Namespace(), cfg.Client()) + api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client()) t.Cleanup(func() { api.Done(t) }) @@ -125,7 +126,7 @@ func TestGitActions(t *testing.T) { t.Fatal(err) } - rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), cfg.Client(), integration.WithInstanceID(nfo.LatestInstance.ID)) + rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(), integration.WithInstanceID(nfo.LatestInstance.ID)) if err != nil { t.Fatal(err) } diff --git a/test/tests/workspace/main_test.go b/test/tests/workspace/main_test.go index 7f28d62dd76b16..ff62bb1814681e 100644 --- a/test/tests/workspace/main_test.go +++ b/test/tests/workspace/main_test.go @@ -14,12 +14,14 @@ import ( ) var ( - testEnv env.Environment - username string - namespace string + testEnv env.Environment + username string + namespace string + kubeconfig string + gitlab bool ) func TestMain(m *testing.M) { - username, namespace, testEnv = integration.Setup(context.Background()) + username, namespace, testEnv, _, kubeconfig, gitlab = integration.Setup(context.Background()) os.Exit(testEnv.Run(m)) }