Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita593520

Browse files
committed
Add unit test for moons
1 parent4b5e219 commita593520

File tree

7 files changed

+109
-6
lines changed

7 files changed

+109
-6
lines changed

‎coderd/database/dbauthz/querier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ func (q *querier) GetWorkspaceByWorkspaceAppID(ctx context.Context, workspaceApp
16481648
}
16491649

16501650
func (q*querier)GetWorkspaceProxies(ctx context.Context,organizationID uuid.UUID) ([]database.WorkspaceProxy,error) {
1651-
returnfetchWithPostFilter(q.auth,q.GetWorkspaceProxies)(ctx,organizationID)
1651+
returnfetchWithPostFilter(q.auth,q.db.GetWorkspaceProxies)(ctx,organizationID)
16521652
}
16531653

16541654
func (q*querier)GetWorkspaceProxyByID(ctx context.Context,id uuid.UUID) (database.WorkspaceProxy,error) {

‎codersdk/deployment.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const (
4545
FeatureExternalProvisionerDaemonsFeatureName="external_provisioner_daemons"
4646
FeatureAppearanceFeatureName="appearance"
4747
FeatureAdvancedTemplateSchedulingFeatureName="advanced_template_scheduling"
48+
FeatureWorkspaceProxyFeatureName="workspace_proxy"
4849
)
4950

5051
// FeatureNames must be kept in-sync with the Feature enum above.
@@ -59,6 +60,7 @@ var FeatureNames = []FeatureName{
5960
FeatureExternalProvisionerDaemons,
6061
FeatureAppearance,
6162
FeatureAdvancedTemplateScheduling,
63+
FeatureWorkspaceProxy,
6264
}
6365

6466
// Humanize returns the feature name in a human-readable format.

‎codersdk/workspaceproxy.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
package codersdk
22

33
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"net/http"
48
"time"
59

10+
"golang.org/x/xerrors"
11+
612
"github.com/google/uuid"
713
)
814

@@ -26,3 +32,38 @@ type WorkspaceProxy struct {
2632
UpdatedAt time.Time`db:"updated_at" json:"updated_at"`
2733
Deletedbool`db:"deleted" json:"deleted"`
2834
}
35+
36+
func (c*Client)CreateWorkspaceProxy(ctx context.Context,orgID uuid.UUID,reqCreateWorkspaceProxyRequest) (WorkspaceProxy,error) {
37+
res,err:=c.Request(ctx,http.MethodPost,
38+
fmt.Sprintf("/api/v2/organizations/%s/workspaceproxies",orgID.String()),
39+
req,
40+
)
41+
iferr!=nil {
42+
returnWorkspaceProxy{},xerrors.Errorf("make request: %w",err)
43+
}
44+
deferres.Body.Close()
45+
46+
ifres.StatusCode!=http.StatusCreated {
47+
returnWorkspaceProxy{},ReadBodyAsError(res)
48+
}
49+
varrespWorkspaceProxy
50+
returnresp,json.NewDecoder(res.Body).Decode(&resp)
51+
}
52+
53+
func (c*Client)WorkspaceProxiesByOrganization(ctx context.Context,orgID uuid.UUID) ([]WorkspaceProxy,error) {
54+
res,err:=c.Request(ctx,http.MethodGet,
55+
fmt.Sprintf("/api/v2/organizations/%s/workspaceproxies",orgID.String()),
56+
nil,
57+
)
58+
iferr!=nil {
59+
returnnil,xerrors.Errorf("make request: %w",err)
60+
}
61+
deferres.Body.Close()
62+
63+
ifres.StatusCode!=http.StatusOK {
64+
returnnil,ReadBodyAsError(res)
65+
}
66+
67+
varproxies []WorkspaceProxy
68+
returnproxies,json.NewDecoder(res.Body).Decode(&proxies)
69+
}

‎enterprise/coderd/coderd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func New(ctx context.Context, options *Options) (*API, error) {
8181
r.Get("/",api.licenses)
8282
r.Delete("/{id}",api.deleteLicense)
8383
})
84-
r.Route("/organizations/{organization}/workspaceproxys",func(r chi.Router) {
84+
r.Route("/organizations/{organization}/workspaceproxies",func(r chi.Router) {
8585
r.Use(
8686
apiKeyMiddleware,
8787
api.moonsEnabledMW,
@@ -271,6 +271,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {
271271
codersdk.FeatureTemplateRBAC:api.RBAC,
272272
codersdk.FeatureExternalProvisionerDaemons:true,
273273
codersdk.FeatureAdvancedTemplateScheduling:true,
274+
codersdk.FeatureWorkspaceProxy:true,
274275
})
275276
iferr!=nil {
276277
returnerr

‎enterprise/coderd/templates.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,21 @@ func (api *API) templateRBACEnabledMW(next http.Handler) http.Handler {
282282

283283
func (api*API)moonsEnabledMW(next http.Handler) http.Handler {
284284
returnhttp.HandlerFunc(func(rw http.ResponseWriter,r*http.Request) {
285+
// The experiment must be enabled.
285286
if!api.AGPL.Experiments.Enabled(codersdk.ExperimentMoons) {
286287
httpapi.RouteNotFound(rw)
287288
return
288289
}
290+
291+
// Entitlement must be enabled.
292+
api.entitlementsMu.RLock()
293+
proxy:=api.entitlements.Features[codersdk.FeatureWorkspaceProxy].Enabled
294+
api.entitlementsMu.RUnlock()
295+
if!proxy {
296+
httpapi.RouteNotFound(rw)
297+
return
298+
}
299+
289300
next.ServeHTTP(rw,r)
290301
})
291302
}

‎enterprise/coderd/workspaceproxy.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
// @Param request body codersdk.CreateWorkspaceProxyRequest true "Create workspace proxy request"
2525
// @Param organization path string true "Organization ID"
2626
// @Success 201 {object} codersdk.WorkspaceProxy
27-
// @Router /organizations/{organization}/workspaceproxys [post]
27+
// @Router /organizations/{organization}/workspaceproxies [post]
2828
func (api*API)postWorkspaceProxyByOrganization(rw http.ResponseWriter,r*http.Request) {
2929
var (
3030
ctx=r.Context()
@@ -77,7 +77,7 @@ func (api *API) postWorkspaceProxyByOrganization(rw http.ResponseWriter, r *http
7777
// @Tags Enterprise
7878
// @Param organization path string true "Organization ID" format(uuid)
7979
// @Success 200 {array} codersdk.WorkspaceProxy
80-
// @Router /organizations/{organization}/workspaceproxys [get]
80+
// @Router /organizations/{organization}/workspaceproxies [get]
8181
func (api*API)workspaceProxiesByOrganization(rw http.ResponseWriter,r*http.Request) {
8282
var (
8383
ctx=r.Context()
@@ -93,8 +93,6 @@ func (api *API) workspaceProxiesByOrganization(rw http.ResponseWriter, r *http.R
9393
httpapi.Write(ctx,rw,http.StatusOK,convertProxies(proxies))
9494
}
9595

96-
97-
9896
funcconvertProxies(p []database.WorkspaceProxy) []codersdk.WorkspaceProxy {
9997
resp:=make([]codersdk.WorkspaceProxy,0,len(p))
10098
for_,proxy:=rangep {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package coderd_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/moby/moby/pkg/namesgenerator"
7+
8+
"github.com/coder/coder/coderd/coderdtest"
9+
"github.com/coder/coder/codersdk"
10+
"github.com/coder/coder/enterprise/coderd/coderdenttest"
11+
"github.com/coder/coder/enterprise/coderd/license"
12+
"github.com/coder/coder/testutil"
13+
"github.com/stretchr/testify/require"
14+
)
15+
16+
funcTestWorkspaceProxyCRUD(t*testing.T) {
17+
t.Parallel()
18+
19+
t.Run("create",func(t*testing.T) {
20+
dv:=coderdtest.DeploymentValues(t)
21+
dv.Experiments= []string{
22+
string(codersdk.ExperimentMoons),
23+
"*",
24+
}
25+
client:=coderdenttest.New(t,&coderdenttest.Options{
26+
Options:&coderdtest.Options{
27+
DeploymentValues:dv,
28+
},
29+
})
30+
user:=coderdtest.CreateFirstUser(t,client)
31+
_=coderdenttest.AddLicense(t,client, coderdenttest.LicenseOptions{
32+
Features: license.Features{
33+
codersdk.FeatureWorkspaceProxy:1,
34+
},
35+
})
36+
ctx:=testutil.Context(t,testutil.WaitLong)
37+
proxy,err:=client.CreateWorkspaceProxy(ctx,user.OrganizationID, codersdk.CreateWorkspaceProxyRequest{
38+
Name:namesgenerator.GetRandomName(1),
39+
Icon:"/emojis/flag.png",
40+
URL:"https://"+namesgenerator.GetRandomName(1)+".com",
41+
WildcardURL:"https://*."+namesgenerator.GetRandomName(1)+".com",
42+
})
43+
require.NoError(t,err)
44+
45+
proxies,err:=client.WorkspaceProxiesByOrganization(ctx,user.OrganizationID)
46+
require.NoError(t,err)
47+
require.Len(t,proxies,1)
48+
require.Equal(t,proxy,proxies[0])
49+
})
50+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp