snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Nightly Race / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 1s
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Nightly Race / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 1s
This commit is contained in:
43
tools/mattermost-govet/tFatal/tFatal.go
Normal file
43
tools/mattermost-govet/tFatal/tFatal.go
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package tFatal
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
|
||||
"golang.org/x/tools/go/analysis"
|
||||
)
|
||||
|
||||
var Analyzer = &analysis.Analyzer{
|
||||
Name: "tFatal",
|
||||
Doc: "check invalid usage of t.Fatal assertions",
|
||||
Run: run,
|
||||
}
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
for _, file := range pass.Files {
|
||||
ast.Inspect(file, func(node ast.Node) bool {
|
||||
switch x := node.(type) {
|
||||
case *ast.CallExpr:
|
||||
fun, ok := x.Fun.(*ast.SelectorExpr)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
|
||||
module, ok := fun.X.(*ast.Ident)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
|
||||
if fun.Sel.Name != "Fatal" || module.Name != "t" {
|
||||
return true
|
||||
}
|
||||
|
||||
pass.Reportf(node.Pos(), "t.Fatal usage is not allowed. Use semantic assertions with require or assert modules from testify package.")
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
15
tools/mattermost-govet/tFatal/tFatal_test.go
Normal file
15
tools/mattermost-govet/tFatal/tFatal_test.go
Normal file
@@ -0,0 +1,15 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package tFatal
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"golang.org/x/tools/go/analysis/analysistest"
|
||||
)
|
||||
|
||||
func TestAll(t *testing.T) {
|
||||
testdata := analysistest.TestData()
|
||||
analysistest.Run(t, testdata, Analyzer, "a")
|
||||
}
|
||||
109
tools/mattermost-govet/tFatal/testdata/src/a/a.go
vendored
Normal file
109
tools/mattermost-govet/tFatal/testdata/src/a/a.go
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package a
|
||||
|
||||
import "testing"
|
||||
|
||||
// Mock testify modules
|
||||
type require struct{}
|
||||
type assert struct{}
|
||||
|
||||
func (r *require) NoError(t *testing.T, err error, msgAndArgs ...interface{}) {}
|
||||
func (r *require) Equal(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{}) {}
|
||||
func (r *require) True(t *testing.T, value bool, msgAndArgs ...interface{}) {}
|
||||
func (r *require) NotNil(t *testing.T, object interface{}, msgAndArgs ...interface{}) {}
|
||||
|
||||
func (a *assert) NoError(t *testing.T, err error, msgAndArgs ...interface{}) {}
|
||||
func (a *assert) Equal(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{}) {}
|
||||
func (a *assert) True(t *testing.T, value bool, msgAndArgs ...interface{}) {}
|
||||
|
||||
var Require = &require{}
|
||||
var Assert = &assert{}
|
||||
|
||||
// Valid: Using testify require assertions
|
||||
func TestValidUsingRequire(t *testing.T) {
|
||||
require := Require
|
||||
|
||||
err := someFunction()
|
||||
require.NoError(t, err)
|
||||
|
||||
result := getValue()
|
||||
require.Equal(t, 42, result)
|
||||
require.True(t, result > 0)
|
||||
require.NotNil(t, result)
|
||||
}
|
||||
|
||||
// Valid: Using testify assert assertions
|
||||
func TestValidUsingAssert(t *testing.T) {
|
||||
assert := Assert
|
||||
|
||||
err := someFunction()
|
||||
assert.NoError(t, err)
|
||||
|
||||
result := getValue()
|
||||
assert.Equal(t, 42, result)
|
||||
assert.True(t, result > 0)
|
||||
}
|
||||
|
||||
// Invalid: Using t.Fatal
|
||||
func TestInvalidUsingTFatal(t *testing.T) {
|
||||
err := someFunction()
|
||||
if err != nil {
|
||||
t.Fatal("error occurred") // want "t.Fatal usage is not allowed. Use semantic assertions with require or assert modules from testify package."
|
||||
}
|
||||
|
||||
result := getValue()
|
||||
if result != 42 {
|
||||
t.Fatal("unexpected result") // want "t.Fatal usage is not allowed. Use semantic assertions with require or assert modules from testify package."
|
||||
}
|
||||
}
|
||||
|
||||
// Valid: Other t methods are allowed
|
||||
func TestValidOtherTMethods(t *testing.T) {
|
||||
// These are allowed
|
||||
t.Log("This is a log message")
|
||||
t.Logf("This is a formatted log: %d", 42)
|
||||
t.Error("This is an error but not Fatal")
|
||||
t.Errorf("This is a formatted error: %v", "test")
|
||||
t.Skip("Skipping test")
|
||||
t.Skipf("Skipping test: %s", "reason")
|
||||
t.SkipNow()
|
||||
t.Parallel()
|
||||
t.Helper()
|
||||
}
|
||||
|
||||
// Invalid: Multiple t.Fatal calls
|
||||
func TestMultipleTFatal(t *testing.T) {
|
||||
if someCondition() {
|
||||
t.Fatal("first fatal") // want "t.Fatal usage is not allowed. Use semantic assertions with require or assert modules from testify package."
|
||||
}
|
||||
|
||||
if anotherCondition() {
|
||||
t.Fatal("second fatal") // want "t.Fatal usage is not allowed. Use semantic assertions with require or assert modules from testify package."
|
||||
}
|
||||
}
|
||||
|
||||
// Valid: Different variable name (not t)
|
||||
func TestValidDifferentVarName(t *testing.T) {
|
||||
type myTest struct{}
|
||||
myT := &myTest{}
|
||||
// This won't be caught since the variable isn't named 't'
|
||||
_ = myT
|
||||
}
|
||||
|
||||
func someFunction() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getValue() int {
|
||||
return 42
|
||||
}
|
||||
|
||||
func someCondition() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func anotherCondition() bool {
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user