Skip to content
Snippets Groups Projects
Commit 5ddd47ba authored by Florent Aide's avatar Florent Aide
Browse files

adding rules for golangci-lint and made linter happy again

parent e6915100
No related branches found
No related tags found
No related merge requests found
Pipeline #38189 failed
run:
timeout: 2m
sort-results: true
linters:
disable-all: true
enable:
# enable by default linters
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
# extra linters
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
- bidichk # Checks for dangerous unicode character sequences
- bodyclose # checks whether HTTP response body is closed successfully
# - containedctx # containedctx is a linter that detects struct contained context.Context field style 1.44.0
- contextcheck # check the function whether use a non-inherited context bugs v1.43.0
# - cyclop # checks function and package cyclomatic complexity complexity v1.37.0
# - decorder # check declaration order and count of types, constants, variables and functions format, style v1.44.0
# - depguard # Go linter that checks if package imports are in a list of acceptable packages style, import, module v1.4.0
# - dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f()) style v1.19.0
# - dupl # Tool for code clone detection style v1.0.0
# - durationcheck # check for two durations multiplied together bugs v1.37.0
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occations, where the check for the returned error can be omitted. bugs 1.44.0
# - errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error. style v1.42.0
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. bugs, error v1.32.0
# - exhaustive # check exhaustiveness of enum switch statements bugs v1.28.0
# - exhaustivestruct # Checks if all struct's fields are initialized style, test v1.32.0
# - exportloopref # checks for pointers to enclosing loop variables bugs v1.28.0
# - forbidigo # Forbids identifiers style v1.34.0
# - forcetypeassert # finds forced type assertions style v1.38.0
# - funlen # Tool for detection of long functions complexity v1.18.0
- gci # Gci control golang package import order and make it always deterministic. format, import ✔ v1.30.0
# - gochecknoglobals # check that no global variables exist
#
# This analyzer checks for global variables and errors on any found.
#
# A global variable is a variable declared in package scope and that can be read
# and written to by any function within the package. Global variables can cause
# side effects which are difficult to keep track of. A code in one function may
# change the variables state while another unrelated chunk of code may be
# effected by it. # style v1.12.0
# - gochecknoinits # Checks that no init functions are present in Go code style v1.12.0
# - gocognit # Computes and checks the cognitive complexity of functions complexity v1.20.0
# - goconst # Finds repeated strings that could be replaced by a constant style v1.0.0
- gocritic # Provides diagnostics that check for bugs, performance and style issues.
# - Extensible without recompilation through dynamic rules.
# - Dynamic rules are written declaratively with AST patterns, filters, report message and optional suggestion. # style, metalinter v1.12.0
# - gocyclo # Computes and checks the cyclomatic complexity of functions complexity v1.0.0
# - godot # Check if comments end in a period style, comment ✔ v1.25.0
# - godox # Tool for detection of FIXME, TODO and other comment keywords style, comment v1.19.0
# - goerr113 # Golang linter to check the errors handling expressions style, error v1.26.0
# - gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification format ✔ v1.0.0
# - gofumpt # Gofumpt checks whether code was gofumpt-ed. format ✔ v1.28.0
# - goheader # Checks is file header matches to pattern style v1.28.0
# - goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. format, import ✔ v1.20.0
# - golint ⚠ # The repository of the linter has been archived by the owner. Replaced by revive. style v1.0.0
# - gomnd # An analyzer to detect magic numbers. style v1.22.0
# - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. style, module v1.39.0
# - gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations. style, import, module v1.25.0
# - goprintffuncname # Checks that printf-like functions are named with f at the end style v1.23.0
- gosec # Inspects source code for security problems bugs v1.0.0
- ifshort # Checks that your code uses short syntax for if-statements whenever possible style v1.36.0
# - importas # Enforces consistent import aliases style v1.38.0
# - interfacer ⚠ # The repository of the linter has been archived by the owner. style v1.0.0
# - ireturn # Accept Interfaces, Return Concrete Types style v1.43.0
# - lll # Reports long lines style v1.8.0
# - maintidx # maintidx measures the maintainability index of each function. complexity v1.44.0
# - makezero # Finds slice declarations with non-zero initial length style, bugs v1.34.0
# - maligned ⚠ # The repository of the linter has been archived by the owner. Replaced by govet 'fieldalignment'. performance v1.0.0
- misspell # Finds commonly misspelled English words in comments style, comment ✔ v1.8.0
# - nakedret # Finds naked returns in functions greater than a specified function length style v1.19.0
# - nestif # Reports deeply nested if statements complexity v1.25.0
# - nilerr # Finds the code that returns nil even if it checks that the error is not nil. bugs v1.38.0
# - nilnil # Checks that there is no simultaneous return of nil error and an invalid value. style v1.43.0
# - nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity style v1.30.0
# - noctx # noctx finds sending http request without context.Context performance, bugs v1.28.0
# - nolintlint # Reports ill-formed or insufficient nolint directives style v1.26.0
# - paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test style, test v1.33.0
# - prealloc # Finds slice declarations that could potentially be preallocated performance v1.19.0
# - predeclared # find code that shadows one of Go's predeclared identifiers style v1.35.0
# - promlinter # Check Prometheus metrics naming via promlint style v1.40.0
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. style, metalinter v1.37.0
- rowserrcheck # checks whether Err of rows is checked successfully bugs, sql v1.23.0
# - scopelint ⚠ # The repository of the linter has been deprecated by the owner. Replaced by exportloopref. bugs v1.12.0
# - sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed. bugs, sql v1.28.0
# - stylecheck # Stylecheck is a replacement for golint style v1.20.0
# - tagliatelle # Checks the struct tags. style v1.40.0
# - tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 style v1.43.0
# - testpackage # linter that makes you use a separate _test package style, test v1.25.0
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers style v1.34.0
# - tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes style, test v1.32.0
- unconvert # Remove unnecessary type conversions style v1.0.0
# - unparam # Reports unused function parameters unused v1.9.0
# - varnamelen # checks that the length of a variable's name matches its scope style v1.43.0
# - wastedassign # wastedassign finds wasted assignment statements. style v1.38.0
- whitespace # Tool for detection of leading and trailing whitespace style ✔ v1.19.0
# - wrapcheck # Checks that errors returned from external packages are wrapped style, error v1.32.0
# - wsl # Whitespace Linter - Forces you to use empty lines! style v1.20.0
linters-settings:
gci:
local-prefixes: "orus.io/orus-io/beaver"
golint:
# minimal confidence for issues, default is 0.8
min-confidence: 0.5
varnamelen:
ignore-names:
- db
- msg
ignore-decls:
- t testing.T
- i int
issues:
exclude:
- SA5008 # duplicate struct tag (staticcheck)
...@@ -19,5 +19,4 @@ ...@@ -19,5 +19,4 @@
// NewBuildCmd ... // NewBuildCmd ...
func NewBuildCmd() *BuildCmd { func NewBuildCmd() *BuildCmd {
cmd := BuildCmd{} cmd := BuildCmd{}
...@@ -23,5 +22,4 @@ ...@@ -23,5 +22,4 @@
cmd := BuildCmd{} cmd := BuildCmd{}
return &cmd return &cmd
} }
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
) )
func Run() int { func Run() int {
if _, err := parser.Parse(); err != nil { if _, err := parser.Parse(); err != nil {
code := 1 code := 1
if fe, ok := err.(*flags.Error); ok { if fe, ok := err.(*flags.Error); ok {
......
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
"github.com/go-cmd/cmd" "github.com/go-cmd/cmd"
) )
func RunCMD(c *cmd.Cmd) (err error, stdout, stderr []string) { // RunCMD runs the given cmd and returns its stdout, stderr and
// an eventual error
func RunCMD(c *cmd.Cmd) (stdout, stderr []string, err error) {
statusChan := c.Start() statusChan := c.Start()
status := <-statusChan status := <-statusChan
if status.Error != nil || status.Exit > 0 { if status.Error != nil || status.Exit > 0 {
...@@ -10,7 +12,7 @@ ...@@ -10,7 +12,7 @@
statusChan := c.Start() statusChan := c.Start()
status := <-statusChan status := <-statusChan
if status.Error != nil || status.Exit > 0 { if status.Error != nil || status.Exit > 0 {
return fmt.Errorf("cannot execute command: %w", err), status.Stdout, status.Stderr return status.Stdout, status.Stderr, fmt.Errorf("cannot execute command: %w", err)
} }
stdout = status.Stdout stdout = status.Stdout
stderr = status.Stderr stderr = status.Stderr
......
...@@ -13,9 +13,10 @@ ...@@ -13,9 +13,10 @@
"github.com/spf13/viper" "github.com/spf13/viper"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"orus.io/orus-io/beaver/runner" "orus.io/orus-io/beaver/runner"
"orus.io/orus-io/beaver/testutils" "orus.io/orus-io/beaver/testutils"
) )
func TestRunCMD(t *testing.T) { func TestRunCMD(t *testing.T) {
c := cmd.NewCmd("echo", "p00f") c := cmd.NewCmd("echo", "p00f")
...@@ -16,10 +17,10 @@ ...@@ -16,10 +17,10 @@
"orus.io/orus-io/beaver/runner" "orus.io/orus-io/beaver/runner"
"orus.io/orus-io/beaver/testutils" "orus.io/orus-io/beaver/testutils"
) )
func TestRunCMD(t *testing.T) { func TestRunCMD(t *testing.T) {
c := cmd.NewCmd("echo", "p00f") c := cmd.NewCmd("echo", "p00f")
err, stdout, stderr := runner.RunCMD(c) stdout, stderr, err := runner.RunCMD(c)
require.NoError(t, err) require.NoError(t, err)
for _, out := range stdout { for _, out := range stdout {
assert.Equal(t, "p00f", out) assert.Equal(t, "p00f", out)
......
package runner package runner
import ( import (
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
...@@ -121,7 +122,6 @@ ...@@ -121,7 +122,6 @@
dirMap := make(map[string]interface{}) dirMap := make(map[string]interface{})
for weNeedToGoDeeper { for weNeedToGoDeeper {
// guard against recursive inherit loops // guard against recursive inherit loops
_, present := dirMap[dir] _, present := dirMap[dir]
if present { if present {
...@@ -138,7 +138,5 @@ ...@@ -138,7 +138,5 @@
} }
if config == nil { if config == nil {
if len(c.Layers) == 1 { if len(c.Layers) == 1 {
return fmt.Errorf("Beaver file not found in directory: %s", dir) return fmt.Errorf("beaver file not found in directory: %s", dir)
} else {
continue
} }
...@@ -144,4 +142,5 @@ ...@@ -144,4 +142,5 @@
} }
continue
} }
config.Dir = dir config.Dir = dir
if err := config.Absolutize(dir); err != nil { if err := config.Absolutize(dir); err != nil {
...@@ -207,5 +206,4 @@ ...@@ -207,5 +206,4 @@
func (c *CmdConfig) newConfigFromDir(dir string) (*Config, error) { func (c *CmdConfig) newConfigFromDir(dir string) (*Config, error) {
cfg, err := NewConfig(dir) cfg, err := NewConfig(dir)
var cfgNotFound bool
if err != nil { if err != nil {
...@@ -211,6 +209,5 @@ ...@@ -211,6 +209,5 @@
if err != nil { if err != nil {
_, cfgNotFound = err.(viper.ConfigFileNotFoundError) if errors.As(err, &viper.ConfigFileNotFoundError{}) {
if !cfgNotFound {
return nil, err return nil, err
} }
} }
...@@ -404,5 +401,6 @@ ...@@ -404,5 +401,6 @@
continue continue
} }
if tmpl, err := template.New(filepath.Base(path)).ParseFiles(path); err != nil { tmpl, err := template.New(filepath.Base(path)).ParseFiles(path)
if err != nil {
return nil, err return nil, err
...@@ -408,15 +406,7 @@ ...@@ -408,15 +406,7 @@
return nil, err return nil, err
} else { }
ext := filepath.Ext(path) ext := filepath.Ext(path)
if tmpFile, err := ioutil.TempFile(tmpDir, fmt.Sprintf("%s-*%s", strings.TrimSuffix(filepath.Base(path), ext), ext)); err != nil { tmpFile, err := ioutil.TempFile(tmpDir, fmt.Sprintf("%s-*%s", strings.TrimSuffix(filepath.Base(path), ext), ext))
return nil, fmt.Errorf("hydrateFiles failed to create tempfile: %w", err) if err != nil {
} else { return nil, fmt.Errorf("hydrateFiles failed to create tempfile: %w", err)
defer func() {
_ = tmpFile.Close()
}()
if err := tmpl.Execute(tmpFile, variables); err != nil {
return nil, fmt.Errorf("hydrateFiles failed to execute template: %w", err)
}
result = append(result, tmpFile.Name())
}
} }
...@@ -422,4 +412,11 @@ ...@@ -422,4 +412,11 @@
} }
defer func() {
_ = tmpFile.Close()
}()
if err := tmpl.Execute(tmpFile, variables); err != nil {
return nil, fmt.Errorf("hydrateFiles failed to execute template: %w", err)
}
result = append(result, tmpFile.Name())
} }
return result, nil return result, nil
} }
...@@ -428,5 +425,6 @@ ...@@ -428,5 +425,6 @@
variables := c.prepareVariables(c.Spec.Variables) variables := c.prepareVariables(c.Spec.Variables)
for key, chart := range c.Spec.Charts { for key, chart := range c.Spec.Charts {
if paths, err := hydrateFiles(dirName, variables, chart.ValuesFileNames); err != nil { paths, err := hydrateFiles(dirName, variables, chart.ValuesFileNames)
if err != nil {
return err return err
...@@ -432,5 +430,2 @@ ...@@ -432,5 +430,2 @@
return err return err
} else {
chart.ValuesFileNames = paths
c.Spec.Charts[key] = chart
} }
...@@ -436,4 +431,6 @@ ...@@ -436,4 +431,6 @@
} }
chart.ValuesFileNames = paths
c.Spec.Charts[key] = chart
} }
return nil return nil
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"orus.io/orus-io/beaver/runner" "orus.io/orus-io/beaver/runner"
"orus.io/orus-io/beaver/testutils" "orus.io/orus-io/beaver/testutils"
) )
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
...@@ -32,9 +33,9 @@ ...@@ -32,9 +33,9 @@
// Build is in charge of applying commands based on the config data // Build is in charge of applying commands based on the config data
func (r *Runner) Build(tmpDir string) error { func (r *Runner) Build(tmpDir string) error {
// TODO: find command full path // TODO: find command full path
var yttCmd string = "ytt" var yttCmd = "ytt"
var helmCmd string = "helm" var helmCmd = "helm"
var kubectlCmd string = "kubectl" var kubectlCmd = "kubectl"
// create helm commands // create helm commands
// create ytt chart commands // create ytt chart commands
cmds := make(map[string]*cmd.Cmd) cmds := make(map[string]*cmd.Cmd)
...@@ -72,7 +73,7 @@ ...@@ -72,7 +73,7 @@
} }
} else { } else {
for name, cmd := range cmds { for name, cmd := range cmds {
err, stdOut, stdErr := RunCMD(cmd) stdOut, stdErr, err := RunCMD(cmd)
if err != nil { if err != nil {
r.config.Logger.Err(err). r.config.Logger.Err(err).
Str("command", cmd.Name). Str("command", cmd.Name).
...@@ -86,5 +87,6 @@ ...@@ -86,5 +87,6 @@
fmt.Printf("\n%s\n\n", strings.Join(stdErr, "\n")) fmt.Printf("\n%s\n\n", strings.Join(stdErr, "\n"))
return fmt.Errorf("failed to run command: %w", err) return fmt.Errorf("failed to run command: %w", err)
} }
if tmpFile, err := ioutil.TempFile(tmpDir, fmt.Sprintf("compiled-%s-*.yaml", name)); err != nil { tmpFile, err := ioutil.TempFile(tmpDir, fmt.Sprintf("compiled-%s-*.yaml", name))
if err != nil {
return fmt.Errorf("cannot create compiled file: %w", err) return fmt.Errorf("cannot create compiled file: %w", err)
...@@ -90,6 +92,9 @@ ...@@ -90,6 +92,9 @@
return fmt.Errorf("cannot create compiled file: %w", err) return fmt.Errorf("cannot create compiled file: %w", err)
} else { }
defer tmpFile.Close() defer func() {
if _, err := tmpFile.WriteString(strings.Join(stdOut, "\n")); err != nil { if err := tmpFile.Close(); err != nil {
return fmt.Errorf("cannot write compiled file: %w", err) r.config.Logger.
Err(err).
Str("temp file", tmpFile.Name()).
Msg("failed to close temp file")
} }
...@@ -95,3 +100,5 @@ ...@@ -95,3 +100,5 @@
} }
compiled = append(compiled, tmpFile.Name()) }()
if _, err := tmpFile.WriteString(strings.Join(stdOut, "\n")); err != nil {
return fmt.Errorf("cannot write compiled file: %w", err)
} }
...@@ -97,4 +104,5 @@ ...@@ -97,4 +104,5 @@
} }
compiled = append(compiled, tmpFile.Name())
} }
} }
...@@ -112,7 +120,7 @@ ...@@ -112,7 +120,7 @@
Msg("would run command") Msg("would run command")
return nil return nil
} }
err, stdOut, stdErr := RunCMD(yttExtraCmd) stdOut, stdErr, err := RunCMD(yttExtraCmd)
if err != nil { if err != nil {
r.config.Logger.Err(err). r.config.Logger.Err(err).
Str("command", yttExtraCmd.Name). Str("command", yttExtraCmd.Name).
...@@ -126,5 +134,6 @@ ...@@ -126,5 +134,6 @@
fmt.Printf("\n%s\n\n", strings.Join(stdErr, "\n")) fmt.Printf("\n%s\n\n", strings.Join(stdErr, "\n"))
return fmt.Errorf("failed to run command: %w", err) return fmt.Errorf("failed to run command: %w", err)
} }
if tmpFile, err := ioutil.TempFile(tmpDir, "fully-compiled-"); err != nil { tmpFile, err := ioutil.TempFile(tmpDir, "fully-compiled-")
if err != nil {
return fmt.Errorf("cannot create fully compiled file: %w", err) return fmt.Errorf("cannot create fully compiled file: %w", err)
...@@ -130,12 +139,8 @@ ...@@ -130,12 +139,8 @@
return fmt.Errorf("cannot create fully compiled file: %w", err) return fmt.Errorf("cannot create fully compiled file: %w", err)
} else { }
defer func() { defer func() {
if err := tmpFile.Close(); err != nil { if err := tmpFile.Close(); err != nil {
r.config.Logger.Err(err). r.config.Logger.Err(err).
Str("tmp file", tmpFile.Name()). Str("tmp file", tmpFile.Name()).
Msg("failed to close temp file") Msg("failed to close temp file")
}
}()
if _, err := tmpFile.WriteString(strings.Join(stdOut, "\n")); err != nil {
return fmt.Errorf("cannot write full compiled file: %w", err)
} }
...@@ -141,14 +146,17 @@ ...@@ -141,14 +146,17 @@
} }
outputDir := filepath.Join(r.config.RootDir, "build", r.config.Namespace) }()
if err := os.RemoveAll(outputDir); err != nil { if _, err := tmpFile.WriteString(strings.Join(stdOut, "\n")); err != nil {
return fmt.Errorf("cannot cleanup output directory: %w", err) return fmt.Errorf("cannot write full compiled file: %w", err)
} }
if err := os.MkdirAll(outputDir, defaultDirMod); err != nil { outputDir := filepath.Join(r.config.RootDir, "build", r.config.Namespace)
return fmt.Errorf("cannot create output directory: %w", err) if err := os.RemoveAll(outputDir); err != nil {
} return fmt.Errorf("cannot cleanup output directory: %w", err)
if _, err := YamlSplit(outputDir, tmpFile.Name()); err != nil { }
return fmt.Errorf("cannot split full compiled file: %w", err) if err := os.MkdirAll(outputDir, defaultDirMod); err != nil {
} return fmt.Errorf("cannot create output directory: %w", err)
}
if _, err := YamlSplit(outputDir, tmpFile.Name()); err != nil {
return fmt.Errorf("cannot split full compiled file: %w", err)
} }
return nil return nil
...@@ -181,6 +189,6 @@ ...@@ -181,6 +189,6 @@
if !ok { if !ok {
return nil, fmt.Errorf("fail to type assert metadata.name from: %+v", resource) return nil, fmt.Errorf("fail to type assert metadata.name from: %+v", resource)
} }
filename := fmt.Sprintf("%s.%s.%s.yaml", kind, strings.Replace(apiVersion, "/", "_", -1), name) filename := fmt.Sprintf("%s.%s.%s.yaml", kind, strings.ReplaceAll(apiVersion, "/", "_"), name)
fPath := filepath.Join(buildDir, filename) fPath := filepath.Join(buildDir, filename)
...@@ -185,4 +193,5 @@ ...@@ -185,4 +193,5 @@
fPath := filepath.Join(buildDir, filename) fPath := filepath.Join(buildDir, filename)
if out, err := yaml.Marshal(resource); err != nil { out, err := yaml.Marshal(resource)
if err != nil {
return nil, fmt.Errorf("cannot marshal resource: %w", err) return nil, fmt.Errorf("cannot marshal resource: %w", err)
...@@ -188,11 +197,5 @@ ...@@ -188,11 +197,5 @@
return nil, fmt.Errorf("cannot marshal resource: %w", err) return nil, fmt.Errorf("cannot marshal resource: %w", err)
} else { }
if err := os.MkdirAll(buildDir, defaultDirMod); err != nil { if err := os.MkdirAll(buildDir, defaultDirMod); err != nil {
return nil, fmt.Errorf("cannot create build directory: %w", err) return nil, fmt.Errorf("cannot create build directory: %w", err)
}
content := append([]byte("---\n"), out[:]...)
if err := os.WriteFile(fPath, content, defaultFileMod); err != nil {
return nil, fmt.Errorf("cannot write resource: %w", err)
}
splitted = append(splitted, fPath)
} }
...@@ -198,4 +201,9 @@ ...@@ -198,4 +201,9 @@
} }
content := append([]byte("---\n"), out...)
if err := os.WriteFile(fPath, content, defaultFileMod); err != nil {
return nil, fmt.Errorf("cannot write resource: %w", err)
}
splitted = append(splitted, fPath)
} }
return splitted, nil return splitted, nil
...@@ -208,7 +216,7 @@ ...@@ -208,7 +216,7 @@
res := make(map[string]interface{}) res := make(map[string]interface{})
if err := decoder.Decode(&res); err != nil { if err := decoder.Decode(&res); err != nil {
// Break when there are no more documents to decode // Break when there are no more documents to decode
if err != io.EOF { if !errors.Is(err, io.EOF) {
return err return err
} }
break break
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
// NewTestLogger creates a TestLogger // NewTestLogger creates a TestLogger
func NewTestLogger(tb testing.TB) *TestLogger { func NewTestLogger(tb testing.TB) *TestLogger {
tb.Helper()
return &TestLogger{tb} return &TestLogger{tb}
} }
...@@ -40,6 +41,7 @@ ...@@ -40,6 +41,7 @@
// SetTB changes the current TB, and returns a function to get back to the // SetTB changes the current TB, and returns a function to get back to the
// previous one // previous one
func (tl *TestLogger) SetTB(tb testing.TB) func() { func (tl *TestLogger) SetTB(tb testing.TB) func() {
tb.Helper()
otb := tl.tb otb := tl.tb
tl.tb = tb tl.tb = tb
return func() { return func() {
...@@ -49,5 +51,6 @@ ...@@ -49,5 +51,6 @@
// GetLogger returns a test Logger // GetLogger returns a test Logger
func GetLogger(tb testing.TB) zerolog.Logger { func GetLogger(tb testing.TB) zerolog.Logger {
tb.Helper()
return NewTestLogger(tb).Logger() return NewTestLogger(tb).Logger()
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment