forked from coder/wsep
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
406 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: ci | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
fmt: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- uses: actions/cache@v1 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: fmt | ||
uses: ./ci/image | ||
with: | ||
args: ./ci/fmt.sh | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- uses: actions/cache@v1 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: lint | ||
uses: ./ci/image | ||
with: | ||
args: ./ci/lint.sh | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- uses: actions/cache@v1 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: test | ||
uses: ./ci/image | ||
with: | ||
args: go test ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
echo "Formatting..." | ||
|
||
go mod tidy | ||
gofmt -w -s . | ||
goimports -w "-local=$$(go list -m)" . | ||
|
||
if [ "$CI" != "" ]; then | ||
if [[ $(git ls-files --other --modified --exclude-standard) != "" ]]; then | ||
echo "Files need generation or are formatted incorrectly:" | ||
git -c color.ui=always status | grep --color=no '\e\[31m' | ||
echo "Please run the following locally:" | ||
echo " ./ci/fmt.sh" | ||
exit 1 | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM golang:1 | ||
|
||
ENV GOFLAGS="-mod=readonly" | ||
ENV CI=true | ||
|
||
RUN go get golang.org/x/tools/cmd/goimports | ||
RUN go get golang.org/x/lint/golint | ||
RUN go get github.com/mattn/goveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
echo "Linting..." | ||
|
||
go vet ./... | ||
golint -set_exit_status ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package wsep | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"io/ioutil" | ||
"net" | ||
"testing" | ||
|
||
"cdr.dev/slog/sloggers/slogtest/assert" | ||
"cdr.dev/wsep/internal/proto" | ||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestRemoteStdin(t *testing.T) { | ||
inputs := []string{ | ||
"pwd", | ||
"echo 123\n456", | ||
"\necho 123456\n", | ||
} | ||
|
||
for _, tcase := range inputs { | ||
server, client := net.Pipe() | ||
var stdin io.WriteCloser = remoteStdin{ | ||
conn: client, | ||
} | ||
go func() { | ||
defer client.Close() | ||
_, err := stdin.Write([]byte(tcase)) | ||
assert.Success(t, "write to stdin", err) | ||
}() | ||
|
||
bytecmp := cmp.Comparer(bytes.Equal) | ||
|
||
msg, err := ioutil.ReadAll(server) | ||
assert.Success(t, "read from server", err) | ||
|
||
header, body := proto.SplitMessage(msg) | ||
|
||
assert.Equal(t, "stdin body", body, []byte(tcase), bytecmp) | ||
assert.Equal(t, "stdin header", header, []byte(`{"type":"stdin"}`), bytecmp) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package proto | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"testing" | ||
|
||
"cdr.dev/slog/sloggers/slogtest/assert" | ||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestWithHeader(t *testing.T) { | ||
tests := []struct { | ||
inputheader, inputbody, header, body []byte | ||
}{ | ||
{ | ||
inputheader: []byte("header"), | ||
inputbody: []byte("body"), | ||
header: []byte("header"), | ||
body: []byte("body"), | ||
}, | ||
{ | ||
inputheader: []byte("header"), | ||
inputbody: []byte("b\nody\n"), | ||
header: []byte("header"), | ||
body: []byte("b\nody\n"), | ||
}, | ||
} | ||
bytecmp := cmp.Comparer(bytes.Equal) | ||
|
||
for _, tcase := range tests { | ||
b := bytes.NewBuffer(nil) | ||
withheader := WithHeader(b, []byte(tcase.inputheader)) | ||
withheader.Write([]byte(tcase.inputbody)) | ||
|
||
msg, err := ioutil.ReadAll(b) | ||
assert.Success(t, "read buffer", err) | ||
|
||
header, body := SplitMessage(msg) | ||
assert.Equal(t, "header is expected value", header, tcase.header, bytecmp) | ||
assert.Equal(t, "body is expected value", body, tcase.body, bytecmp) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters