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

Add custom prefix devurl #74

Merged
merged 7 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add future support for integration devurl tests
  • Loading branch information
Russtopia committed Jul 30, 2020
commit cc55a4aa905c50facd2ecdf777c47194f1c640e0
94 changes: 94 additions & 0 deletions ci/integration/devurls_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package integration

import (
"context"
"testing"
"time"

"cdr.dev/coder-cli/ci/tcli"
"cdr.dev/slog/sloggers/slogtest/assert"
)

func TestDevURLCLI(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
defer cancel()

c, err := tcli.NewContainerRunner(ctx, &tcli.ContainerConfig{
Image: "codercom/enterprise-dev",
Name: "coder-cli-devurl-tests",
BindMounts: map[string]string{
binpath: "/bin/coder",
},
})
assert.Success(t, "new run container", err)
defer c.Close()

c.Run(ctx, "which coder").Assert(t,
tcli.Success(),
tcli.StdoutMatches("/usr/sbin/coder"),
tcli.StderrEmpty(),
)

c.Run(ctx, "coder urls ls").Assert(t,
tcli.Error(),
)

// The following cannot be enabled nor verified until either the
// integration testing dogfood target has environments created, or
// we implement the 'env create' command for coder-cli to create our
// own here.

// If we were to create an env ourselves ... we could test devurls something like

// // == Login
// headlessLogin(ctx, t, c)

// // == urls ls should fail w/o supplying an envname
// c.Run(ctx, "coder urls ls").Assert(t,
// tcli.Error(),
// )

// // == env creation should succeed
// c.Run(ctx, "coder envs create env1 --from image1 --cores 1 --ram 2gb --disk 10gb --nogpu").Assert(t,
// tcli.Success())

// // == urls ls should succeed for a newly-created environment
// var durl entclient.DevURL
// c.Run(ctx, `coder urls ls -o json`).Assert(t,
// tcli.Success(),
// jsonUnmarshals(&durl), // though if a new env, durl should be empty
// )

// // == devurl creation w/default PRIVATE access
// c.Run(ctx, `coder urls create env1 3000`).Assert(t,
// tcli.Success())

// // == devurl create w/access == AUTHED
// c.Run(ctx, `coder urls create env1 3001 --access=AUTHED`).Assert(t,
// tcli.Success())

// // == devurl create with name
// c.Run(ctx, `coder urls create env1 3002 --access=PUBLIC --name=foobar`).Assert(t,
// tcli.Success())

// // == devurl ls should return well-formed entries incl. one with AUTHED access
// c.Run(ctx, `coder urls ls env1 -o json | jq -c '.[] | select( .access == "AUTHED")'`).Assert(t,
// tcli.Success(),
// jsonUnmarshals(&durl))

// // == devurl ls should return well-formed entries incl. one with name 'foobar'
// c.Run(ctx, `coder urls ls env1 -o json | jq -c '.[] | select( .name == "foobar")'`).Assert(t,
// tcli.Success(),
// jsonUnmarshals(&durl))

// // == devurl del should function
// c.Run(ctx, `coder urls del env1 3002`).Assert(t,
// tcli.Success())

// // == removed devurl should no longer be there
// c.Run(ctx, `coder urls ls env1 -o json | jq -c '.[] | select( .name == "foobar")'`).Assert(t,
// tcli.Error(),
// jsonUnmarshals(&durl))

}
1 change: 1 addition & 0 deletions cmd/coder/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type DevURL struct {
URL string `json:"url"`
Port int `json:"port"`
Access string `json:"access"`
Name string `json:"name"`
}

var urlAccessLevel = map[string]string{
Expand Down
16 changes: 10 additions & 6 deletions internal/entclient/devurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import (
"net/http"
)

// DevURL is the parsed json response record for a devURL from cemanager
type DevURL struct {
ID string `json:"id"`
URL string `json:"url"`
Port int `json:"port"`
Access string `json:"access"`
Name string `json:"name"`
}

type delDevURLRequest struct {
EnvID string `json:"environment_id"`
DevURLID string `json:"url_id"`
Expand Down Expand Up @@ -61,12 +70,7 @@ func (c Client) InsertDevURL(envID string, port int, name, access string) error
return nil
}

type updateDevURLRequest struct {
EnvID string `json:"environment_id"`
Port int `json:"port"`
Access string `json:"access"`
Name string `json:"name"`
}
type updateDevURLRequest createDevURLRequest

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