Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ws-manager-mk2/service/manager_test.go
2498 views
1
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package service
6
7
import (
8
"context"
9
"testing"
10
11
"github.com/gitpod-io/gitpod/ws-manager/api"
12
"github.com/gitpod-io/gitpod/ws-manager/api/config"
13
"github.com/google/go-cmp/cmp"
14
"github.com/google/go-cmp/cmp/cmpopts"
15
)
16
17
func TestDescribeCluster(t *testing.T) {
18
type Expectation struct {
19
Error string
20
Response *api.DescribeClusterResponse
21
}
22
tests := []struct {
23
Name string
24
Expectation Expectation
25
Config config.Configuration
26
}{
27
{
28
Name: "empty config",
29
Expectation: Expectation{Response: &api.DescribeClusterResponse{WorkspaceClasses: []*api.WorkspaceClass{}}},
30
},
31
{
32
Name: "preferred class",
33
Config: config.Configuration{
34
WorkspaceClasses: map[string]*config.WorkspaceClass{
35
"default": {
36
Name: "Default Workspace",
37
CreditsPerMinute: 0.4,
38
Container: config.ContainerConfiguration{
39
Limits: &config.ResourceLimitConfiguration{
40
CPU: &config.CpuResourceLimit{BurstLimit: "10"},
41
Memory: "15G",
42
Storage: "20G",
43
},
44
},
45
},
46
},
47
PreferredWorkspaceClass: "default",
48
},
49
Expectation: Expectation{
50
Response: &api.DescribeClusterResponse{
51
PreferredWorkspaceClass: "default",
52
WorkspaceClasses: []*api.WorkspaceClass{
53
{Id: "default", DisplayName: "Default Workspace", Description: "10 vCPU, 15GB memory, 20GB disk", CreditsPerMinute: 0.4},
54
},
55
},
56
},
57
},
58
{
59
Name: "multiple classes",
60
Config: config.Configuration{
61
WorkspaceClasses: map[string]*config.WorkspaceClass{
62
"xlarge": {},
63
"large": {},
64
},
65
},
66
Expectation: Expectation{
67
Response: &api.DescribeClusterResponse{
68
WorkspaceClasses: []*api.WorkspaceClass{
69
{Id: "large", Description: "0 vCPU, 0GB memory, 0GB disk"},
70
{Id: "xlarge", Description: "0 vCPU, 0GB memory, 0GB disk"},
71
},
72
},
73
},
74
},
75
}
76
77
for _, test := range tests {
78
t.Run(test.Name, func(t *testing.T) {
79
var act Expectation
80
81
srv := WorkspaceManagerServer{Config: &test.Config}
82
resp, err := srv.DescribeCluster(context.Background(), &api.DescribeClusterRequest{})
83
if err != nil {
84
act.Error = err.Error()
85
}
86
if resp != nil {
87
act.Response = resp
88
}
89
90
if diff := cmp.Diff(test.Expectation, act, cmpopts.IgnoreUnexported(api.DescribeClusterResponse{}, api.WorkspaceClass{})); diff != "" {
91
t.Errorf("DescribeCluster() mismatch (-want +got):\n%s", diff)
92
}
93
})
94
}
95
}
96
97