diff --git a/go.mod b/go.mod index 1eeda4d..2a01a7a 100644 --- a/go.mod +++ b/go.mod @@ -6,5 +6,6 @@ require ( github.com/getkin/kin-openapi v0.61.0 github.com/pkg/errors v0.9.1 github.com/sajari/fuzzy v1.0.0 + github.com/stretchr/testify v1.10.0 // indirect golang.org/x/tools v0.23.0 ) diff --git a/go.sum b/go.sum index e534060..f0235cc 100644 --- a/go.sum +++ b/go.sum @@ -27,9 +27,17 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/sajari/fuzzy v1.0.0 h1:+FmwVvJErsd0d0hAPlj4CxqxUtQY/fOoY0DwX4ykpRY= github.com/sajari/fuzzy v1.0.0/go.mod h1:OjYR6KxoWOe9+dOlXeiCJd4dIbED4Oo8wpS89o0pwOo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= @@ -105,3 +113,6 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/license/license.go b/license/license.go index 6aa1036..76e3f2b 100644 --- a/license/license.go +++ b/license/license.go @@ -22,81 +22,122 @@ var EEAnalyzer = &analysis.Analyzer{ Run: run, } -var sourceAvailablePackagePrefixRe = regexp.MustCompile("^github.com/mattermost/mattermost/server/v[0-9]+/enterprise") +var ( + ignoreFilesPattern string + sourceAvailablePackagePrefixRe = regexp.MustCompile("^github.com/mattermost/mattermost/server/v[0-9]+/enterprise") +) + +const ( + defaultLicenseLine1 = "// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved." + defaultLicenseLine2 = "// See LICENSE.txt for license information." + enterpriseLicenseLine2 = "// See ENTERPRISE-LICENSE.txt and SOURCE-CODE-LICENSE.txt for license information." + sourceAvailableLicenseLine2 = "// See LICENSE.enterprise for license information." +) + +var buildHeaders = []string{ + "//go:generate", + "//go:build", +} + +var generatedHeaders = []string{ + "// Code generated by mockery", + "// Code generated by MockGen. DO NOT EDIT.", + "by go-bindata DO NOT EDIT. (@generated)", +} + +func init() { + Analyzer.Flags.StringVar(&ignoreFilesPattern, "ignore", "", "Comma separated list of files to ignore") + EEAnalyzer.Flags.StringVar(&ignoreFilesPattern, "ignore", "", "Comma separated list of files to ignore") +} func run(pass *analysis.Pass) (interface{}, error) { - const mockeryHeader = "// Code generated by mockery" - const goGenerateHeader = "//go:generate" - const bindataHeader = "by go-bindata DO NOT EDIT. (@generated)" - const buildTag = "// +build" + var ignoreFiles []string + if ignoreFilesPattern != "" { + ignoreFiles = strings.Split(ignoreFilesPattern, ",") + } + + expectedLine1 := defaultLicenseLine1 + expectedLine2 := defaultLicenseLine2 - const licenseLine1 = "// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved." - const defaultLicenseLine2 = "// See LICENSE.txt for license information." - const enterpriseLicenseLine2 = "// See ENTERPRISE-LICENSE.txt and SOURCE-CODE-LICENSE.txt for license information." - const sourceAvailableLicenseLine2 = "// See LICENSE.enterprise for license information." + if pass.Analyzer.Name == "enterpriseLicense" { + // Closed source enterprise license + expectedLine2 = enterpriseLicenseLine2 + } else if sourceAvailablePackagePrefixRe.MatchString(pass.Pkg.Path()) { + // Source available license + expectedLine2 = sourceAvailableLicenseLine2 + } +nextFile: for _, file := range pass.Files { - licenseLine2 := defaultLicenseLine2 - if pass.Analyzer.Name == "enterpriseLicense" { - // Closed source enterprise license - licenseLine2 = enterpriseLicenseLine2 - } else if sourceAvailablePackagePrefixRe.MatchString(pass.Pkg.Path()) { - // Source available license - licenseLine2 = sourceAvailableLicenseLine2 + fileObj := pass.Fset.File(file.Pos()) + + // Ignore files specified via -ignore + if fileIsIgnored(fileObj.Name(), ignoreFiles) { + continue nextFile } - // Ignore file copied from enterprise - fileObj := pass.Fset.File(file.Pos()) + // Ignore file copied from enterprise (this can later be passed via `-ignore`) if strings.HasSuffix(fileObj.Name(), "imports/imports.go") { - continue + continue nextFile } if len(file.Comments) == 0 { pass.Reportf(file.Pos(), "License not found") - continue + continue nextFile } if len(file.Comments[0].List) == 0 { pass.Reportf(file.Pos(), "License not found or wrong") - continue - } - - if strings.HasPrefix(file.Comments[0].List[0].Text, mockeryHeader) { - continue + continue nextFile } - if strings.HasSuffix(file.Comments[0].List[0].Text, bindataHeader) { - continue + // Ignore known generated files. + for _, header := range generatedHeaders { + if strings.Contains(file.Comments[0].List[0].Text, header) { + continue nextFile + } } + // Allow build directives to precede license directives. commentGroup := 0 - if strings.HasPrefix(file.Comments[0].List[0].Text, goGenerateHeader) || strings.HasPrefix(file.Comments[0].List[0].Text, buildTag) { - if len(file.Comments[0].List) > 1 { - pass.Reportf(file.Pos(), "Must be an empty line between the build directive and the license") - continue + for _, buildHeader := range buildHeaders { + if strings.HasPrefix(file.Comments[0].List[0].Text, buildHeader) { + if len(file.Comments[0].List) > 1 { + pass.Reportf(file.Pos(), "Must be an empty line between the build directive and the license") + continue nextFile + } + commentGroup++ } - commentGroup++ } if len(file.Comments) < commentGroup+1 { pass.Reportf(file.Pos(), "License not found") - continue + continue nextFile } if len(file.Comments[commentGroup].List) < 2 { pass.Reportf(file.Pos(), "License not found or wrong") - continue + continue nextFile } - if file.Comments[commentGroup].List[0].Text != licenseLine1 { - pass.Reportf(file.Comments[0].List[0].Pos(), "License wrong:\n\tseen:\n\t%s\n\t%s\n\n\texpected:\n\t%s\n\t%s", file.Comments[0].List[0].Text, file.Comments[0].List[1].Text, licenseLine1, licenseLine2) - continue + if file.Comments[commentGroup].List[0].Text != expectedLine1 { + pass.Reportf(file.Comments[commentGroup].List[0].Pos(), "License copywright wrong, expected: %s", expectedLine1) + continue nextFile } - if file.Comments[commentGroup].List[1].Text != licenseLine2 { - pass.Reportf(file.Comments[0].List[1].Pos(), "License wrong:\n\tseen:\n\t%s\n\t%s\n\n\texpected:\n\t%s\n\t%s", file.Comments[0].List[0].Text, file.Comments[0].List[1].Text, licenseLine1, licenseLine2) - continue + if file.Comments[commentGroup].List[1].Text != expectedLine2 { + pass.Reportf(file.Comments[commentGroup].List[1].Pos(), "License reference wrong, expected %s", expectedLine2) + continue nextFile } } return nil, nil } + +func fileIsIgnored(file string, ignoreFiles []string) bool { + for _, f := range ignoreFiles { + if strings.HasSuffix(file, f) { + return true + } + } + return false +} diff --git a/license/license_test.go b/license/license_test.go new file mode 100644 index 0000000..0a80696 --- /dev/null +++ b/license/license_test.go @@ -0,0 +1,199 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +package license_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/mattermost/mattermost-govet/v2/license" + "golang.org/x/tools/go/analysis/analysistest" +) + +func TestStandard(t *testing.T) { + t.Run("ignored", func(t *testing.T) { + t.Run("specified file", func(t *testing.T) { + testdata := analysistest.TestData() + require.NoError(t, license.Analyzer.Flags.Set("ignore", "ignored1.go,ignored2.go")) + analysistest.Run(t, testdata, license.Analyzer, "standard/ignored_files") + }) + + t.Run("mockery", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "standard/ignored/mockery") + }) + + t.Run("mockgen", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "standard/ignored/mockgen") + }) + + t.Run("go-bindata", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "standard/ignored/go-bin-data") + }) + }) + + t.Run("missing license", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "standard/missing") + }) + + t.Run("valid license", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "standard/valid") + }) + + t.Run("invalid copyright on line 1", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "standard/invalid_copyright") + }) + + t.Run("invalid reference on line 2", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "standard/invalid_reference") + }) + + t.Run("build directives", func(t *testing.T) { + t.Run("go:generate with valid license", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "standard/build/gogenerate") + }) + + t.Run("go:build with valid license", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "standard/build/buildtag") + }) + + t.Run("directive with valid license but without newline", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "standard/build/withoutnewline") + }) + }) +} + +func TestEnterprise(t *testing.T) { + t.Run("ignored", func(t *testing.T) { + t.Run("specified file", func(t *testing.T) { + testdata := analysistest.TestData() + require.NoError(t, license.EEAnalyzer.Flags.Set("ignore", "ignored1.go,ignored2.go")) + analysistest.Run(t, testdata, license.EEAnalyzer, "enterprise/ignored_files") + }) + + t.Run("mockery", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.EEAnalyzer, "enterprise/ignored/mockery") + }) + + t.Run("mockgen", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.EEAnalyzer, "enterprise/ignored/mockgen") + }) + + t.Run("go-bindata", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.EEAnalyzer, "enterprise/ignored/go-bin-data") + }) + }) + + t.Run("missing license", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.EEAnalyzer, "enterprise/missing") + }) + + t.Run("valid license", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.EEAnalyzer, "enterprise/valid") + }) + + t.Run("invalid copyright on line 1", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.EEAnalyzer, "enterprise/invalid_copyright") + }) + + t.Run("invalid reference on line 2", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.EEAnalyzer, "enterprise/invalid_reference") + }) + + t.Run("build directives", func(t *testing.T) { + t.Run("go:generate with valid license", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.EEAnalyzer, "enterprise/build/gogenerate") + }) + + t.Run("go:build with valid license", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.EEAnalyzer, "enterprise/build/buildtag") + }) + + t.Run("directive with valid license but without newline", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.EEAnalyzer, "enterprise/build/withoutnewline") + }) + }) +} + +func TestSourceAvailable(t *testing.T) { + t.Run("ignored", func(t *testing.T) { + t.Run("specified file", func(t *testing.T) { + testdata := analysistest.TestData() + require.NoError(t, license.Analyzer.Flags.Set("ignore", "ignored1.go,ignored2.go")) + analysistest.Run(t, testdata, license.Analyzer, "github.com/mattermost/mattermost/server/v8/enterprise/ignored_files") + }) + + t.Run("mockery", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "github.com/mattermost/mattermost/server/v8/enterprise/ignored/mockery") + }) + + t.Run("mockgen", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "github.com/mattermost/mattermost/server/v8/enterprise/ignored/mockgen") + }) + + t.Run("go-bindata", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "github.com/mattermost/mattermost/server/v8/enterprise/ignored/go-bin-data") + }) + }) + + t.Run("missing license", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "github.com/mattermost/mattermost/server/v8/enterprise/missing") + }) + + t.Run("valid license", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "github.com/mattermost/mattermost/server/v8/enterprise/valid") + }) + + t.Run("invalid copyright on line 1", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "github.com/mattermost/mattermost/server/v8/enterprise/invalid_copyright") + }) + + t.Run("invalid reference on line 2", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "github.com/mattermost/mattermost/server/v8/enterprise/invalid_reference") + }) + + t.Run("build directives", func(t *testing.T) { + t.Run("go:generate with valid license", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "github.com/mattermost/mattermost/server/v8/enterprise/build/gogenerate") + }) + + t.Run("go:build with valid license", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "github.com/mattermost/mattermost/server/v8/enterprise/build/buildtag") + }) + + t.Run("directive with valid license but without newline", func(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, license.Analyzer, "github.com/mattermost/mattermost/server/v8/enterprise/build/withoutnewline") + }) + }) +} diff --git a/license/testdata/src/enterprise/build/buildtag/build.go b/license/testdata/src/enterprise/build/buildtag/build.go new file mode 100644 index 0000000..3cab7f6 --- /dev/null +++ b/license/testdata/src/enterprise/build/buildtag/build.go @@ -0,0 +1,8 @@ +//go:build !blah + +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See ENTERPRISE-LICENSE.txt and SOURCE-CODE-LICENSE.txt for license information. + +package buildtag + +func Build() {} diff --git a/license/testdata/src/enterprise/build/gogenerate/generate.go b/license/testdata/src/enterprise/build/gogenerate/generate.go new file mode 100644 index 0000000..5568125 --- /dev/null +++ b/license/testdata/src/enterprise/build/gogenerate/generate.go @@ -0,0 +1,8 @@ +//go:generate echo "generating" + +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See ENTERPRISE-LICENSE.txt and SOURCE-CODE-LICENSE.txt for license information. + +package gogenerate + +func Generate() {} diff --git a/license/testdata/src/enterprise/build/withoutnewline/build.go b/license/testdata/src/enterprise/build/withoutnewline/build.go new file mode 100644 index 0000000..97bd05d --- /dev/null +++ b/license/testdata/src/enterprise/build/withoutnewline/build.go @@ -0,0 +1,7 @@ +//go:build !blah +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See ENTERPRISE-LICENSE.txt and SOURCE-CODE-LICENSE.txt for license information. + +package withoutnewline // want "Must be an empty line between the build directive and the license" + +func Build() {} diff --git a/license/testdata/src/enterprise/enterprise/invalid.go b/license/testdata/src/enterprise/enterprise/invalid.go new file mode 100644 index 0000000..6632d91 --- /dev/null +++ b/license/testdata/src/enterprise/enterprise/invalid.go @@ -0,0 +1,6 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// Wrong enterprise license reference // want `License reference wrong, expected // See ENTERPRISE-LICENSE\.txt and SOURCE-CODE-LICENSE\.txt for license information\.` + +package enterprise + +func Invalid() {} diff --git a/license/testdata/src/enterprise/generated/gen.go b/license/testdata/src/enterprise/generated/gen.go new file mode 100644 index 0000000..eaef5f7 --- /dev/null +++ b/license/testdata/src/enterprise/generated/gen.go @@ -0,0 +1,7 @@ +//go:generate + +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See ENTERPRISE-LICENSE.txt and SOURCE-CODE-LICENSE.txt for license information. +package generated + +func Generated() {} diff --git a/license/testdata/src/enterprise/ignored/go-bin-data/bindata.go b/license/testdata/src/enterprise/ignored/go-bin-data/bindata.go new file mode 100644 index 0000000..d222fb3 --- /dev/null +++ b/license/testdata/src/enterprise/ignored/go-bin-data/bindata.go @@ -0,0 +1,5 @@ +// Code generated by go-bindata DO NOT EDIT. (@generated) + +package bindata + +func Bindata() {} diff --git a/license/testdata/src/enterprise/ignored/mockery/mock.go b/license/testdata/src/enterprise/ignored/mockery/mock.go new file mode 100644 index 0000000..f1fcd79 --- /dev/null +++ b/license/testdata/src/enterprise/ignored/mockery/mock.go @@ -0,0 +1,5 @@ +// Code generated by mockery + +package mockery + +func Mock() {} diff --git a/license/testdata/src/enterprise/ignored/mockgen/mock.go b/license/testdata/src/enterprise/ignored/mockgen/mock.go new file mode 100644 index 0000000..b645f11 --- /dev/null +++ b/license/testdata/src/enterprise/ignored/mockgen/mock.go @@ -0,0 +1,5 @@ +// Code generated by MockGen. DO NOT EDIT. + +package mockgen + +func Mock() {} diff --git a/license/testdata/src/enterprise/ignored_files/ignored1.go b/license/testdata/src/enterprise/ignored_files/ignored1.go new file mode 100644 index 0000000..f64a310 --- /dev/null +++ b/license/testdata/src/enterprise/ignored_files/ignored1.go @@ -0,0 +1,3 @@ +package ignored_files + +func Foo() {} diff --git a/license/testdata/src/enterprise/ignored_files/ignored2.go b/license/testdata/src/enterprise/ignored_files/ignored2.go new file mode 100644 index 0000000..fe28c63 --- /dev/null +++ b/license/testdata/src/enterprise/ignored_files/ignored2.go @@ -0,0 +1,3 @@ +package ignored_files + +func Bar() {} diff --git a/license/testdata/src/enterprise/invalid_copyright/invalid.go b/license/testdata/src/enterprise/invalid_copyright/invalid.go new file mode 100644 index 0000000..b6d72c4 --- /dev/null +++ b/license/testdata/src/enterprise/invalid_copyright/invalid.go @@ -0,0 +1,6 @@ +// Wrong copyright line // want `License copywright wrong, expected: // Copyright \(c\) 2015-present Mattermost, Inc\. All Rights Reserved\.` +// See ENTERPRISE-LICENSE.txt and SOURCE-CODE-LICENSE.txt for license information. + +package invalid_copyright + +func Invalid() {} diff --git a/license/testdata/src/enterprise/invalid_reference/invalid.go b/license/testdata/src/enterprise/invalid_reference/invalid.go new file mode 100644 index 0000000..c73d166 --- /dev/null +++ b/license/testdata/src/enterprise/invalid_reference/invalid.go @@ -0,0 +1,6 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// Wrong license reference // want `License reference wrong, expected // See ENTERPRISE-LICENSE.txt and SOURCE-CODE-LICENSE.txt for license information.` + +package invalid_reference + +func Invalid() {} diff --git a/license/testdata/src/enterprise/missing/missing.go b/license/testdata/src/enterprise/missing/missing.go new file mode 100644 index 0000000..54a7dac --- /dev/null +++ b/license/testdata/src/enterprise/missing/missing.go @@ -0,0 +1,3 @@ +package missing // want `License not found or wrong` + +func Missing() {} diff --git a/license/testdata/src/enterprise/source_available/invalid.go b/license/testdata/src/enterprise/source_available/invalid.go new file mode 100644 index 0000000..45fa781 --- /dev/null +++ b/license/testdata/src/enterprise/source_available/invalid.go @@ -0,0 +1,6 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// Wrong source available license reference // want `License reference wrong, expected // See ENTERPRISE-LICENSE\.txt and SOURCE-CODE-LICENSE\.txt for license information\.` + +package source_available + +func Invalid() {} diff --git a/license/testdata/src/enterprise/valid/valid.go b/license/testdata/src/enterprise/valid/valid.go new file mode 100644 index 0000000..cff5622 --- /dev/null +++ b/license/testdata/src/enterprise/valid/valid.go @@ -0,0 +1,6 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See ENTERPRISE-LICENSE.txt and SOURCE-CODE-LICENSE.txt for license information. + +package valid + +func Valid() {} diff --git a/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/build/buildtag/build.go b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/build/buildtag/build.go new file mode 100644 index 0000000..474870f --- /dev/null +++ b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/build/buildtag/build.go @@ -0,0 +1,8 @@ +//go:build !blah + +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.enterprise for license information. + +package buildtag + +func Build() {} diff --git a/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/build/gogenerate/generate.go b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/build/gogenerate/generate.go new file mode 100644 index 0000000..a6ddd56 --- /dev/null +++ b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/build/gogenerate/generate.go @@ -0,0 +1,8 @@ +//go:generate echo "generating" + +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.enterprise for license information. + +package gogenerate + +func Generate() {} diff --git a/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/build/withoutnewline/build.go b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/build/withoutnewline/build.go new file mode 100644 index 0000000..2c4d0d4 --- /dev/null +++ b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/build/withoutnewline/build.go @@ -0,0 +1,7 @@ +//go:build !blah +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.enterprise for license information. + +package withoutnewline // want "Must be an empty line between the build directive and the license" + +func Build() {} diff --git a/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/enterprise/invalid.go b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/enterprise/invalid.go new file mode 100644 index 0000000..6632d91 --- /dev/null +++ b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/enterprise/invalid.go @@ -0,0 +1,6 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// Wrong enterprise license reference // want `License reference wrong, expected // See ENTERPRISE-LICENSE\.txt and SOURCE-CODE-LICENSE\.txt for license information\.` + +package enterprise + +func Invalid() {} diff --git a/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/generated/gen.go b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/generated/gen.go new file mode 100644 index 0000000..f2fe725 --- /dev/null +++ b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/generated/gen.go @@ -0,0 +1,7 @@ +//go:generate + +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.enterprise for license information. +package generated + +func Generated() {} diff --git a/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/ignored/go-bin-data/bindata.go b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/ignored/go-bin-data/bindata.go new file mode 100644 index 0000000..d222fb3 --- /dev/null +++ b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/ignored/go-bin-data/bindata.go @@ -0,0 +1,5 @@ +// Code generated by go-bindata DO NOT EDIT. (@generated) + +package bindata + +func Bindata() {} diff --git a/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/ignored/mockery/mock.go b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/ignored/mockery/mock.go new file mode 100644 index 0000000..f1fcd79 --- /dev/null +++ b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/ignored/mockery/mock.go @@ -0,0 +1,5 @@ +// Code generated by mockery + +package mockery + +func Mock() {} diff --git a/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/ignored/mockgen/mock.go b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/ignored/mockgen/mock.go new file mode 100644 index 0000000..b645f11 --- /dev/null +++ b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/ignored/mockgen/mock.go @@ -0,0 +1,5 @@ +// Code generated by MockGen. DO NOT EDIT. + +package mockgen + +func Mock() {} diff --git a/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/ignored_files/ignored1.go b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/ignored_files/ignored1.go new file mode 100644 index 0000000..f64a310 --- /dev/null +++ b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/ignored_files/ignored1.go @@ -0,0 +1,3 @@ +package ignored_files + +func Foo() {} diff --git a/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/ignored_files/ignored2.go b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/ignored_files/ignored2.go new file mode 100644 index 0000000..fe28c63 --- /dev/null +++ b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/ignored_files/ignored2.go @@ -0,0 +1,3 @@ +package ignored_files + +func Bar() {} diff --git a/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/invalid_copyright/invalid.go b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/invalid_copyright/invalid.go new file mode 100644 index 0000000..fae4444 --- /dev/null +++ b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/invalid_copyright/invalid.go @@ -0,0 +1,6 @@ +// Wrong copyright line // want `License copywright wrong, expected: // Copyright \(c\) 2015-present Mattermost, Inc\. All Rights Reserved\.` +// See LICENSE.enterprise for license information. + +package invalid_copyright + +func Invalid() {} diff --git a/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/invalid_reference/invalid.go b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/invalid_reference/invalid.go new file mode 100644 index 0000000..ab1bacf --- /dev/null +++ b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/invalid_reference/invalid.go @@ -0,0 +1,6 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// Wrong license reference // want `License reference wrong, expected // See LICENSE.enterprise for license information.` + +package invalid_reference + +func Invalid() {} diff --git a/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/missing/missing.go b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/missing/missing.go new file mode 100644 index 0000000..54a7dac --- /dev/null +++ b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/missing/missing.go @@ -0,0 +1,3 @@ +package missing // want `License not found or wrong` + +func Missing() {} diff --git a/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/source_available/invalid.go b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/source_available/invalid.go new file mode 100644 index 0000000..45fa781 --- /dev/null +++ b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/source_available/invalid.go @@ -0,0 +1,6 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// Wrong source available license reference // want `License reference wrong, expected // See ENTERPRISE-LICENSE\.txt and SOURCE-CODE-LICENSE\.txt for license information\.` + +package source_available + +func Invalid() {} diff --git a/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/valid/valid.go b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/valid/valid.go new file mode 100644 index 0000000..21964de --- /dev/null +++ b/license/testdata/src/github.com/mattermost/mattermost/server/v8/enterprise/valid/valid.go @@ -0,0 +1,6 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.enterprise for license information. + +package valid + +func Valid() {} diff --git a/license/testdata/src/standard/build/buildtag/build.go b/license/testdata/src/standard/build/buildtag/build.go new file mode 100644 index 0000000..ce21a0d --- /dev/null +++ b/license/testdata/src/standard/build/buildtag/build.go @@ -0,0 +1,8 @@ +//go:build !blah + +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +package buildtag + +func Build() {} diff --git a/license/testdata/src/standard/build/gogenerate/generate.go b/license/testdata/src/standard/build/gogenerate/generate.go new file mode 100644 index 0000000..41a2aea --- /dev/null +++ b/license/testdata/src/standard/build/gogenerate/generate.go @@ -0,0 +1,8 @@ +//go:generate echo "generating" + +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +package gogenerate + +func Generate() {} diff --git a/license/testdata/src/standard/build/withoutnewline/build.go b/license/testdata/src/standard/build/withoutnewline/build.go new file mode 100644 index 0000000..195e068 --- /dev/null +++ b/license/testdata/src/standard/build/withoutnewline/build.go @@ -0,0 +1,7 @@ +//go:build !blah +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +package withoutnewline // want "Must be an empty line between the build directive and the license" + +func Build() {} diff --git a/license/testdata/src/standard/enterprise/invalid.go b/license/testdata/src/standard/enterprise/invalid.go new file mode 100644 index 0000000..6632d91 --- /dev/null +++ b/license/testdata/src/standard/enterprise/invalid.go @@ -0,0 +1,6 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// Wrong enterprise license reference // want `License reference wrong, expected // See ENTERPRISE-LICENSE\.txt and SOURCE-CODE-LICENSE\.txt for license information\.` + +package enterprise + +func Invalid() {} diff --git a/license/testdata/src/standard/generated/gen.go b/license/testdata/src/standard/generated/gen.go new file mode 100644 index 0000000..59dbdec --- /dev/null +++ b/license/testdata/src/standard/generated/gen.go @@ -0,0 +1,7 @@ +//go:generate + +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. +package generated + +func Generated() {} diff --git a/license/testdata/src/standard/ignored/go-bin-data/bindata.go b/license/testdata/src/standard/ignored/go-bin-data/bindata.go new file mode 100644 index 0000000..d222fb3 --- /dev/null +++ b/license/testdata/src/standard/ignored/go-bin-data/bindata.go @@ -0,0 +1,5 @@ +// Code generated by go-bindata DO NOT EDIT. (@generated) + +package bindata + +func Bindata() {} diff --git a/license/testdata/src/standard/ignored/mockery/mock.go b/license/testdata/src/standard/ignored/mockery/mock.go new file mode 100644 index 0000000..f1fcd79 --- /dev/null +++ b/license/testdata/src/standard/ignored/mockery/mock.go @@ -0,0 +1,5 @@ +// Code generated by mockery + +package mockery + +func Mock() {} diff --git a/license/testdata/src/standard/ignored/mockgen/mock.go b/license/testdata/src/standard/ignored/mockgen/mock.go new file mode 100644 index 0000000..b645f11 --- /dev/null +++ b/license/testdata/src/standard/ignored/mockgen/mock.go @@ -0,0 +1,5 @@ +// Code generated by MockGen. DO NOT EDIT. + +package mockgen + +func Mock() {} diff --git a/license/testdata/src/standard/ignored_files/ignored1.go b/license/testdata/src/standard/ignored_files/ignored1.go new file mode 100644 index 0000000..f64a310 --- /dev/null +++ b/license/testdata/src/standard/ignored_files/ignored1.go @@ -0,0 +1,3 @@ +package ignored_files + +func Foo() {} diff --git a/license/testdata/src/standard/ignored_files/ignored2.go b/license/testdata/src/standard/ignored_files/ignored2.go new file mode 100644 index 0000000..fe28c63 --- /dev/null +++ b/license/testdata/src/standard/ignored_files/ignored2.go @@ -0,0 +1,3 @@ +package ignored_files + +func Bar() {} diff --git a/license/testdata/src/standard/invalid_copyright/invalid.go b/license/testdata/src/standard/invalid_copyright/invalid.go new file mode 100644 index 0000000..644cd40 --- /dev/null +++ b/license/testdata/src/standard/invalid_copyright/invalid.go @@ -0,0 +1,6 @@ +// Wrong copyright line // want `License copywright wrong, expected: // Copyright \(c\) 2015-present Mattermost, Inc\. All Rights Reserved\.` +// See LICENSE.txt for license information. + +package invalid_copyright + +func Invalid() {} diff --git a/license/testdata/src/standard/invalid_reference/invalid.go b/license/testdata/src/standard/invalid_reference/invalid.go new file mode 100644 index 0000000..eb82c0e --- /dev/null +++ b/license/testdata/src/standard/invalid_reference/invalid.go @@ -0,0 +1,6 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// Wrong license reference // want `License reference wrong, expected // See LICENSE\.txt for license information\.` + +package invalid_reference + +func Invalid() {} diff --git a/license/testdata/src/standard/missing/missing.go b/license/testdata/src/standard/missing/missing.go new file mode 100644 index 0000000..54a7dac --- /dev/null +++ b/license/testdata/src/standard/missing/missing.go @@ -0,0 +1,3 @@ +package missing // want `License not found or wrong` + +func Missing() {} diff --git a/license/testdata/src/standard/source_available/invalid.go b/license/testdata/src/standard/source_available/invalid.go new file mode 100644 index 0000000..45fa781 --- /dev/null +++ b/license/testdata/src/standard/source_available/invalid.go @@ -0,0 +1,6 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// Wrong source available license reference // want `License reference wrong, expected // See ENTERPRISE-LICENSE\.txt and SOURCE-CODE-LICENSE\.txt for license information\.` + +package source_available + +func Invalid() {} diff --git a/license/testdata/src/standard/valid/valid.go b/license/testdata/src/standard/valid/valid.go new file mode 100644 index 0000000..0d37990 --- /dev/null +++ b/license/testdata/src/standard/valid/valid.go @@ -0,0 +1,6 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +package valid + +func Valid() {} diff --git a/mattermost-govet b/mattermost-govet new file mode 100755 index 0000000..91c46dd Binary files /dev/null and b/mattermost-govet differ