Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a633886

Browse files
committed
Merge branch 'main' into bryphe/chore/jest-tests
2 parents dc6f16b + afc2fa3 commit a633886

File tree

11 files changed

+326
-32
lines changed

11 files changed

+326
-32
lines changed

.github/workflows/coder.yaml

+11-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ jobs:
129129

130130
- run:
131131
gotestsum --jsonfile="gotests.json" --packages="./..." --
132-
-covermode=atomic -coverprofile="gotests.coverage" -timeout=1m
132+
-covermode=atomic -coverprofile="gotests.coverage" -timeout=3m
133+
-count=3 -race
133134

134135
- uses: codecov/codecov-action@v2
135136
with:
@@ -144,6 +145,15 @@ jobs:
144145
steps:
145146
- uses: actions/checkout@v2
146147

148+
- name: Cache Node
149+
id: cache-node
150+
uses: actions/cache@v2
151+
with:
152+
path: |
153+
**/node_modules
154+
.eslintcache
155+
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
156+
147157
- uses: actions/setup-node@v2
148158
with:
149159
node-version: "14"

cmd/coderd/main.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/coder/coder/coderd/cmd"
8+
)
9+
10+
func main() {
11+
err := cmd.Root().Execute()
12+
if err != nil {
13+
_, _ = fmt.Println(err.Error())
14+
os.Exit(1)
15+
}
16+
}

coderd/cmd/root.go

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package cmd
2+
3+
import (
4+
"net"
5+
"net/http"
6+
"os"
7+
8+
"cdr.dev/slog"
9+
"cdr.dev/slog/sloggers/sloghuman"
10+
"github.com/coder/coder/coderd"
11+
"github.com/coder/coder/database"
12+
"github.com/spf13/cobra"
13+
"golang.org/x/xerrors"
14+
)
15+
16+
func Root() *cobra.Command {
17+
var (
18+
address string
19+
)
20+
root := &cobra.Command{
21+
Use: "coderd",
22+
RunE: func(cmd *cobra.Command, args []string) error {
23+
handler := coderd.New(&coderd.Options{
24+
Logger: slog.Make(sloghuman.Sink(os.Stderr)),
25+
Database: database.NewInMemory(),
26+
})
27+
28+
listener, err := net.Listen("tcp", address)
29+
if err != nil {
30+
return xerrors.Errorf("listen %q: %w", address, err)
31+
}
32+
defer listener.Close()
33+
34+
errCh := make(chan error)
35+
go func() {
36+
defer close(errCh)
37+
errCh <- http.Serve(listener, handler)
38+
}()
39+
40+
select {
41+
case <-cmd.Context().Done():
42+
return cmd.Context().Err()
43+
case err := <-errCh:
44+
return err
45+
}
46+
},
47+
}
48+
defaultAddress, ok := os.LookupEnv("ADDRESS")
49+
if !ok {
50+
defaultAddress = "127.0.0.1:3000"
51+
}
52+
root.Flags().StringVarP(&address, "address", "a", defaultAddress, "The address to serve the API and dashboard.")
53+
54+
return root
55+
}

coderd/cmd/root_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cmd_test
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/coder/coder/coderd/cmd"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestRoot(t *testing.T) {
12+
ctx, cancelFunc := context.WithCancel(context.Background())
13+
go cancelFunc()
14+
err := cmd.Root().ExecuteContext(ctx)
15+
require.ErrorIs(t, err, context.Canceled)
16+
}

coderd/coderd.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package coderd
2+
3+
import (
4+
"net/http"
5+
6+
"cdr.dev/slog"
7+
"github.com/coder/coder/database"
8+
"github.com/go-chi/chi"
9+
"github.com/go-chi/render"
10+
)
11+
12+
// Options are requires parameters for Coder to start.
13+
type Options struct {
14+
Logger slog.Logger
15+
Database database.Store
16+
}
17+
18+
// New constructs the Coder API into an HTTP handler.
19+
func New(options *Options) http.Handler {
20+
r := chi.NewRouter()
21+
r.Route("/api/v2", func(r chi.Router) {
22+
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
23+
render.JSON(w, r, struct {
24+
Message string `json:"message"`
25+
}{
26+
Message: "👋",
27+
})
28+
})
29+
})
30+
return r
31+
}

database/migrations/000001_base.up.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ CREATE TABLE IF NOT EXISTS api_keys (
8585
devurl_token boolean DEFAULT false NOT NULL
8686
);
8787

88-
CREATE TABLE licenses (
88+
CREATE TABLE IF NOT EXISTS licenses (
8989
id integer NOT NULL,
9090
license jsonb NOT NULL,
9191
created_at timestamp with time zone NOT NULL

go.mod

+18-10
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ go 1.17
55
// Required until https://github.com/hashicorp/terraform-config-inspect/pull/74 is merged.
66
replace github.com/hashicorp/terraform-config-inspect => github.com/kylecarbs/terraform-config-inspect v0.0.0-20211215004401-bbc517866b88
77

8+
// Required until https://github.com/pion/ice/pull/411 is merged.
9+
replace github.com/pion/ice/v2 => github.com/kylecarbs/ice/v2 v2.1.8-0.20220113224934-e3297ead83b2
10+
811
require (
912
cdr.dev/slog v1.4.1
13+
github.com/go-chi/chi v1.5.4
14+
github.com/go-chi/render v1.0.1
1015
github.com/golang-migrate/migrate/v4 v4.15.1
1116
github.com/google/uuid v1.3.0
1217
github.com/hashicorp/go-version v1.3.0
@@ -19,6 +24,7 @@ require (
1924
github.com/pion/logging v0.2.2
2025
github.com/pion/transport v0.13.0
2126
github.com/pion/webrtc/v3 v3.1.13
27+
github.com/spf13/cobra v1.3.0
2228
github.com/stretchr/testify v1.7.0
2329
go.uber.org/atomic v1.7.0
2430
go.uber.org/goleak v1.1.12
@@ -28,7 +34,6 @@ require (
2834
)
2935

3036
require (
31-
cloud.google.com/go v0.92.3 // indirect
3237
cloud.google.com/go/storage v1.14.0 // indirect
3338
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
3439
github.com/Microsoft/go-winio v0.5.1 // indirect
@@ -47,9 +52,9 @@ require (
4752
github.com/docker/docker v20.10.12+incompatible // indirect
4853
github.com/docker/go-connections v0.4.0 // indirect
4954
github.com/docker/go-units v0.4.0 // indirect
50-
github.com/fatih/color v1.12.0 // indirect
55+
github.com/fatih/color v1.13.0 // indirect
5156
github.com/gogo/protobuf v1.3.2 // indirect
52-
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
57+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
5358
github.com/google/go-cmp v0.5.6 // indirect
5459
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
5560
github.com/hashicorp/errwrap v1.0.0 // indirect
@@ -59,15 +64,16 @@ require (
5964
github.com/hashicorp/hcl/v2 v2.0.0 // indirect
6065
github.com/hashicorp/terraform-json v0.13.0 // indirect
6166
github.com/imdario/mergo v0.3.12 // indirect
62-
github.com/mattn/go-colorable v0.1.8 // indirect
63-
github.com/mattn/go-isatty v0.0.13 // indirect
67+
github.com/inconshreveable/mousetrap v1.0.0 // indirect
68+
github.com/mattn/go-colorable v0.1.12 // indirect
69+
github.com/mattn/go-isatty v0.0.14 // indirect
6470
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
65-
github.com/mitchellh/mapstructure v1.4.1 // indirect
71+
github.com/mitchellh/mapstructure v1.4.3 // indirect
6672
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
6773
github.com/opencontainers/go-digest v1.0.0 // indirect
6874
github.com/opencontainers/image-spec v1.0.2 // indirect
6975
github.com/opencontainers/runc v1.0.2 // indirect
70-
github.com/pion/dtls/v2 v2.0.13 // indirect
76+
github.com/pion/dtls/v2 v2.1.0 // indirect
7177
github.com/pion/ice/v2 v2.1.18 // indirect
7278
github.com/pion/interceptor v0.1.4 // indirect
7379
github.com/pion/mdns v0.0.5 // indirect
@@ -83,17 +89,19 @@ require (
8389
github.com/pkg/errors v0.9.1 // indirect
8490
github.com/pmezard/go-difflib v1.0.0 // indirect
8591
github.com/sirupsen/logrus v1.8.1 // indirect
92+
github.com/spf13/pflag v1.0.5 // indirect
8693
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
8794
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
8895
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
8996
github.com/zclconf/go-cty v1.9.1 // indirect
9097
github.com/zeebo/errs v1.2.2 // indirect
9198
go.opencensus.io v0.23.0 // indirect
92-
golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 // indirect
93-
golang.org/x/net v0.0.0-20211215060638-4ddde0e984e9 // indirect
94-
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c // indirect
99+
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
100+
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f // indirect
101+
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect
95102
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
96103
golang.org/x/text v0.3.7 // indirect
104+
google.golang.org/api v0.63.0 // indirect
97105
google.golang.org/grpc v1.43.0 // indirect
98106
gopkg.in/yaml.v2 v2.4.0 // indirect
99107
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect

0 commit comments

Comments
 (0)