-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
license: Add -ignore, MockGen, tests
This is an AI-started copy and paste from similar code in the `inconsistentReceiverName` vet check. (I'm intentionally not factoring it as a `util/` extension at this time.) It enables calls like this: ```sh mattermost-govet -license -license.ignore=server/manifest.go ./... ``` It also extends the existing ignore checks to include the `MockGen` header, and introduces test coverage for all.
- Loading branch information
1 parent
065c05c
commit a4a63e1
Showing
50 changed files
with
544 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
}) | ||
}) | ||
} |
Oops, something went wrong.