Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 35 additions & 34 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ linters:
- copyloopvar
- decorder
- dogsled
# - dupl # temporarily disabled - has 2 issues
- dupl
- dupword
- durationcheck
- errcheck
- errchkjson
- errname
- exhaustive
Expand All @@ -32,14 +33,14 @@ linters:
- gomoddirectives
- gomodguard
- goprintffuncname
# - gosmopolitan # temporarily disabled - has 2 issues
- gosmopolitan
- govet
- grouper
- iface
- importas
- ineffassign
- interfacebloat
# - lll # temporarily disabled - has 50 issues
- lll
- loggercheck
- makezero
- mirror
Expand All @@ -48,18 +49,19 @@ linters:
- nilerr
- nilnesserr
- noctx
# - nolintlint # temporarily disabled - has 4 issues
- nolintlint
- nosprintfhostport
- predeclared
- promlinter
- protogetter
- reassign
- recvcheck
# - revive # temporarily disabled - has 38 issues
- revive
- rowserrcheck
- sloglint
- spancheck
- sqlclosecheck
- staticcheck
- tagliatelle
- testableexamples
- tparallel
Expand All @@ -76,8 +78,6 @@ linters:
# These linters are disabled ONLY because fixing/investigating their complaints initially was too overwhelming.
# We SHOULD try and evaluate each of them eventually and either fix their reports
# or comment here on why we decided to not listen to them.
- errcheck # temporarily disabled - has 11 issues
- staticcheck # temporarily disabled - has 7 issues
- cyclop
- depguard
- err113
Expand Down Expand Up @@ -109,6 +109,32 @@ linters:
- thelper
- varnamelen
- wrapcheck
settings:
errcheck:
check-type-assertions: true
check-blank: true
lll:
line-length: 250
dupl:
threshold: 400
govet:
settings:
printf:
funcs:
- (github.com/kudobuilder/kuttl/internal/utils.Logger).Logf
- (github.com/kudobuilder/kuttl/internal/utils.TestLogger).Logf
- (github.com/kudobuilder/kuttl/internal/case.clientWithKubeConfig).Logf
- (github.com/kudobuilder/kuttl/internal/case.clientWithKubeConfig).Wrapf
# TODO: fix the `context` usage in step package and enable these linters.
usetesting:
context-background: false
context-todo: false
exclusions:
paths:
- hack
- dist
- keps
- kind-*

formatters:
enable:
Expand All @@ -117,31 +143,6 @@ formatters:
settings:
goimports:
# Don't use 'github.com/kudobuilder/kuttl', it'll result in unreliable output!
local-prefixes: github.com/kudobuilder
local-prefixes:
- github.com/kudobuilder

linters-settings:
errcheck:
check-type-assertions: true
check-blank: true
lll:
line-length: 250
dupl:
threshold: 400
govet:
settings:
printf:
funcs:
- (github.com/kudobuilder/kuttl/internal/utils.Logger).Logf
- (github.com/kudobuilder/kuttl/internal/utils.TestLogger).Logf
- (github.com/kudobuilder/kuttl/internal/case.clientWithKubeConfig).Logf
- (github.com/kudobuilder/kuttl/internal/case.clientWithKubeConfig).Wrapf
# TODO: fix the `context` usage in step package and enable these linters.
usetesting:
context-background: false
context-todo: false
issues:
exclude-dirs:
- hack
- dist
- keps
- kind-*
1 change: 1 addition & 0 deletions cmd/kubectl-kuttl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package main provides the kubectl-kuttl command-line interface.
package main

import (
Expand Down
1 change: 1 addition & 0 deletions internal/assert/assert.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package assert provides assertion functionality for KUTTL test harness.
package assert

import (
Expand Down
2 changes: 1 addition & 1 deletion internal/assert/dummy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package assert
import "testing"

// TestDummy is a no-op test to satisfy coverage tools
func TestDummy(t *testing.T) {
func TestDummy(_ *testing.T) {
// This test exists only to ensure the package is recognized by go test
// and to avoid "go: no such tool 'covdata'" warnings
}
3 changes: 2 additions & 1 deletion internal/env/env.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Package env provides environment variable expansion functionality.
package env

import (
"os"
"strings"
)

// Expand provides OS expansion of defined ENV VARs inside args to commands. The expansion is limited to what is defined on the OS
// ExpandWithMap provides OS expansion of defined ENV VARs inside args to commands. The expansion is limited to what is defined on the OS
// and the variables passed into to the env parameter. To escape a dollar sign, pass in two dollar signs.
func ExpandWithMap(c string, env map[string]string) string {
// expand $$ -> $
Expand Down
2 changes: 2 additions & 0 deletions internal/expressions/cel.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package expressions provides Common Expression Language (CEL) evaluation functionality.
package expressions

import (
Expand Down Expand Up @@ -86,6 +87,7 @@ func RunAssertExpressions(
return errs
}

// LoadPrograms loads and compiles CEL programs from test assertions.
func LoadPrograms(testAssert *harness.TestAssert) (map[string]cel.Program, error) {
var errs []error
var assertions []*harness.Assertion
Expand Down
2 changes: 1 addition & 1 deletion internal/expressions/dummy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package expressions
import "testing"

// TestDummy is a no-op test to satisfy coverage tools
func TestDummy(t *testing.T) {
func TestDummy(_ *testing.T) {
// This test exists only to ensure the package is recognized by go test
// and to avoid "go: no such tool 'covdata'" warnings
}
5 changes: 3 additions & 2 deletions internal/file/files.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package file provides file manipulation and processing utilities.
package file

import (
Expand All @@ -11,7 +12,7 @@ import (
"github.com/kudobuilder/kuttl/internal/kubernetes"
)

// from a list of paths, returns an array of runtime objects
// ToObjects from a list of paths, returns an array of runtime objects.
func ToObjects(paths []string) ([]client.Object, error) {
apply := []client.Object{}

Expand All @@ -26,7 +27,7 @@ func ToObjects(paths []string) ([]client.Object, error) {
return apply, nil
}

// From a file or dir path returns an array of flat file paths
// FromPath from a file or dir path returns an array of flat file paths.
// pattern is a filepath.Match pattern to limit files to a pattern
func FromPath(path, pattern string) ([]string, error) {
files := []string{}
Expand Down
3 changes: 3 additions & 0 deletions internal/file/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
)

// Type represents the type of a test file.
type Type int

const (
Expand All @@ -21,6 +22,7 @@ const (
TypeError
)

// Info contains parsed information about a test file name.
type Info struct {
Type Type
// Error is set for TypeUnknown objects and describes the reason.
Expand All @@ -47,6 +49,7 @@ var fileNameRegex = regexp.MustCompile(`^(\d+-)?([^-.]+)(-[^.]+)?((?:\.gotmpl)?\
// fileNamePattern is a human-readable representation of fileNameRegex.
const fileNamePattern = "(<number>-)<name>(-<name>)((.gotmpl).yaml)"

// Parse parses a file name and returns information about its type and structure.
func Parse(fullName string) Info {
name := filepath.Base(fullName)
matches := fileNameRegex.FindStringSubmatch(name)
Expand Down
8 changes: 5 additions & 3 deletions internal/file/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func UntarInPlace(path string) error {
if err != nil {
return err
}
defer file.Close()
defer file.Close() //nolint:errcheck // We are just reading, don't care if closing fails as long as UnTar works.

compressed := filepath.Ext(path) == ".tgz"
return UnTar(folder, file, compressed)
Expand All @@ -33,7 +33,7 @@ func UnTar(dest string, r io.Reader, compressed bool) (err error) {
if err != nil {
return err
}
defer gzr.Close()
defer gzr.Close() //nolint:errcheck // We are just reading, don't care if closing fails as long as reading works.
r = gzr
}
tr := tar.NewReader(r)
Expand Down Expand Up @@ -76,7 +76,9 @@ func UnTar(dest string, r io.Reader, compressed bool) (err error) {
return err
}

f.Close()
if err := f.Close(); err != nil {
return err
}
}
}
}
16 changes: 12 additions & 4 deletions internal/file/tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@ package file

import (
"os"
"path"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestUntarInPlace(t *testing.T) {
tarfile := "testdata/tar-test.tgz"
err := UntarInPlace(tarfile)
assert.NoError(t, err)

folder := "testdata/tar-test"
defer os.RemoveAll(folder)
sandbox := t.TempDir()

testFile := path.Join(sandbox, "tar-test.tgz")
data, err := os.ReadFile(tarfile)
require.NoError(t, err)
require.NoError(t, os.WriteFile(testFile, data, 0600))

err = UntarInPlace(testFile)
assert.NoError(t, err)

folder := path.Join(sandbox, "tar-test")
fi, err := os.Stat(folder)
assert.NoError(t, err)
assert.True(t, fi.IsDir())
Expand Down
3 changes: 1 addition & 2 deletions internal/harness/harness.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package harness provides the main test harness functionality for KUTTL.
package harness

import (
Expand Down Expand Up @@ -288,8 +289,6 @@ func (h *Harness) Config() (*rest.Config, error) {
return nil, err
}

defer f.Close()

return h.config, kubernetes.Kubeconfig(h.config, f)
}

Expand Down
Loading
Loading