Path: blob/main/components/ws-manager-mk2/service/manager_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 service56import (7"context"8"testing"910"github.com/gitpod-io/gitpod/ws-manager/api"11"github.com/gitpod-io/gitpod/ws-manager/api/config"12"github.com/google/go-cmp/cmp"13"github.com/google/go-cmp/cmp/cmpopts"14)1516func TestDescribeCluster(t *testing.T) {17type Expectation struct {18Error string19Response *api.DescribeClusterResponse20}21tests := []struct {22Name string23Expectation Expectation24Config config.Configuration25}{26{27Name: "empty config",28Expectation: Expectation{Response: &api.DescribeClusterResponse{WorkspaceClasses: []*api.WorkspaceClass{}}},29},30{31Name: "preferred class",32Config: config.Configuration{33WorkspaceClasses: map[string]*config.WorkspaceClass{34"default": {35Name: "Default Workspace",36CreditsPerMinute: 0.4,37Container: config.ContainerConfiguration{38Limits: &config.ResourceLimitConfiguration{39CPU: &config.CpuResourceLimit{BurstLimit: "10"},40Memory: "15G",41Storage: "20G",42},43},44},45},46PreferredWorkspaceClass: "default",47},48Expectation: Expectation{49Response: &api.DescribeClusterResponse{50PreferredWorkspaceClass: "default",51WorkspaceClasses: []*api.WorkspaceClass{52{Id: "default", DisplayName: "Default Workspace", Description: "10 vCPU, 15GB memory, 20GB disk", CreditsPerMinute: 0.4},53},54},55},56},57{58Name: "multiple classes",59Config: config.Configuration{60WorkspaceClasses: map[string]*config.WorkspaceClass{61"xlarge": {},62"large": {},63},64},65Expectation: Expectation{66Response: &api.DescribeClusterResponse{67WorkspaceClasses: []*api.WorkspaceClass{68{Id: "large", Description: "0 vCPU, 0GB memory, 0GB disk"},69{Id: "xlarge", Description: "0 vCPU, 0GB memory, 0GB disk"},70},71},72},73},74}7576for _, test := range tests {77t.Run(test.Name, func(t *testing.T) {78var act Expectation7980srv := WorkspaceManagerServer{Config: &test.Config}81resp, err := srv.DescribeCluster(context.Background(), &api.DescribeClusterRequest{})82if err != nil {83act.Error = err.Error()84}85if resp != nil {86act.Response = resp87}8889if diff := cmp.Diff(test.Expectation, act, cmpopts.IgnoreUnexported(api.DescribeClusterResponse{}, api.WorkspaceClass{})); diff != "" {90t.Errorf("DescribeCluster() mismatch (-want +got):\n%s", diff)91}92})93}94}959697