@@ -6,7 +6,7 @@ package apiv1
6
6
7
7
import (
8
8
"context"
9
- "fmt "
9
+ "errors "
10
10
"github.com/gitpod-io/gitpod/common-go/baseserver"
11
11
gitpod "github.com/gitpod-io/gitpod/gitpod-protocol"
12
12
v1 "github.com/gitpod-io/gitpod/public-api/v1"
@@ -37,24 +37,10 @@ func TestWorkspaceService_GetWorkspace(t *testing.T) {
37
37
foundWorkspaceID : {
38
38
LatestInstance : & gitpod.WorkspaceInstance {},
39
39
Workspace : & gitpod.Workspace {
40
- BaseImageNameResolved : "" ,
41
- BasedOnPrebuildID : "" ,
42
- BasedOnSnapshotID : "" ,
43
- Config : nil ,
44
- ContentDeletedTime : "" ,
45
- Context : nil ,
46
- ContextURL : contextURL ,
47
- CreationTime : "" ,
48
- Deleted : false ,
49
- Description : description ,
50
- ID : foundWorkspaceID ,
51
- ImageNameResolved : "" ,
52
- ImageSource : nil ,
53
- OwnerID : ownerID ,
54
- Pinned : false ,
55
- Shareable : false ,
56
- SoftDeleted : "" ,
57
- Type : "" ,
40
+ ContextURL : contextURL ,
41
+ Description : description ,
42
+ ID : foundWorkspaceID ,
43
+ OwnerID : ownerID ,
58
44
},
59
45
},
60
46
}},
@@ -68,39 +54,44 @@ func TestWorkspaceService_GetWorkspace(t *testing.T) {
68
54
client := v1 .NewWorkspacesServiceClient (conn )
69
55
ctx := metadata .AppendToOutgoingContext (context .Background (), "authorization" , bearerToken )
70
56
71
- scenarios := []struct {
72
- name string
57
+ type Expectation struct {
58
+ Code codes.Code
59
+ Response * v1.GetWorkspaceResponse
60
+ }
73
61
62
+ scenarios := []struct {
63
+ name string
74
64
WorkspaceID string
75
-
76
- ErrorCode codes.Code
77
- Response * v1.GetWorkspaceResponse
65
+ Expect Expectation
78
66
}{
79
67
{
80
68
name : "returns a workspace when workspace is found by ID" ,
81
69
WorkspaceID : foundWorkspaceID ,
82
- ErrorCode : codes .OK ,
83
- Response : & v1.GetWorkspaceResponse {
84
- Result : & v1.Workspace {
85
- WorkspaceId : foundWorkspaceID ,
86
- OwnerId : ownerID ,
87
- ProjectId : "" ,
88
- Context : & v1.WorkspaceContext {
89
- ContextUrl : contextURL ,
90
- Details : & v1.WorkspaceContext_Git_ {Git : & v1.WorkspaceContext_Git {
91
- NormalizedContextUrl : contextURL ,
92
- Commit : "" ,
93
- }},
70
+ Expect : Expectation {
71
+ Code : codes .OK ,
72
+ Response : & v1.GetWorkspaceResponse {
73
+ Result : & v1.Workspace {
74
+ WorkspaceId : foundWorkspaceID ,
75
+ OwnerId : ownerID ,
76
+ ProjectId : "" ,
77
+ Context : & v1.WorkspaceContext {
78
+ ContextUrl : contextURL ,
79
+ Details : & v1.WorkspaceContext_Git_ {Git : & v1.WorkspaceContext_Git {
80
+ NormalizedContextUrl : contextURL ,
81
+ Commit : "" ,
82
+ }},
83
+ },
84
+ Description : description ,
94
85
},
95
- Description : description ,
96
86
},
97
87
},
98
88
},
99
89
{
100
90
name : "not found when workspace is not found by ID" ,
101
91
WorkspaceID : "some-not-found-workspace-id" ,
102
- ErrorCode : codes .NotFound ,
103
- Response : nil ,
92
+ Expect : Expectation {
93
+ Code : codes .NotFound ,
94
+ },
104
95
},
105
96
}
106
97
@@ -109,8 +100,10 @@ func TestWorkspaceService_GetWorkspace(t *testing.T) {
109
100
resp , err := client .GetWorkspace (ctx , & v1.GetWorkspaceRequest {
110
101
WorkspaceId : scenario .WorkspaceID ,
111
102
})
112
- require .Equal (t , scenario .ErrorCode , status .Code (err ), "status code must match" )
113
- if diff := cmp .Diff (scenario .Response , resp , protocmp .Transform ()); diff != "" {
103
+ if diff := cmp .Diff (scenario .Expect , Expectation {
104
+ Code : status .Code (err ),
105
+ Response : resp ,
106
+ }, protocmp .Transform ()); diff != "" {
114
107
t .Errorf ("unexpected difference:\n %v" , diff )
115
108
}
116
109
})
@@ -153,7 +146,7 @@ type FakeGitpodAPI struct {
153
146
func (f * FakeGitpodAPI ) GetWorkspace (ctx context.Context , id string ) (res * gitpod.WorkspaceInfo , err error ) {
154
147
w , ok := f .workspaces [id ]
155
148
if ! ok {
156
- return nil , fmt . Errorf ( "workspace not found " )
149
+ return nil , errors . New ( "code 404 " )
157
150
}
158
151
159
152
return w , nil
0 commit comments