diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..0065a03 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,22 @@ +kind: pipeline +name: default + +steps: + - name: build + image: golang:latest + commands: + - make test + + - name: coverage + image: plugins/codecov + settings: + token: + from_secret: codecov-token + + - name: notify + image: plugins/webhook + urls: https://msgbus.mills.io/ci.mills.io + when: + status: + - success + - failure diff --git a/.gitignore b/.gitignore index 5de4e65..2476587 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -*~ +*~* *.bak -examples/hello/hello -examples/client/client -examples/fileserver/fileserver +coverage.txt +./hello +./client +./fileserver diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2915733..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: go -sudo: false -go: - - tip -script: - - go test -race -coverprofile=coverage.txt -covermode=atomic -after_success: - - bash <(curl -s https://codecov.io/bash) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fd7c71b --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +.PHONY: build install profile bench test clean + +all: build + +build: + @go build -o client ./examples/client + @go build -o fileserver ./examples/fileserver + @go build -o hello ./examples/hello + +install: + @go install ./... + +profile: + @go test -cpuprofile cpu.prof -memprofile mem.prof -v -bench . . + +bench: + @go test -bench . . + +test: + @go test \ + -race \ + -cover \ + -coverprofile=coverage.txt \ + -covermode=atomic \ + . + +clean: + @git clean -f -d -X diff --git a/README.md b/README.md index 8ecc812..e19ed48 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Gopher protocol library for Golang -[![Build Status](https://travis-ci.org/prologic/go-gopher.svg)](https://travis-ci.org/prologic/go-gopher) +[![Build Status](https://cloud.drone.io/api/badges/prologic/go-gopher/status.svg)](https://cloud.drone.io/prologic/go-gopher) [![CodeCov](https://codecov.io/gh/prologic/go-gopher/branch/master/graph/badge.svg)](https://codecov.io/gh/prologic/go-gopher) [![Go Report Card](https://goreportcard.com/badge/prologic/go-gopher)](https://goreportcard.com/report/prologic/go-gopher) [![GoDoc](https://godoc.org/github.com/prologic/go-gopher?status.svg)](https://godoc.org/github.com/prologic/go-gopher) - +[![Sourcegraph](https://sourcegraph.com/github.com/prologic/go-gopher/-/badge.svg)](https://sourcegraph.com/github.com/prologic/go-gopher?badge) This is a standards compliant Gopher library for the Go programming language implementing the RFC 1436 specification. The library includes both client and diff --git a/coverage.txt b/coverage.txt index 132c62c..04a21d0 100644 --- a/coverage.txt +++ b/coverage.txt @@ -21,28 +21,28 @@ github.com/prologic/go-gopher/gopher.go:137.13,138.15 1 0 github.com/prologic/go-gopher/gopher.go:139.11,140.15 1 0 github.com/prologic/go-gopher/gopher.go:141.11,142.15 1 0 github.com/prologic/go-gopher/gopher.go:143.10,144.15 1 0 -github.com/prologic/go-gopher/gopher.go:161.53,164.23 2 12 -github.com/prologic/go-gopher/gopher.go:168.2,175.20 2 11 -github.com/prologic/go-gopher/gopher.go:182.2,182.20 1 11 -github.com/prologic/go-gopher/gopher.go:189.2,189.20 1 11 -github.com/prologic/go-gopher/gopher.go:204.2,204.21 1 11 -github.com/prologic/go-gopher/gopher.go:210.2,210.8 1 11 +github.com/prologic/go-gopher/gopher.go:161.53,164.23 2 7 +github.com/prologic/go-gopher/gopher.go:168.2,175.20 2 6 +github.com/prologic/go-gopher/gopher.go:182.2,182.20 1 6 +github.com/prologic/go-gopher/gopher.go:189.2,189.20 1 6 +github.com/prologic/go-gopher/gopher.go:204.2,204.21 1 6 +github.com/prologic/go-gopher/gopher.go:210.2,210.8 1 6 github.com/prologic/go-gopher/gopher.go:164.23,166.3 1 1 -github.com/prologic/go-gopher/gopher.go:175.20,177.3 1 10 -github.com/prologic/go-gopher/gopher.go:177.3,179.3 1 1 -github.com/prologic/go-gopher/gopher.go:182.20,184.3 1 10 -github.com/prologic/go-gopher/gopher.go:184.3,186.3 1 1 -github.com/prologic/go-gopher/gopher.go:189.20,191.17 2 10 -github.com/prologic/go-gopher/gopher.go:198.3,198.19 1 10 +github.com/prologic/go-gopher/gopher.go:175.20,177.3 1 5 +github.com/prologic/go-gopher/gopher.go:177.8,179.3 1 1 +github.com/prologic/go-gopher/gopher.go:182.20,184.3 1 5 +github.com/prologic/go-gopher/gopher.go:184.8,186.3 1 1 +github.com/prologic/go-gopher/gopher.go:189.20,191.17 2 5 +github.com/prologic/go-gopher/gopher.go:198.3,198.19 1 5 github.com/prologic/go-gopher/gopher.go:191.17,193.25 1 0 github.com/prologic/go-gopher/gopher.go:196.4,196.17 1 0 github.com/prologic/go-gopher/gopher.go:193.25,195.5 1 0 -github.com/prologic/go-gopher/gopher.go:199.3,201.3 1 1 -github.com/prologic/go-gopher/gopher.go:204.21,205.31 1 10 +github.com/prologic/go-gopher/gopher.go:199.8,201.3 1 1 +github.com/prologic/go-gopher/gopher.go:204.21,205.31 1 5 github.com/prologic/go-gopher/gopher.go:205.31,207.4 1 0 -github.com/prologic/go-gopher/gopher.go:214.46,230.2 1 6 -github.com/prologic/go-gopher/gopher.go:233.46,244.29 10 10 -github.com/prologic/go-gopher/gopher.go:249.2,251.15 2 10 +github.com/prologic/go-gopher/gopher.go:214.46,230.2 1 1 +github.com/prologic/go-gopher/gopher.go:233.46,244.29 10 5 +github.com/prologic/go-gopher/gopher.go:249.2,251.15 2 5 github.com/prologic/go-gopher/gopher.go:244.29,247.3 2 0 github.com/prologic/go-gopher/gopher.go:254.39,255.16 1 4 github.com/prologic/go-gopher/gopher.go:256.17,257.14 1 4 @@ -65,16 +65,16 @@ github.com/prologic/go-gopher/gopher.go:306.26,308.3 1 0 github.com/prologic/go-gopher/gopher.go:316.24,319.17 3 2 github.com/prologic/go-gopher/gopher.go:322.3,322.16 1 2 github.com/prologic/go-gopher/gopher.go:319.17,321.4 1 0 -github.com/prologic/go-gopher/gopher.go:323.3,325.3 1 0 +github.com/prologic/go-gopher/gopher.go:323.8,325.3 1 0 github.com/prologic/go-gopher/gopher.go:333.19,336.23 3 1 github.com/prologic/go-gopher/gopher.go:336.23,338.4 1 0 -github.com/prologic/go-gopher/gopher.go:339.3,339.27 1 1 +github.com/prologic/go-gopher/gopher.go:339.8,339.27 1 1 github.com/prologic/go-gopher/gopher.go:339.27,342.3 2 0 -github.com/prologic/go-gopher/gopher.go:342.3,345.3 2 1 +github.com/prologic/go-gopher/gopher.go:342.8,345.3 2 1 github.com/prologic/go-gopher/gopher.go:350.25,352.17 2 2 github.com/prologic/go-gopher/gopher.go:356.3,356.14 1 2 github.com/prologic/go-gopher/gopher.go:352.17,354.4 1 0 -github.com/prologic/go-gopher/gopher.go:357.3,359.17 2 0 +github.com/prologic/go-gopher/gopher.go:357.8,359.17 2 0 github.com/prologic/go-gopher/gopher.go:363.3,363.20 1 0 github.com/prologic/go-gopher/gopher.go:359.17,361.4 1 0 github.com/prologic/go-gopher/gopher.go:372.47,373.25 1 0 @@ -92,26 +92,26 @@ github.com/prologic/go-gopher/gopher.go:433.2,433.30 1 2 github.com/prologic/go-gopher/gopher.go:394.26,396.3 1 0 github.com/prologic/go-gopher/gopher.go:399.16,401.3 1 0 github.com/prologic/go-gopher/gopher.go:404.16,406.3 1 0 -github.com/prologic/go-gopher/gopher.go:414.21,417.21 2 9 -github.com/prologic/go-gopher/gopher.go:421.3,421.39 1 9 -github.com/prologic/go-gopher/gopher.go:425.3,426.17 2 7 -github.com/prologic/go-gopher/gopher.go:430.3,430.30 1 7 +github.com/prologic/go-gopher/gopher.go:414.21,417.21 2 4 +github.com/prologic/go-gopher/gopher.go:421.3,421.39 1 4 +github.com/prologic/go-gopher/gopher.go:425.3,426.17 2 2 +github.com/prologic/go-gopher/gopher.go:430.3,430.30 1 2 github.com/prologic/go-gopher/gopher.go:417.21,418.12 1 0 github.com/prologic/go-gopher/gopher.go:421.39,422.9 1 2 github.com/prologic/go-gopher/gopher.go:426.17,428.12 2 0 github.com/prologic/go-gopher/gopher.go:507.45,510.9 3 1 github.com/prologic/go-gopher/gopher.go:513.2,513.10 1 1 github.com/prologic/go-gopher/gopher.go:510.9,512.3 1 0 -github.com/prologic/go-gopher/gopher.go:516.46,517.30 1 4 +github.com/prologic/go-gopher/gopher.go:516.46,517.30 1 0 github.com/prologic/go-gopher/gopher.go:524.2,524.16 1 0 -github.com/prologic/go-gopher/gopher.go:517.30,519.31 2 23 -github.com/prologic/go-gopher/gopher.go:522.3,522.11 1 4 -github.com/prologic/go-gopher/gopher.go:519.31,520.12 1 19 -github.com/prologic/go-gopher/gopher.go:528.37,530.16 2 5 -github.com/prologic/go-gopher/gopher.go:534.2,534.16 1 5 -github.com/prologic/go-gopher/gopher.go:538.2,539.16 2 5 -github.com/prologic/go-gopher/gopher.go:543.2,545.32 3 5 -github.com/prologic/go-gopher/gopher.go:549.2,551.36 3 4 +github.com/prologic/go-gopher/gopher.go:517.30,519.31 2 0 +github.com/prologic/go-gopher/gopher.go:522.3,522.11 1 0 +github.com/prologic/go-gopher/gopher.go:519.31,520.12 1 0 +github.com/prologic/go-gopher/gopher.go:528.37,530.16 2 1 +github.com/prologic/go-gopher/gopher.go:534.2,534.16 1 1 +github.com/prologic/go-gopher/gopher.go:538.2,539.16 2 1 +github.com/prologic/go-gopher/gopher.go:543.2,545.32 3 1 +github.com/prologic/go-gopher/gopher.go:549.2,551.36 3 0 github.com/prologic/go-gopher/gopher.go:530.16,532.3 1 0 github.com/prologic/go-gopher/gopher.go:534.16,536.3 1 0 github.com/prologic/go-gopher/gopher.go:539.16,541.3 1 0 @@ -158,10 +158,10 @@ github.com/prologic/go-gopher/gopher.go:747.16,749.3 1 0 github.com/prologic/go-gopher/gopher.go:753.16,755.3 1 0 github.com/prologic/go-gopher/gopher.go:758.16,760.3 1 0 github.com/prologic/go-gopher/gopher.go:763.27,766.3 2 2 -github.com/prologic/go-gopher/gopher.go:766.3,770.3 2 0 +github.com/prologic/go-gopher/gopher.go:766.8,770.3 2 0 github.com/prologic/go-gopher/gopher.go:781.59,782.23 1 0 github.com/prologic/go-gopher/gopher.go:782.23,784.3 1 0 -github.com/prologic/go-gopher/gopher.go:784.3,786.3 1 0 +github.com/prologic/go-gopher/gopher.go:784.8,786.3 1 0 github.com/prologic/go-gopher/gopher.go:815.57,818.2 2 1 github.com/prologic/go-gopher/gopher.go:849.79,852.2 2 0 github.com/prologic/go-gopher/gopher.go:895.30,895.54 1 0 @@ -215,12 +215,12 @@ github.com/prologic/go-gopher/gopher.go:1097.2,1097.15 1 1 github.com/prologic/go-gopher/gopher.go:1102.2,1109.23 2 1 github.com/prologic/go-gopher/gopher.go:1093.15,1095.3 1 1 github.com/prologic/go-gopher/gopher.go:1097.15,1100.3 2 0 -github.com/prologic/go-gopher/gopher.go:1112.45,1113.15 1 7 -github.com/prologic/go-gopher/gopher.go:1117.2,1117.15 1 7 -github.com/prologic/go-gopher/gopher.go:1121.2,1121.33 1 7 -github.com/prologic/go-gopher/gopher.go:1126.2,1127.16 2 7 -github.com/prologic/go-gopher/gopher.go:1131.2,1132.16 2 7 -github.com/prologic/go-gopher/gopher.go:1136.2,1136.12 1 7 +github.com/prologic/go-gopher/gopher.go:1112.45,1113.15 1 2 +github.com/prologic/go-gopher/gopher.go:1117.2,1117.15 1 2 +github.com/prologic/go-gopher/gopher.go:1121.2,1121.33 1 2 +github.com/prologic/go-gopher/gopher.go:1126.2,1127.16 2 2 +github.com/prologic/go-gopher/gopher.go:1131.2,1132.16 2 2 +github.com/prologic/go-gopher/gopher.go:1136.2,1136.12 1 2 github.com/prologic/go-gopher/gopher.go:1113.15,1115.3 1 1 github.com/prologic/go-gopher/gopher.go:1117.15,1119.3 1 0 github.com/prologic/go-gopher/gopher.go:1121.33,1124.3 2 0 @@ -252,19 +252,19 @@ github.com/prologic/go-gopher/gopher.go:1232.16,1234.3 1 1 github.com/prologic/go-gopher/gopher.go:1258.67,1264.16 4 1 github.com/prologic/go-gopher/gopher.go:1270.2,1272.29 2 1 github.com/prologic/go-gopher/gopher.go:1264.16,1269.3 2 0 -github.com/prologic/go-gopher/gopher.go:1272.29,1273.28 1 9 -github.com/prologic/go-gopher/gopher.go:1276.3,1276.34 1 6 -github.com/prologic/go-gopher/gopher.go:1273.28,1274.12 1 3 -github.com/prologic/go-gopher/gopher.go:1276.34,1281.18 2 1 -github.com/prologic/go-gopher/gopher.go:1285.4,1291.6 1 1 +github.com/prologic/go-gopher/gopher.go:1272.29,1273.28 1 1 +github.com/prologic/go-gopher/gopher.go:1276.3,1276.34 1 1 +github.com/prologic/go-gopher/gopher.go:1273.28,1274.12 1 0 +github.com/prologic/go-gopher/gopher.go:1276.34,1281.18 2 0 +github.com/prologic/go-gopher/gopher.go:1285.4,1291.6 1 0 github.com/prologic/go-gopher/gopher.go:1281.18,1284.5 2 0 -github.com/prologic/go-gopher/gopher.go:1292.4,1292.42 1 5 -github.com/prologic/go-gopher/gopher.go:1292.42,1297.18 2 5 -github.com/prologic/go-gopher/gopher.go:1302.4,1310.6 2 5 +github.com/prologic/go-gopher/gopher.go:1292.9,1292.42 1 1 +github.com/prologic/go-gopher/gopher.go:1292.42,1297.18 2 1 +github.com/prologic/go-gopher/gopher.go:1302.4,1310.6 2 1 github.com/prologic/go-gopher/gopher.go:1297.18,1300.5 2 0 github.com/prologic/go-gopher/gopher.go:1317.37,1317.54 1 1 -github.com/prologic/go-gopher/gopher.go:1318.37,1318.73 1 25 -github.com/prologic/go-gopher/gopher.go:1319.37,1319.64 1 17 +github.com/prologic/go-gopher/gopher.go:1318.37,1318.73 1 0 +github.com/prologic/go-gopher/gopher.go:1319.37,1319.64 1 0 github.com/prologic/go-gopher/gopher.go:1322.74,1326.16 3 1 github.com/prologic/go-gopher/gopher.go:1330.2,1333.16 3 1 github.com/prologic/go-gopher/gopher.go:1339.2,1339.15 1 1 diff --git a/gopher_test.go b/gopher_test.go index 1f7889a..a0a6f62 100644 --- a/gopher_test.go +++ b/gopher_test.go @@ -51,12 +51,13 @@ func TestFileServer(t *testing.T) { res, err := gopher.Get("gopher://localhost:7000/") assert.NoError(err) - assert.Len(res.Dir.Items, 6) + assert.Len(res.Dir.Items, 1) json, err := res.Dir.ToJSON() assert.Nil(err) - assert.JSONEq(string(json), `{"items":[{"type":"0","description":"LICENSE","selector":"LICENSE","host":"127.0.0.1","port":7000,"extras":[]},{"type":"0","description":"README.md","selector":"README.md","host":"127.0.0.1","port":7000,"extras":[]},{"type":"0","description":"coverage.txt","selector":"coverage.txt","host":"127.0.0.1","port":7000,"extras":[]},{"type":"1","description":"examples","selector":"examples","host":"127.0.0.1","port":7000,"extras":[]},{"type":"0","description":"gopher.go","selector":"gopher.go","host":"127.0.0.1","port":7000,"extras":[]},{"type":"0","description":"gopher_test.go","selector":"gopher_test.go","host":"127.0.0.1","port":7000,"extras":[]}]}`) + log.Println(string(json)) + assert.JSONEq(string(json), `{"items":[{"type":"0","description":"hello.txt","selector":"hello.txt","host":"127.0.0.1","port":7000,"extras":[]}]}`) } func TestParseItemNull(t *testing.T) { @@ -122,7 +123,7 @@ func TestParseItemMarshalIdempotency(t *testing.T) { } func TestMain(m *testing.M) { - gopher.Handle("/", gopher.FileServer(gopher.Dir("."))) + gopher.Handle("/", gopher.FileServer(gopher.Dir("./testdata"))) gopher.HandleFunc("/hello", hello) go func() { log.Fatal(gopher.ListenAndServe("localhost:7000", nil)) diff --git a/testdata/hello.txt b/testdata/hello.txt new file mode 100644 index 0000000..557db03 --- /dev/null +++ b/testdata/hello.txt @@ -0,0 +1 @@ +Hello World