Skip to content

Commit 6141beb

Browse files
committed
[ws-manager-mk2] Add fixture tests
1 parent 39a21b4 commit 6141beb

File tree

7 files changed

+72
-0
lines changed

7 files changed

+72
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2022 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 controllers
6+
7+
import (
8+
"context"
9+
"testing"
10+
11+
ctesting "github.com/gitpod-io/gitpod/common-go/testing"
12+
workspacev1 "github.com/gitpod-io/gitpod/ws-manager/api/crd/v1"
13+
corev1 "k8s.io/api/core/v1"
14+
)
15+
16+
func TestUpdateWorkspaceStatus(t *testing.T) {
17+
type fixture struct {
18+
Pods corev1.PodList `json:"pods"`
19+
Status *workspacev1.WorkspaceStatus `json:"status,omitempty"`
20+
}
21+
type gold struct {
22+
Error string `json:"error,omitempty"`
23+
Status *workspacev1.WorkspaceStatus `json:"status,omitempty"`
24+
}
25+
26+
test := ctesting.FixtureTest{
27+
T: t,
28+
Path: "testdata/status_*.json",
29+
Fixture: func() interface{} { return &fixture{} },
30+
Gold: func() interface{} { return &gold{} },
31+
Test: func(t *testing.T, input interface{}) interface{} {
32+
fixture := input.(*fixture)
33+
34+
var res workspacev1.Workspace
35+
if fixture.Status != nil {
36+
res.Status = *fixture.Status
37+
}
38+
err := updateWorkspaceStatus(context.Background(), &res, fixture.Pods)
39+
if err != nil {
40+
return &gold{Error: err.Error()}
41+
}
42+
43+
return &gold{
44+
Status: &res.Status,
45+
}
46+
},
47+
}
48+
test.Run()
49+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"status": {
3+
"podStarts": 0,
4+
"headless": false,
5+
"conditions": {
6+
"failed": "multiple pods exists - this should never happen"
7+
}
8+
}
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"pods": {"items": [{}, {}, {}]}
3+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"status": {
3+
"podStarts": 0,
4+
"headless": false,
5+
"phase": "stopped",
6+
"conditions": {}
7+
}
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

components/ws-manager-mk2/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ require (
4646
github.com/fsnotify/fsnotify v1.5.1 // indirect
4747
github.com/go-logr/logr v1.2.0 // indirect
4848
github.com/go-logr/zapr v1.2.0 // indirect
49+
github.com/go-test/deep v1.0.5 // indirect
4950
github.com/gogo/protobuf v1.3.2 // indirect
5051
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
5152
github.com/golang/protobuf v1.5.2 // indirect

components/ws-manager-mk2/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ github.com/go-ozzo/ozzo-validation v3.6.0+incompatible h1:msy24VGS42fKO9K1vLz82/
188188
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible/go.mod h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU=
189189
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
190190
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
191+
github.com/go-test/deep v1.0.5 h1:AKODKU3pDH1RzZzm6YZu77YWtEAq6uh1rLIAQlay2qc=
191192
github.com/go-test/deep v1.0.5/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8=
192193
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
193194
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=

0 commit comments

Comments
 (0)