Skip to content

Commit fe66e57

Browse files
committed
Add unit test
1 parent 94e38e8 commit fe66e57

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

codersdk/workspaceproxy.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ type ProxyHealthReport struct {
4646
}
4747

4848
type WorkspaceProxy struct {
49-
ID uuid.UUID `json:"id" format:"uuid" table:"id"`
50-
Name string `json:"name" table:"name,default_sort"`
51-
Icon string `json:"icon" table:"icon"`
49+
ID uuid.UUID `json:"id" format:"uuid" table:"id"`
50+
Name string `json:"name" table:"name,default_sort"`
51+
DisplayName string `json:"display_name" table:"display_name""`
52+
Icon string `json:"icon" table:"icon"`
5253
// Full url including scheme of the proxy api url: https://us.example.com
5354
URL string `json:"url" table:"url"`
5455
// WildcardHostname with the wildcard for subdomain based app hosting: *.us.example.com
@@ -127,14 +128,14 @@ type PatchWorkspaceProxyResponse struct {
127128
func (c *Client) PatchWorkspaceProxy(ctx context.Context, req PatchWorkspaceProxy) (WorkspaceProxy, error) {
128129
res, err := c.Request(ctx, http.MethodPatch,
129130
fmt.Sprintf("/api/v2/workspaceproxies/%s", req.ID.String()),
130-
nil,
131+
req,
131132
)
132133
if err != nil {
133134
return WorkspaceProxy{}, xerrors.Errorf("make request: %w", err)
134135
}
135136
defer res.Body.Close()
136137

137-
if res.StatusCode != http.StatusCreated {
138+
if res.StatusCode != http.StatusOK {
138139
return WorkspaceProxy{}, ReadBodyAsError(res)
139140
}
140141
var resp WorkspaceProxy

enterprise/coderd/workspaceproxy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ func convertProxy(p database.WorkspaceProxy, status proxyhealth.ProxyStatus) cod
576576
return codersdk.WorkspaceProxy{
577577
ID: p.ID,
578578
Name: p.Name,
579+
DisplayName: p.DisplayName,
579580
Icon: p.Icon,
580581
URL: p.Url,
581582
WildcardHostname: p.WildcardHostname,

enterprise/coderd/workspaceproxy_test.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func TestRegions(t *testing.T) {
177177
func TestWorkspaceProxyCRUD(t *testing.T) {
178178
t.Parallel()
179179

180-
t.Run("create", func(t *testing.T) {
180+
t.Run("CreateAndUpdate", func(t *testing.T) {
181181
t.Parallel()
182182

183183
dv := coderdtest.DeploymentValues(t)
@@ -203,14 +203,33 @@ func TestWorkspaceProxyCRUD(t *testing.T) {
203203
})
204204
require.NoError(t, err)
205205

206-
proxies, err := client.WorkspaceProxies(ctx)
206+
found, err := client.WorkspaceProxyByID(ctx, proxyRes.Proxy.ID)
207207
require.NoError(t, err)
208-
require.Len(t, proxies, 1)
209-
require.Equal(t, proxyRes.Proxy.ID, proxies[0].ID)
208+
// This will be different, so set it to the same
209+
found.Status = proxyRes.Proxy.Status
210+
require.Equal(t, proxyRes.Proxy, found, "expected proxy")
210211
require.NotEmpty(t, proxyRes.ProxyToken)
212+
213+
// Update the proxy
214+
expName := namesgenerator.GetRandomName(1)
215+
expDisplayName := namesgenerator.GetRandomName(1)
216+
expIcon := namesgenerator.GetRandomName(1)
217+
_, err = client.PatchWorkspaceProxy(ctx, codersdk.PatchWorkspaceProxy{
218+
ID: proxyRes.Proxy.ID,
219+
Name: expName,
220+
DisplayName: expDisplayName,
221+
Icon: expIcon,
222+
})
223+
require.NoError(t, err, "expected no error updating proxy")
224+
225+
found, err = client.WorkspaceProxyByID(ctx, proxyRes.Proxy.ID)
226+
require.NoError(t, err)
227+
require.Equal(t, expName, found.Name, "name")
228+
require.Equal(t, expDisplayName, found.DisplayName, "display name")
229+
require.Equal(t, expIcon, found.Icon, "icon")
211230
})
212231

213-
t.Run("delete", func(t *testing.T) {
232+
t.Run("Delete", func(t *testing.T) {
214233
t.Parallel()
215234

216235
dv := coderdtest.DeploymentValues(t)

0 commit comments

Comments
 (0)