feat: Add "coder" CLI (#221)

* feat: Add "coder" CLI

* Add CLI test for login

* Add "bin/coder" target to Makefile

* Update promptui to fix race

* Fix error scope

* Don't run CLI tests on Windows

* Fix requested changes
This commit is contained in:
Kyle Carberry
2022-02-10 08:33:27 -06:00
committed by GitHub
parent 277318bdb4
commit 07fe5ced68
24 changed files with 921 additions and 7 deletions
+17
View File
@@ -9,6 +9,23 @@ import (
"github.com/coder/coder/coderd"
)
// HasInitialUser returns whether the initial user has already been
// created or not.
func (c *Client) HasInitialUser(ctx context.Context) (bool, error) {
res, err := c.request(ctx, http.MethodGet, "/api/v2/user", nil)
if err != nil {
return false, err
}
defer res.Body.Close()
if res.StatusCode == http.StatusNotFound {
return false, nil
}
if res.StatusCode != http.StatusOK {
return false, readBodyAsError(res)
}
return true, nil
}
// CreateInitialUser attempts to create the first user on a Coder deployment.
// This initial user has superadmin privileges. If >0 users exist, this request
// will fail.
+20
View File
@@ -10,6 +10,26 @@ import (
"github.com/coder/coder/coderd/coderdtest"
)
func TestHasInitialUser(t *testing.T) {
t.Parallel()
t.Run("NotFound", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t)
has, err := client.HasInitialUser(context.Background())
require.NoError(t, err)
require.False(t, has)
})
t.Run("Found", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t)
_ = coderdtest.CreateInitialUser(t, client)
has, err := client.HasInitialUser(context.Background())
require.NoError(t, err)
require.True(t, has)
})
}
func TestCreateInitialUser(t *testing.T) {
t.Parallel()
t.Run("Error", func(t *testing.T) {