diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..9feb581 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,17 @@ +name: golangci-lint +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] +jobs: + lint: + name: lint + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.29 \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..a5ce542 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,22 @@ +name: test +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] +jobs: + test: + strategy: + matrix: + go-version: [1.14.x, 1.15.x] + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - name: Checkout code + uses: actions/checkout@v2 + - name: Test + run: go test -v -race ./... diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..198f7c1 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,22 @@ +run: + timeout: 5m + +linters: + enable: + - deadcode + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - structcheck + - typecheck + - unused + - varcheck + - gofmt + disable-all: true + +linters-settings: + gofmt: + # simplify code: gofmt with `-s` option, true by default + simplify: false \ No newline at end of file diff --git a/wgsd_test.go b/wgsd_test.go index 88aea11..9ef5e56 100644 --- a/wgsd_test.go +++ b/wgsd_test.go @@ -1,7 +1,6 @@ package wgsd import ( - "bytes" "context" "encoding/base32" "fmt" @@ -26,14 +25,6 @@ func (m *mockClient) Device(d string) (*wgtypes.Device, error) { }, nil } -func base32EqualsPubKey(t *testing.T, b32 string, pubKey wgtypes.Key) bool { - got, err := base32.StdEncoding.DecodeString(strings.ToUpper(b32)) - if err != nil { - t.Fatalf("error decoding base32 string: %v", err) - } - return bytes.Equal(pubKey[:], got) -} - func TestWGSD(t *testing.T) { key1 := [32]byte{} key1[0] = 1 @@ -65,7 +56,7 @@ func TestWGSD(t *testing.T) { } testCases := []test.Case{ - test.Case{ + { Qname: "_wireguard._udp.example.com.", Qtype: dns.TypePTR, Rcode: dns.RcodeSuccess, @@ -74,7 +65,7 @@ func TestWGSD(t *testing.T) { test.PTR(fmt.Sprintf("_wireguard._udp.example.com. 0 IN PTR %s._wireguard._udp.example.com.", peer2b32)), }, }, - test.Case{ + { Qname: fmt.Sprintf("%s._wireguard._udp.example.com.", peer1b32), Qtype: dns.TypeSRV, Rcode: dns.RcodeSuccess, @@ -85,7 +76,7 @@ func TestWGSD(t *testing.T) { test.A(fmt.Sprintf("%s.example.com. 0 IN A %s", peer1b32, peer1.Endpoint.IP.String())), }, }, - test.Case{ + { Qname: fmt.Sprintf("%s._wireguard._udp.example.com.", peer2b32), Qtype: dns.TypeSRV, Rcode: dns.RcodeSuccess, @@ -96,7 +87,7 @@ func TestWGSD(t *testing.T) { test.AAAA(fmt.Sprintf("%s.example.com. 0 IN AAAA %s", peer2b32, peer2.Endpoint.IP.String())), }, }, - test.Case{ + { Qname: fmt.Sprintf("%s.example.com.", peer1b32), Qtype: dns.TypeA, Rcode: dns.RcodeSuccess, @@ -104,7 +95,7 @@ func TestWGSD(t *testing.T) { test.A(fmt.Sprintf("%s.example.com. 0 IN A %s", peer1b32, peer1.Endpoint.IP.String())), }, }, - test.Case{ + { Qname: fmt.Sprintf("%s.example.com.", peer2b32), Qtype: dns.TypeAAAA, Rcode: dns.RcodeSuccess, @@ -112,7 +103,7 @@ func TestWGSD(t *testing.T) { test.AAAA(fmt.Sprintf("%s.example.com. 0 IN AAAA %s", peer2b32, peer2.Endpoint.IP.String())), }, }, - test.Case{ + { Qname: "nxdomain.example.com.", Qtype: dns.TypeAAAA, Rcode: dns.RcodeNameError, @@ -120,7 +111,7 @@ func TestWGSD(t *testing.T) { test.SOA(soa("example.com.").String()), }, }, - test.Case{ + { Qname: "servfail.notexample.com.", Qtype: dns.TypeAAAA, Rcode: dns.RcodeServerFailure,