diff --git a/internal/migrate/create_test.go b/internal/migrate/create_test.go index c7477c17f..ba55b9acd 100644 --- a/internal/migrate/create_test.go +++ b/internal/migrate/create_test.go @@ -8,15 +8,14 @@ import ( "strconv" "testing" + _ "github.com/lib/pq" + _ "github.com/mattn/go-sqlite3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "storj.io/storj/internal/dbutil/pgutil" "storj.io/storj/internal/dbutil/pgutil/pgtest" "storj.io/storj/internal/migrate" - - _ "github.com/lib/pq" - _ "github.com/mattn/go-sqlite3" ) func TestCreate_Sqlite(t *testing.T) { diff --git a/pkg/encryption/encryption_test.go b/pkg/encryption/encryption_test.go index 89c647902..7627093dc 100644 --- a/pkg/encryption/encryption_test.go +++ b/pkg/encryption/encryption_test.go @@ -10,15 +10,14 @@ import ( "math/rand" "testing" - "storj.io/storj/pkg/eestream" - "storj.io/storj/pkg/encryption" - "storj.io/storj/pkg/storj" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "storj.io/storj/internal/memory" "storj.io/storj/internal/testcontext" + "storj.io/storj/pkg/eestream" + "storj.io/storj/pkg/encryption" + "storj.io/storj/pkg/storj" ) const ( diff --git a/pkg/kademlia/dialer_test.go b/pkg/kademlia/dialer_test.go index 470a84470..a6a857d0c 100644 --- a/pkg/kademlia/dialer_test.go +++ b/pkg/kademlia/dialer_test.go @@ -14,13 +14,12 @@ import ( "go.uber.org/zap/zaptest" "golang.org/x/sync/errgroup" - "storj.io/storj/pkg/peertls/tlsopts" - "storj.io/storj/internal/memory" "storj.io/storj/internal/testcontext" "storj.io/storj/internal/testplanet" "storj.io/storj/pkg/kademlia" "storj.io/storj/pkg/pb" + "storj.io/storj/pkg/peertls/tlsopts" "storj.io/storj/pkg/storj" "storj.io/storj/pkg/transport" ) diff --git a/pkg/metainfo/kvmetainfo/buckets_test.go b/pkg/metainfo/kvmetainfo/buckets_test.go index 15a3749f8..93fb14871 100644 --- a/pkg/metainfo/kvmetainfo/buckets_test.go +++ b/pkg/metainfo/kvmetainfo/buckets_test.go @@ -8,8 +8,6 @@ import ( "fmt" "testing" - "storj.io/storj/satellite/console" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/vivint/infectious" @@ -25,6 +23,7 @@ import ( "storj.io/storj/pkg/storage/segments" "storj.io/storj/pkg/storage/streams" "storj.io/storj/pkg/storj" + "storj.io/storj/satellite/console" ) const ( diff --git a/pkg/process/exec_conf_test.go b/pkg/process/exec_conf_test.go index d6ade041f..e3f0dbb93 100644 --- a/pkg/process/exec_conf_test.go +++ b/pkg/process/exec_conf_test.go @@ -9,10 +9,10 @@ import ( "os" "testing" - "github.com/stretchr/testify/require" - "storj.io/storj/internal/testcontext" - "github.com/spf13/cobra" + "github.com/stretchr/testify/require" + + "storj.io/storj/internal/testcontext" ) func setenv(key, value string) func() { diff --git a/pkg/storj/identity_version_test.go b/pkg/storj/identity_version_test.go index 1f4291460..f62ebfccc 100644 --- a/pkg/storj/identity_version_test.go +++ b/pkg/storj/identity_version_test.go @@ -7,15 +7,14 @@ import ( "crypto/x509" "testing" - "storj.io/storj/pkg/peertls/extensions" - "storj.io/storj/pkg/peertls/tlsopts" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "storj.io/storj/internal/testpeertls" "storj.io/storj/pkg/identity" "storj.io/storj/pkg/peertls" + "storj.io/storj/pkg/peertls/extensions" + "storj.io/storj/pkg/peertls/tlsopts" "storj.io/storj/pkg/storj" ) diff --git a/scripts/check-imports.go b/scripts/check-imports.go index bda7fb664..a7e838bb2 100644 --- a/scripts/check-imports.go +++ b/scripts/check-imports.go @@ -49,6 +49,7 @@ func main() { Mode: packages.LoadAllSyntax, Env: os.Environ(), BuildFlags: buildFlags, + Tests: true, }, pkgNames...) if err != nil { @@ -85,19 +86,30 @@ func main() { incorrectPkgs := []string{} for _, pkg := range pkgs { if !correctPackage(pkg) { - incorrectPkgs = append(incorrectPkgs, pkg.String()) + incorrectPkgs = append(incorrectPkgs, pkg.PkgPath) correct = false } } if !correct { - fmt.Fprintln(os.Stderr, "Error: imports are not in the correct order for package/s: ", incorrectPkgs) - fmt.Fprintln(os.Stderr, "Correct order should be: std packages -> external packages -> storj.io packages.") + fmt.Fprintln(os.Stderr) + fmt.Fprintln(os.Stderr, "Error: imports are not in the correct order for package/s: ") + for _, pkg := range incorrectPkgs { + fmt.Fprintln(os.Stderr, "\t"+pkg) + } + + fmt.Fprintln(os.Stderr) + fmt.Fprintln(os.Stderr, "Correct order should be: \n\tstd packages -> external packages -> storj.io packages.") os.Exit(1) } } func correctPackage(pkg *packages.Package) bool { + // ignore generated test binaries + if strings.HasSuffix(pkg.ID, ".test") { + return true + } + correct := true for i, file := range pkg.Syntax { path := pkg.CompiledGoFiles[i] @@ -160,6 +172,7 @@ func correctOrder(specgroups [][]ast.Spec) bool { } specgroups = specgroups[1:] } + if len(specgroups) == 0 { return true } @@ -182,7 +195,18 @@ func correctOrder(specgroups [][]ast.Spec) bool { } std, other, storj = countGroup(specgroups[0]) - return other > 0 && std+storj == 0 + return other >= 0 && std+storj == 0 +} + +func printAll(groups [][]ast.Spec) { + defer fmt.Println("---") + for i, group := range groups { + fmt.Println("===", i) + for _, imp := range group { + imp := imp.(*ast.ImportSpec) + fmt.Println("\t", imp.Path.Value) + } + } } func countGroup(p []ast.Spec) (std, other, storj int) { diff --git a/storagenode/orders/db_test.go b/storagenode/orders/db_test.go index 2d3c5f433..05d8efd93 100644 --- a/storagenode/orders/db_test.go +++ b/storagenode/orders/db_test.go @@ -7,13 +7,12 @@ import ( "crypto/rand" "testing" - "storj.io/storj/internal/testidentity" - "github.com/golang/protobuf/ptypes" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" "storj.io/storj/internal/testcontext" + "storj.io/storj/internal/testidentity" "storj.io/storj/pkg/auth/signing" "storj.io/storj/pkg/pb" "storj.io/storj/pkg/storj" diff --git a/storagenode/piecestore/serials_test.go b/storagenode/piecestore/serials_test.go index defec78ba..f6ad2038f 100644 --- a/storagenode/piecestore/serials_test.go +++ b/storagenode/piecestore/serials_test.go @@ -8,13 +8,12 @@ import ( "testing" "time" - "storj.io/storj/internal/testidentity" - "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "storj.io/storj/internal/testcontext" + "storj.io/storj/internal/testidentity" "storj.io/storj/pkg/storj" "storj.io/storj/storagenode" "storj.io/storj/storagenode/storagenodedb/storagenodedbtest" diff --git a/storagenode/vouchers/vouchers_test.go b/storagenode/vouchers/vouchers_test.go index fe1eb77b4..86fbd344a 100644 --- a/storagenode/vouchers/vouchers_test.go +++ b/storagenode/vouchers/vouchers_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/zap" + "storj.io/storj/internal/testcontext" "storj.io/storj/internal/testidentity" "storj.io/storj/internal/testplanet"