Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit cc55a4a

Browse files
author
Russtopia
committed
Add future support for integration devurl tests
1 parent c71c3c9 commit cc55a4a

File tree

3 files changed

+105
-6
lines changed

3 files changed

+105
-6
lines changed

ci/integration/devurls_test.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package integration
2+
3+
import (
4+
"context"
5+
"testing"
6+
"time"
7+
8+
"cdr.dev/coder-cli/ci/tcli"
9+
"cdr.dev/slog/sloggers/slogtest/assert"
10+
)
11+
12+
func TestDevURLCLI(t *testing.T) {
13+
t.Parallel()
14+
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
15+
defer cancel()
16+
17+
c, err := tcli.NewContainerRunner(ctx, &tcli.ContainerConfig{
18+
Image: "codercom/enterprise-dev",
19+
Name: "coder-cli-devurl-tests",
20+
BindMounts: map[string]string{
21+
binpath: "/bin/coder",
22+
},
23+
})
24+
assert.Success(t, "new run container", err)
25+
defer c.Close()
26+
27+
c.Run(ctx, "which coder").Assert(t,
28+
tcli.Success(),
29+
tcli.StdoutMatches("/usr/sbin/coder"),
30+
tcli.StderrEmpty(),
31+
)
32+
33+
c.Run(ctx, "coder urls ls").Assert(t,
34+
tcli.Error(),
35+
)
36+
37+
// The following cannot be enabled nor verified until either the
38+
// integration testing dogfood target has environments created, or
39+
// we implement the 'env create' command for coder-cli to create our
40+
// own here.
41+
42+
// If we were to create an env ourselves ... we could test devurls something like
43+
44+
// // == Login
45+
// headlessLogin(ctx, t, c)
46+
47+
// // == urls ls should fail w/o supplying an envname
48+
// c.Run(ctx, "coder urls ls").Assert(t,
49+
// tcli.Error(),
50+
// )
51+
52+
// // == env creation should succeed
53+
// c.Run(ctx, "coder envs create env1 --from image1 --cores 1 --ram 2gb --disk 10gb --nogpu").Assert(t,
54+
// tcli.Success())
55+
56+
// // == urls ls should succeed for a newly-created environment
57+
// var durl entclient.DevURL
58+
// c.Run(ctx, `coder urls ls -o json`).Assert(t,
59+
// tcli.Success(),
60+
// jsonUnmarshals(&durl), // though if a new env, durl should be empty
61+
// )
62+
63+
// // == devurl creation w/default PRIVATE access
64+
// c.Run(ctx, `coder urls create env1 3000`).Assert(t,
65+
// tcli.Success())
66+
67+
// // == devurl create w/access == AUTHED
68+
// c.Run(ctx, `coder urls create env1 3001 --access=AUTHED`).Assert(t,
69+
// tcli.Success())
70+
71+
// // == devurl create with name
72+
// c.Run(ctx, `coder urls create env1 3002 --access=PUBLIC --name=foobar`).Assert(t,
73+
// tcli.Success())
74+
75+
// // == devurl ls should return well-formed entries incl. one with AUTHED access
76+
// c.Run(ctx, `coder urls ls env1 -o json | jq -c '.[] | select( .access == "AUTHED")'`).Assert(t,
77+
// tcli.Success(),
78+
// jsonUnmarshals(&durl))
79+
80+
// // == devurl ls should return well-formed entries incl. one with name 'foobar'
81+
// c.Run(ctx, `coder urls ls env1 -o json | jq -c '.[] | select( .name == "foobar")'`).Assert(t,
82+
// tcli.Success(),
83+
// jsonUnmarshals(&durl))
84+
85+
// // == devurl del should function
86+
// c.Run(ctx, `coder urls del env1 3002`).Assert(t,
87+
// tcli.Success())
88+
89+
// // == removed devurl should no longer be there
90+
// c.Run(ctx, `coder urls ls env1 -o json | jq -c '.[] | select( .name == "foobar")'`).Assert(t,
91+
// tcli.Error(),
92+
// jsonUnmarshals(&durl))
93+
94+
}

cmd/coder/urls.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type DevURL struct {
4444
URL string `json:"url"`
4545
Port int `json:"port"`
4646
Access string `json:"access"`
47+
Name string `json:"name"`
4748
}
4849

4950
var urlAccessLevel = map[string]string{

internal/entclient/devurl.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ import (
55
"net/http"
66
)
77

8+
// DevURL is the parsed json response record for a devURL from cemanager
9+
type DevURL struct {
10+
ID string `json:"id"`
11+
URL string `json:"url"`
12+
Port int `json:"port"`
13+
Access string `json:"access"`
14+
Name string `json:"name"`
15+
}
16+
817
type delDevURLRequest struct {
918
EnvID string `json:"environment_id"`
1019
DevURLID string `json:"url_id"`
@@ -61,12 +70,7 @@ func (c Client) InsertDevURL(envID string, port int, name, access string) error
6170
return nil
6271
}
6372

64-
type updateDevURLRequest struct {
65-
EnvID string `json:"environment_id"`
66-
Port int `json:"port"`
67-
Access string `json:"access"`
68-
Name string `json:"name"`
69-
}
73+
type updateDevURLRequest createDevURLRequest
7074

7175
// UpdateDevURL updates an existing devurl for the authenticated user
7276
func (c Client) UpdateDevURL(envID, urlID string, port int, name, access string) error {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy