Skip to content

Commit

Permalink
tests: verify what forbid would let through
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Aug 15, 2023
1 parent d48d064 commit e706a4a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
9 changes: 7 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ module github.com/moov-io/infra

go 1.21

require goftp.io/server v0.4.1
require (
github.com/stretchr/testify v1.8.3
goftp.io/server v0.4.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/jlaffaye/ftp v0.2.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
Expand All @@ -14,10 +18,11 @@ require (
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/stretchr/testify v1.8.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
Expand Down
41 changes: 41 additions & 0 deletions tests/go/panic_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package go_test

import (
"regexp"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func TestPanicLinter(t *testing.T) {
// The follow snippets of code should be allowed through by the go/lint-project.sh script.
r := regexp.MustCompile(`([a-z]+)`)
require.True(t, r.MatchString("abc"))

var out string
func() {
defer func() {
caught := recover()
if ss, ok := caught.(string); ok {
out = ss
}
}()
require.Equal(t, "", strings.Repeat("Z", -1))
}()
require.Equal(t, "strings: negative Repeat count", out)

f := &foo{}
f.panic("whoops")

// call panic but allow it
require.Panics(t, func() {
panic("bad thing") //nolint:forbidigo
})
}

type foo struct{}

func (*foo) panic(desc string) {
// send PD alert or something
}

0 comments on commit e706a4a

Please sign in to comment.