Skip to content

Commit

Permalink
Enable testifylint linter (#842)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 authored Mar 14, 2024
1 parent 82f34c8 commit 22945e9
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0
with:
version: latest
only-new-issues: true
only-new-issues: false

# Optional: golangci-lint command line arguments.
args: --verbose
52 changes: 34 additions & 18 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
issues:
fix: true
exclude-rules:
- linters:
- gosec
text: 'G101'
path: 'pkg/test/resource/v3/secret.go'
- linters:
- gosec
text: 'G101'
path: 'pkg/test/resource/v3/secret.go'
max-issues-per-linter: 0
max-same-issues: 0

linters:
enable:
- bodyclose
- contextcheck
- errcheck
- errorlint
- gofumpt
- goimports
- gosec
- misspell
- revive
- unconvert
- unparam
- unused
- whitespace
- bodyclose
- contextcheck
- errcheck
- errorlint
- gofumpt
- goimports
- gosec
- misspell
- revive
- testifylint
- unconvert
- unparam
- unused
- whitespace

linters-settings:
exhaustive:
Expand All @@ -33,6 +33,22 @@ linters-settings:
local-prefixes: github.com/envoyproxy/go-control-plane
misspell:
locale: US
testifylint:
disable:
- float-compare
- go-require
enable:
- bool-compare
- compares
- empty
- error-is-as
- error-nil
- expected-actual
- len
- require-error
- suite-dont-use-pkg
- suite-extra-assert-call

unparam:
check-exported: false

Expand Down
4 changes: 2 additions & 2 deletions internal/example/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func makeEndpoint(clusterName string) *endpoint.ClusterLoadAssignment {
}
}

func makeRoute(routeName string, clusterName string) *route.RouteConfiguration {
func makeRoute(routeName, clusterName string) *route.RouteConfiguration {
return &route.RouteConfiguration{
Name: routeName,
VirtualHosts: []*route.VirtualHost{{
Expand All @@ -104,7 +104,7 @@ func makeRoute(routeName string, clusterName string) *route.RouteConfiguration {
}
}

func makeHTTPListener(listenerName string, route string) *listener.Listener {
func makeHTTPListener(listenerName, route string) *listener.Listener {
routerConfig, _ := anypb.New(&router.Router{})
// HTTP filter configuration
manager := &hcm.HttpConnectionManager{
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/v3/delta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/envoyproxy/go-control-plane/pkg/test/resource/v3"
)

func assertResourceMapEqual(t *testing.T, want map[string]types.Resource, got map[string]types.Resource) {
func assertResourceMapEqual(t *testing.T, want, got map[string]types.Resource) {
t.Helper()

if !cmp.Equal(want, got, protocmp.Transform()) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/v3/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func getResourceReferences(resources map[string]types.ResourceWithTTL, out map[r
}
}

func mapMerge(dst map[string]bool, src map[string]bool) {
func mapMerge(dst, src map[string]bool) {
for k, v := range src {
dst[k] = v
}
Expand Down
1 change: 0 additions & 1 deletion pkg/cache/v3/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func (s *Snapshot) Consistent() error {
}

for idx, items := range s.Resources {

// We only want to check resource types that are expected to be referenced by another resource type.
// Basically, if the consistency relationship is modeled as a DAG, we only want
// to check nodes that are expected to have edges pointing to it.
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/v3/delta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ func TestDeltaWildcardSubscriptions(t *testing.T) {
},
}

validateResponse := func(t *testing.T, replies <-chan *discovery.DeltaDiscoveryResponse, expectedResources []string, expectedRemovedResources []string) {
validateResponse := func(t *testing.T, replies <-chan *discovery.DeltaDiscoveryResponse, expectedResources, expectedRemovedResources []string) {
t.Helper()
select {
case response := <-replies:
Expand Down
1 change: 0 additions & 1 deletion pkg/test/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ func main() {
if err := eds.UpdateResource(name, res); err != nil {
log.Printf("update error %q for %+v\n", err, name)
os.Exit(1)

}
}
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/test/resource/v3/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func MakeEndpoint(clusterName string, port uint32) *endpoint.ClusterLoadAssignme
}

// MakeCluster creates a cluster using either ADS or EDS.
func MakeCluster(mode string, clusterName string) *cluster.Cluster {
func MakeCluster(mode, clusterName string) *cluster.Cluster {
edsSource := configSource(mode)

connectTimeout := 5 * time.Second
Expand All @@ -109,7 +109,7 @@ func MakeCluster(mode string, clusterName string) *cluster.Cluster {
}
}

func MakeVHDSRouteConfig(mode string, routeName string) *route.RouteConfiguration {
func MakeVHDSRouteConfig(mode, routeName string) *route.RouteConfiguration {
return &route.RouteConfiguration{
Name: routeName,
Vhds: &route.Vhds{
Expand All @@ -119,7 +119,7 @@ func MakeVHDSRouteConfig(mode string, routeName string) *route.RouteConfiguratio
}

// MakeRouteConfig creates an HTTP route config that routes to a given cluster.
func MakeRouteConfig(routeName string, clusterName string) *route.RouteConfiguration {
func MakeRouteConfig(routeName, clusterName string) *route.RouteConfiguration {
return &route.RouteConfiguration{
Name: routeName,
VirtualHosts: []*route.VirtualHost{{
Expand All @@ -144,7 +144,7 @@ func MakeRouteConfig(routeName string, clusterName string) *route.RouteConfigura
}

// MakeScopedRouteConfig creates an HTTP scoped route that routes to a given cluster.
func MakeScopedRouteConfig(scopedRouteName string, routeConfigurationName string, keyFragments []string) *route.ScopedRouteConfiguration {
func MakeScopedRouteConfig(scopedRouteName, routeConfigurationName string, keyFragments []string) *route.ScopedRouteConfiguration {
k := &route.ScopedRouteConfiguration_Key{}

for _, key := range keyFragments {
Expand All @@ -164,7 +164,7 @@ func MakeScopedRouteConfig(scopedRouteName string, routeConfigurationName string
}
}

func MakeVirtualHost(virtualHostName string, clusterName string) *route.VirtualHost {
func MakeVirtualHost(virtualHostName, clusterName string) *route.VirtualHost {
ret := &route.VirtualHost{
Name: virtualHostName,
Domains: []string{"*"},
Expand Down Expand Up @@ -297,7 +297,7 @@ func makeListener(listenerName string, port uint32, filterChains []*listener.Fil
}
}

func MakeRouteHTTPListener(mode string, listenerName string, port uint32, route string) *listener.Listener {
func MakeRouteHTTPListener(mode, listenerName string, port uint32, route string) *listener.Listener {
rdsSource := configSource(mode)
routeSpecifier := &hcm.HttpConnectionManager_Rds{
Rds: &hcm.Rds{
Expand Down Expand Up @@ -331,7 +331,7 @@ func MakeRouteHTTPListener(mode string, listenerName string, port uint32, route
}

// Creates a HTTP listener using Scoped Routes, which extracts the "Host" header field as the key.
func MakeScopedRouteHTTPListener(mode string, listenerName string, port uint32) *listener.Listener {
func MakeScopedRouteHTTPListener(mode, listenerName string, port uint32) *listener.Listener {
source := configSource(mode)
routeSpecifier := &hcm.HttpConnectionManager_ScopedRoutes{
ScopedRoutes: &hcm.ScopedRoutes{
Expand Down Expand Up @@ -386,7 +386,7 @@ func MakeScopedRouteHTTPListener(mode string, listenerName string, port uint32)
// MakeScopedRouteHTTPListenerForRoute is the same as
// MakeScopedRouteHTTPListener, except it inlines a reference to the
// routeConfigName, and so doesn't require a ScopedRouteConfiguration resource.
func MakeScopedRouteHTTPListenerForRoute(mode string, listenerName string, port uint32, routeConfigName string) *listener.Listener {
func MakeScopedRouteHTTPListenerForRoute(mode, listenerName string, port uint32, routeConfigName string) *listener.Listener {
source := configSource(mode)
routeSpecifier := &hcm.HttpConnectionManager_ScopedRoutes{
ScopedRoutes: &hcm.ScopedRoutes{
Expand Down Expand Up @@ -488,7 +488,7 @@ func MakeRuntime(runtimeName string) *runtime.Runtime {
}

// MakeExtensionConfig creates a extension config for a cluster.
func MakeExtensionConfig(mode string, extensionConfigName string, route string) *core.TypedExtensionConfig {
func MakeExtensionConfig(mode, extensionConfigName, route string) *core.TypedExtensionConfig {
rdsSource := configSource(mode)

// HTTP filter configuration
Expand Down

0 comments on commit 22945e9

Please sign in to comment.