Path: blob/main/components/ws-manager-mk2/controllers/create_test.go
2498 views
// Copyright (c) 2023 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 controllers56import (7"testing"89"github.com/gitpod-io/gitpod/ws-manager/api/config"10v1 "github.com/gitpod-io/gitpod/ws-manager/api/crd/v1"11"github.com/google/go-cmp/cmp"12corev1 "k8s.io/api/core/v1"13)1415func TestCreateWorkspaceEnvironment(t *testing.T) {16type Expectation struct {17Error string18Vars []corev1.EnvVar19}20tests := []struct {21Name string22Expectation Expectation23Context *startWorkspaceContext24}{25{26Name: "with Git config",27Context: &startWorkspaceContext{28Config: &config.Configuration{29WorkspaceClasses: map[string]*config.WorkspaceClass{30"default": {Name: "default"},31},32},33Workspace: &v1.Workspace{34Spec: v1.WorkspaceSpec{35Class: "default",36Git: &v1.GitSpec{37Username: "foobar",38Email: "[email protected]",39},40},41},42},43Expectation: Expectation{44Vars: []corev1.EnvVar{45{Name: "GITPOD_REPO_ROOT", Value: "/workspace"},46{Name: "GITPOD_REPO_ROOTS", Value: "/workspace"},47{Name: "GITPOD_THEIA_PORT", Value: "0"},48{Name: "THEIA_WORKSPACE_ROOT", Value: "/workspace"},49{Name: "GITPOD_WORKSPACE_CLASS", Value: "default"},50{Name: "THEIA_SUPERVISOR_ENDPOINT", Value: ":0"},51{Name: "THEIA_WEBVIEW_EXTERNAL_ENDPOINT", Value: "webview-{{hostname}}"},52{Name: "THEIA_MINI_BROWSER_HOST_PATTERN", Value: "browser-{{hostname}}"},53{Name: "GITPOD_GIT_USER_NAME", Value: "foobar"},54{Name: "GITPOD_GIT_USER_EMAIL", Value: "[email protected]"},55{Name: "GITPOD_INTERVAL", Value: "0"}, {Name: "GITPOD_MEMORY", Value: "0"}, {Name: "GITPOD_CPU_COUNT", Value: "0"},56},57},58},59{60Name: "without Git config",61Context: &startWorkspaceContext{62Config: &config.Configuration{63WorkspaceClasses: map[string]*config.WorkspaceClass{64"default": {Name: "default"},65},66},67Workspace: &v1.Workspace{68Spec: v1.WorkspaceSpec{69Class: "default",70},71},72},73Expectation: Expectation{74Vars: []corev1.EnvVar{75{Name: "GITPOD_REPO_ROOT", Value: "/workspace"},76{Name: "GITPOD_REPO_ROOTS", Value: "/workspace"},77{Name: "GITPOD_THEIA_PORT", Value: "0"},78{Name: "THEIA_WORKSPACE_ROOT", Value: "/workspace"},79{Name: "GITPOD_WORKSPACE_CLASS", Value: "default"},80{Name: "THEIA_SUPERVISOR_ENDPOINT", Value: ":0"},81{Name: "THEIA_WEBVIEW_EXTERNAL_ENDPOINT", Value: "webview-{{hostname}}"},82{Name: "THEIA_MINI_BROWSER_HOST_PATTERN", Value: "browser-{{hostname}}"},83{Name: "GITPOD_INTERVAL", Value: "0"}, {Name: "GITPOD_MEMORY", Value: "0"}, {Name: "GITPOD_CPU_COUNT", Value: "0"},84},85},86},87}8889for _, test := range tests {90t.Run(test.Name, func(t *testing.T) {91var act Expectation9293res, err := createWorkspaceEnvironment(test.Context)94if err != nil {95act.Error = err.Error()96}97act.Vars = res9899if diff := cmp.Diff(test.Expectation, act); diff != "" {100t.Errorf("createWorkspaceEnvironment() mismatch (-want +got):\n%s", diff)101}102})103}104}105106107