good morning!!!!

Skip to content
Snippets Groups Projects
Unverified Commit dd107dd1 authored by Anmol Sethi's avatar Anmol Sethi
Browse files

Update CI

parent d0a80496
No related branches found
No related tags found
No related merge requests found
* @nhooyr
...@@ -4,22 +4,48 @@ on: [push, pull_request] ...@@ -4,22 +4,48 @@ on: [push, pull_request]
jobs: jobs:
fmt: fmt:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: nhooyr/websocket-ci@sha256:8a8fd73fdea33585d50a33619c4936adfd016246a2ed6bbfbf06def24b518a6a
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- run: make fmt - uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: make fmt
uses: ./ci/image
with:
args: make fmt
lint: lint:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: nhooyr/websocket-ci@sha256:8a8fd73fdea33585d50a33619c4936adfd016246a2ed6bbfbf06def24b518a6a
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- run: make lint - uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: make lint
uses: ./ci/image
with:
args: make lint
test: test:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: nhooyr/websocket-ci@sha256:8a8fd73fdea33585d50a33619c4936adfd016246a2ed6bbfbf06def24b518a6a
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- run: make test - uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: make test
uses: ./ci/image
with:
args: make test
env: env:
COVERALLS_TOKEN: ${{ secrets.github_token }} COVERALLS_TOKEN: ${{ secrets.github_token }}
- name: Upload coverage.html - name: Upload coverage.html
......
...@@ -11,7 +11,3 @@ SHELL = bash ...@@ -11,7 +11,3 @@ SHELL = bash
include ci/fmt.mk include ci/fmt.mk
include ci/lint.mk include ci/lint.mk
include ci/test.mk include ci/test.mk
ci-image:
docker build -f ./ci/Dockerfile -t nhooyr/websocket-ci .
docker push nhooyr/websocket-ci
...@@ -5,8 +5,6 @@ RUN apt-get install -y chromium ...@@ -5,8 +5,6 @@ RUN apt-get install -y chromium
RUN apt-get install -y npm RUN apt-get install -y npm
RUN apt-get install -y jq RUN apt-get install -y jq
ENV GOPATH=/root/gopath
ENV PATH=$GOPATH/bin:$PATH
ENV GOFLAGS="-mod=readonly" ENV GOFLAGS="-mod=readonly"
ENV PAGER=cat ENV PAGER=cat
ENV CI=true ENV CI=true
...@@ -18,14 +16,3 @@ RUN go get golang.org/x/tools/cmd/goimports ...@@ -18,14 +16,3 @@ RUN go get golang.org/x/tools/cmd/goimports
RUN go get golang.org/x/lint/golint RUN go get golang.org/x/lint/golint
RUN go get github.com/agnivade/wasmbrowsertest RUN go get github.com/agnivade/wasmbrowsertest
RUN go get github.com/mattn/goveralls RUN go get github.com/mattn/goveralls
# Cache go modules and build cache.
COPY . /tmp/websocket
RUN cd /tmp/websocket && \
CI= make && \
rm -rf /tmp/websocket
# GitHub actions tries to override HOME to /github/home and then
# mounts a temp directory into there. We do not want this behaviour.
# I assume it is so that $HOME is preserved between steps in a job.
ENTRYPOINT ["env", "HOME=/root"]
...@@ -17,6 +17,41 @@ import ( ...@@ -17,6 +17,41 @@ import (
"nhooyr.io/websocket" "nhooyr.io/websocket"
) )
func TestConn(t *testing.T) {
t.Parallel()
t.Run("json", func(t *testing.T) {
s, closeFn := testServer(t, func(w http.ResponseWriter, r *http.Request) {
c, err := websocket.Accept(w, r, &websocket.AcceptOptions{
Subprotocols: []string{"echo"},
InsecureSkipVerify: true,
})
assert.Success(t, err)
defer c.Close(websocket.StatusInternalError, "")
err = echoLoop(r.Context(), c)
assertCloseStatus(t, websocket.StatusNormalClosure, err)
}, false)
defer closeFn()
wsURL := strings.Replace(s.URL, "http", "ws", 1)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
opts := &websocket.DialOptions{
Subprotocols: []string{"echo"},
}
opts.HTTPClient = s.Client()
c, _, err := websocket.Dial(ctx, wsURL, opts)
assert.Success(t, err)
assertJSONEcho(t, ctx, c, 2)
})
}
func testServer(tb testing.TB, fn func(w http.ResponseWriter, r *http.Request), tls bool) (s *httptest.Server, closeFn func()) { func testServer(tb testing.TB, fn func(w http.ResponseWriter, r *http.Request), tls bool) (s *httptest.Server, closeFn func()) {
h := http.HandlerFunc(fn) h := http.HandlerFunc(fn)
if tls { if tls {
...@@ -108,37 +143,3 @@ func echoLoop(ctx context.Context, c *websocket.Conn) error { ...@@ -108,37 +143,3 @@ func echoLoop(ctx context.Context, c *websocket.Conn) error {
} }
} }
} }
func TestConn(t *testing.T) {
t.Parallel()
t.Run("json", func(t *testing.T) {
s, closeFn := testServer(t, func(w http.ResponseWriter, r *http.Request) {
c, err := websocket.Accept(w, r, &websocket.AcceptOptions{
Subprotocols: []string{"echo"},
InsecureSkipVerify: true,
})
assert.Success(t, err)
defer c.Close(websocket.StatusInternalError, "")
err = echoLoop(r.Context(), c)
assertCloseStatus(t, websocket.StatusNormalClosure, err)
}, false)
defer closeFn()
wsURL := strings.Replace(s.URL, "http", "ws", 1)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
opts := &websocket.DialOptions{
Subprotocols: []string{"echo"},
}
opts.HTTPClient = s.Client()
c, _, err := websocket.Dial(ctx, wsURL, opts)
assert.Success(t, err)
assertJSONEcho(t, ctx, c, 2)
})
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment