-
Notifications
You must be signed in to change notification settings - Fork 960
feat: coder-attach: add support for external workspaces #19178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
3ea541e
4818df1
4bfdb83
1044051
fd2458b
0c39f50
23e555a
f9f5be1
e281f0e
d77522d
451c806
f9274fe
00b6f26
c019a31
7d07857
c462a69
2d2dfec
387fc04
c2588ea
33dd778
c413479
3c1d694
73acd0f
7cc6861
da68c20
2e24741
682ea60
51967a5
f060324
ff6e8fa
e2a7182
141bc54
a75c1f4
22f2c00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package coderd_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/coder/coder/v2/coderd/coderdtest" | ||
) | ||
|
||
func TestInitScript(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("OK", func(t *testing.T) { | ||
t.Parallel() | ||
client := coderdtest.New(t, nil) | ||
script, err := client.InitScript(context.Background(), "windows", "amd64") | ||
require.NoError(t, err) | ||
require.NotEmpty(t, script) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should test the replacements as well, probably search for substrings like |
||
}) | ||
|
||
t.Run("BadRequest", func(t *testing.T) { | ||
t.Parallel() | ||
client := coderdtest.New(t, nil) | ||
_, err := client.InitScript(context.Background(), "darwin", "armv7") | ||
require.Error(t, err) | ||
fmt.Printf("err: %+v\n", err) | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package codersdk | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This file should probably be renamed just |
||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
) | ||
|
||
func (c *Client) InitScript(ctx context.Context, os, arch string) (string, error) { | ||
url := fmt.Sprintf("/api/v2/init-script/%s/%s", os, arch) | ||
res, err := c.Request(ctx, http.MethodGet, url, nil) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer res.Body.Close() | ||
|
||
if res.StatusCode != http.StatusOK { | ||
return "", ReadBodyAsError(res) | ||
} | ||
|
||
script, err := io.ReadAll(res.Body) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return string(script), nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably write a message here too, using
httpapi.Write(..., codersdk.Response{})
is probably fine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unknown os/arch: %s/%s