From 5fdf2514a29df0c4aa346003811b86a55d0ca11a Mon Sep 17 00:00:00 2001 From: Yury Bushmelev Date: Thu, 11 Dec 2025 11:56:52 +0800 Subject: [PATCH 1/3] chore: bump golangci-lint version to v2.7 --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 80c671d..483ae40 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,4 +13,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v9 with: - version: v2.4 + version: v2.7 From 85305351336ee23fcd4ae8fd50c3582dcb5700bf Mon Sep 17 00:00:00 2001 From: Yury Bushmelev Date: Fri, 12 Dec 2025 12:12:01 +0800 Subject: [PATCH 2/3] chore: update golangci-lint settings * disable paramTypeCombine gocritic check * disable staticcheck ST1005,ST1003 rules * disable depguard, lll, mnd, funlen linters for now --- .golangci.yml | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index e6dfcbe..1217448 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,14 +1,14 @@ version: "2" + linters: default: none enable: - bodyclose - - depguard + # - depguard # TODO: Re-enable later - dogsled - dupl - errcheck - exhaustive - - funlen - gochecknoinits - goconst - gocritic @@ -17,9 +17,9 @@ linters: - gosec - govet - ineffassign - - lll + # - lll # TODO: Re-enable later - misspell - - mnd + # - mnd # TODO: Re-enable later - nakedret - noctx - nolintlint @@ -40,6 +40,14 @@ linters: - opinionated - performance - style + disabled-checks: + - paramTypeCombine # I'm not sure it makes code more readable + - hugeParam # TODO: Re-consider this later + staticcheck: + checks: + - all + - "-ST1003" # TODO: Deal with variable names later + - "-ST1005" # TODO: Re-think error messages policy later exclusions: generated: lax presets: @@ -51,6 +59,12 @@ linters: - third_party$ - builtin$ - examples$ + rules: + - path: "(.+)_test\\.go" + linters: + - goconst + - mnd + formatters: enable: - gofmt @@ -61,3 +75,6 @@ formatters: - third_party$ - builtin$ - examples$ + +issues: + max-issues-per-linter: 0 From 113ca1d7b6f12c2d7ee2e43a93ea433044d856f5 Mon Sep 17 00:00:00 2001 From: Yury Bushmelev Date: Thu, 11 Dec 2025 11:57:21 +0800 Subject: [PATCH 3/3] refactor: fix golangci-lint issues * drop unused function args * fix goimports issue (formatting) * fix whitespace issues (formatting) * fix unnecessary convert issue * fix spelling issues * fix some errcheck issues * fix noctx lint issue * unshadow docs module (gocritic) * delete unused function parameter * drop unused code, name output params * fix more gocritic lint issues * fix more gocritic issues * replace deprecated io/ioutil * replace deprecated cobra.ExactValidArgs() * replace deprecated cobra.SetOutput() * replace deprecated strings.Title() * remove unnecessary assignment * remove most of nolint comments * fix assignOp gocritic issues * use new octal literal style (gocritic) * fix more gocritic issues * delete commented-out code * fix goconst issues --- acceptance/new/new_test.go | 7 +- acceptance/testutils/testutils.go | 13 +- cmd/build/build.go | 1 - cmd/build/build_test.go | 7 +- cmd/completion/completion.go | 2 +- cmd/explain/explain.go | 8 +- cmd/install/install_test.go | 11 +- cmd/new/new.go | 4 +- cmd/new/new_test.go | 4 +- cmd/root/root.go | 4 +- go.mod | 2 +- internal/pkg/pct/pct.go | 93 +++++++------ internal/pkg/pct/pct_test.go | 31 ++--- .../pct_config_processor.go | 6 +- .../pct_config_processor_test.go | 14 +- pkg/build/build_test.go | 8 +- pkg/docs/docs.go | 2 +- pkg/exec_runner/exec_runner.go | 8 +- pkg/gzip/gunzip_test.go | 6 +- pkg/gzip/gzip.go | 2 +- pkg/gzip/gzip_test.go | 3 +- pkg/install/install.go | 2 +- pkg/install/install_test.go | 125 +++++++++--------- pkg/mock/gunzip.go | 2 +- pkg/mock/tar.go | 1 - pkg/tar/tar.go | 4 +- pkg/tar/tar_test.go | 16 +-- pkg/utils/utils.go | 3 +- 28 files changed, 191 insertions(+), 198 deletions(-) diff --git a/acceptance/new/new_test.go b/acceptance/new/new_test.go index 362373a..f78bfd0 100644 --- a/acceptance/new/new_test.go +++ b/acceptance/new/new_test.go @@ -2,7 +2,7 @@ package new_test import ( "encoding/json" - "io/ioutil" + "io" "os" "path/filepath" "testing" @@ -10,9 +10,8 @@ import ( "github.com/jay7x/pct/acceptance/testutils" "github.com/rs/zerolog" "github.com/rs/zerolog/log" - "gopkg.in/yaml.v2" - "github.com/stretchr/testify/assert" + "gopkg.in/yaml.v2" ) const APP = "pct" @@ -20,7 +19,7 @@ const APP = "pct" var templatePath string func TestMain(m *testing.M) { - log.Logger = zerolog.New(ioutil.Discard).With().Timestamp().Logger() + log.Logger = zerolog.New(io.Discard).With().Timestamp().Logger() templatePath, _ = filepath.Abs("../../internal/pkg/pct/testdata/examples") diff --git a/acceptance/testutils/testutils.go b/acceptance/testutils/testutils.go index 5314951..fb1b721 100644 --- a/acceptance/testutils/testutils.go +++ b/acceptance/testutils/testutils.go @@ -1,6 +1,7 @@ package testutils import ( + "context" "fmt" "os" "os/exec" @@ -8,6 +9,7 @@ import ( "strings" "syscall" "testing" + "time" "github.com/rs/zerolog/log" ) @@ -27,11 +29,13 @@ func SkipAcceptanceTest(t *testing.T) { // Run Command takes a command to execute and the directory in which to execute the command. // if wd is and empty string it will default to the current working directory func RunCommand(cmdString string, wd string) (stdout string, stderr string, exitCode int) { - cmds := strings.Split(cmdString, " ") + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) + defer cancel() + cmds := strings.Split(cmdString, " ") cmds = toolArgsAsSingleArg(cmds) // Remove when GH-52 is resolved - cmd := exec.Command(cmds[0], cmds[1:]...) // #nosec // used only for testing + cmd := exec.CommandContext(ctx, cmds[0], cmds[1:]...) // #nosec // used only for testing if wd != "" { cmd.Dir = wd } @@ -39,8 +43,11 @@ func RunCommand(cmdString string, wd string) (stdout string, stderr string, exit exitCode = 0 if err != nil { + if ctx.Err() == context.DeadlineExceeded { + panic("Command timed out") + } stderr = err.Error() - // todo: double check that error statuss work on Windows + // todo: double check that error status work on Windows if msg, ok := err.(*exec.ExitError); ok { // there is error code exitCode = msg.Sys().(syscall.WaitStatus).ExitStatus() } diff --git a/cmd/build/build.go b/cmd/build/build.go index c643286..736c340 100644 --- a/cmd/build/build.go +++ b/cmd/build/build.go @@ -37,7 +37,6 @@ func (bc *BuildCommand) CreateCommand() *cobra.Command { } func (bc *BuildCommand) preExecute(cmd *cobra.Command, args []string) error { - wd, err := os.Getwd() log.Trace().Msgf("WD: %v", wd) diff --git a/cmd/build/build_test.go b/cmd/build/build_test.go index 345066a..0719842 100644 --- a/cmd/build/build_test.go +++ b/cmd/build/build_test.go @@ -2,15 +2,14 @@ package build_test import ( "bytes" - "io/ioutil" + "io" "os" "path/filepath" "testing" - "github.com/stretchr/testify/assert" - "github.com/jay7x/pct/cmd/build" "github.com/jay7x/pct/pkg/mock" + "github.com/stretchr/testify/assert" ) func TestCreateBuildCommand(t *testing.T) { @@ -79,7 +78,7 @@ func TestCreateBuildCommand(t *testing.T) { t.Errorf("Unexpected error when none wanted: %v", err) return } else { - out, _ := ioutil.ReadAll(b) + out, _ := io.ReadAll(b) assert.Regexp(t, tt.expectedErrorMatch, string(out)) } } else if tt.expectedErrorMatch != "" { diff --git a/cmd/completion/completion.go b/cmd/completion/completion.go index 4156bd2..dd14467 100644 --- a/cmd/completion/completion.go +++ b/cmd/completion/completion.go @@ -50,7 +50,7 @@ PowerShell: PS> pct completion powershell > pct.ps1 # and source this file from your PowerShell profile.`, ValidArgs: []string{"bash", "fish", "pwsh", "zsh"}, - Args: cobra.ExactValidArgs(1), + Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), Run: func(cmd *cobra.Command, args []string) { var err error switch args[0] { diff --git a/cmd/explain/explain.go b/cmd/explain/explain.go index 5b901d0..311781a 100644 --- a/cmd/explain/explain.go +++ b/cmd/explain/explain.go @@ -100,19 +100,19 @@ func flagCompletion(cmd *cobra.Command, args []string, toComplete string) ([]str } func execute(cmd *cobra.Command, args []string) error { - docs := docsApi.ParsedDocsCache + myDocs := docsApi.ParsedDocsCache if listTopics { if format == "" { format = "table" } if category != "" { - docs = docsApi.FilterByCategory(category, docs) + myDocs = docsApi.FilterByCategory(category, myDocs) } if tag != "" { - docs = docsApi.FilterByTag(tag, docs) + myDocs = docsApi.FilterByTag(tag, myDocs) } // If there's only one match, should we render the matching doc? - docsApi.FormatFrontMatter(format, docs) + docsApi.FormatFrontMatter(format, myDocs) } else if topic != "" { doc, err := docsApi.SelectDocument(topic, docsApi.ParsedDocsCache) if err != nil { diff --git a/cmd/install/install_test.go b/cmd/install/install_test.go index ad9b004..84477c1 100644 --- a/cmd/install/install_test.go +++ b/cmd/install/install_test.go @@ -2,13 +2,12 @@ package install_test import ( "bytes" - "io/ioutil" + "io" "testing" - "github.com/spf13/afero" - "github.com/jay7x/pct/cmd/install" "github.com/jay7x/pct/pkg/mock" + "github.com/spf13/afero" "github.com/spf13/viper" "github.com/stretchr/testify/assert" ) @@ -85,7 +84,8 @@ func TestCreateinstallCommand(t *testing.T) { installCmd := cmd.CreateCommand() b := bytes.NewBufferString("") - installCmd.SetOutput(b) + installCmd.SetOut(b) + installCmd.SetErr(b) installCmd.SetArgs(tt.args) err := installCmd.Execute() @@ -96,10 +96,9 @@ func TestCreateinstallCommand(t *testing.T) { } if (err != nil) && tt.expectError { - out, _ := ioutil.ReadAll(b) + out, _ := io.ReadAll(b) assert.Contains(t, string(out), tt.expectedOutput) } - }) } } diff --git a/cmd/new/new.go b/cmd/new/new.go index d6acde5..b2784a7 100644 --- a/cmd/new/new.go +++ b/cmd/new/new.go @@ -120,10 +120,10 @@ func flagCompletion(cmd *cobra.Command, args []string, toComplete string) ([]str } localTemplatePath = viper.GetString("templatepath") - return completeName(localTemplatePath, toComplete), cobra.ShellCompDirectiveNoSpace | cobra.ShellCompDirectiveNoFileComp + return completeName(toComplete), cobra.ShellCompDirectiveNoSpace | cobra.ShellCompDirectiveNoFileComp } -func completeName(cache string, match string) []string { +func completeName(match string) []string { var names []string for _, tmpl := range cachedTemplates { namespacedTemplate := fmt.Sprintf("%s/%s", tmpl.Author, tmpl.Id) diff --git a/cmd/new/new_test.go b/cmd/new/new_test.go index 55b687a..2e44eed 100644 --- a/cmd/new/new_test.go +++ b/cmd/new/new_test.go @@ -2,7 +2,7 @@ package new import ( "bytes" - "io/ioutil" + "io" "regexp" "testing" @@ -59,7 +59,7 @@ func TestCreateCommand(t *testing.T) { return } - out, err := ioutil.ReadAll(b) + out, err := io.ReadAll(b) if err != nil { t.Errorf("Failed to read stdout: %v", err) return diff --git a/cmd/root/root.go b/cmd/root/root.go index 65ab292..257a21d 100644 --- a/cmd/root/root.go +++ b/cmd/root/root.go @@ -19,7 +19,6 @@ var ( LocalTemplateCache string debug bool - // format string ) func InitLogger() { @@ -64,7 +63,6 @@ func CreateRootCommand() *cobra.Command { cobra.CheckErr(err) tmp.PersistentFlags().BoolVarP(&debug, "debug", "d", false, "enable debug output") - // tmp.PersistentFlags().StringVarP(&format, "format", "f", "junit", "formating (default is junit)") return tmp } @@ -91,7 +89,7 @@ func InitConfig() { // and also the fully formatted command as passed with arguments/flags. // Idea borrowed from carolynvs/porter: // https://github.com/carolynvs/porter/blob/ccca10a63627e328616c1006600153da8411a438/cmd/porter/main.go -func GetCalledCommand(cmd *cobra.Command) (string, string) { +func GetCalledCommand(cmd *cobra.Command) (calledCmd string, calledArgs string) { if len(os.Args) < 2 { return "", "" } diff --git a/go.mod b/go.mod index 73cac56..78a9875 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/spf13/cobra v1.10.2 github.com/spf13/viper v1.21.0 github.com/stretchr/testify v1.11.1 + golang.org/x/text v0.28.0 gopkg.in/yaml.v2 v2.4.0 ) @@ -67,7 +68,6 @@ require ( golang.org/x/net v0.43.0 // indirect golang.org/x/sys v0.35.0 // indirect golang.org/x/term v0.34.0 // indirect - golang.org/x/text v0.28.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/internal/pkg/pct/pct.go b/internal/pkg/pct/pct.go index 11f468a..300a0a5 100644 --- a/internal/pkg/pct/pct.go +++ b/internal/pkg/pct/pct.go @@ -29,6 +29,8 @@ import ( "github.com/rs/zerolog/log" "github.com/spf13/afero" "github.com/spf13/viper" + "golang.org/x/text/cases" + "golang.org/x/text/language" "gopkg.in/yaml.v2" ) @@ -37,6 +39,11 @@ const ( TemplateConfigFileName = "pct-config.yml" UserTemplateConfigName = "pct" UserTemplateConfigFileName = "pct.yml" + + FormatTable = "table" + FormatJSON = "json" + + TemplateTypeProject = "project" ) // PuppetContentTemplateInfo is the housing struct for marshaling YAML data @@ -125,7 +132,7 @@ func (p *Pct) List(templatePath string, templateName string) []PuppetContentTemp log.Debug().Msgf("Found: %+v", file) i := p.readTemplateConfig(file).Template // Do not write id-less configs (ie, invalid, could not parse) to the return - if len(i.Id) > 0 { + if i.Id != "" { tmpls = append(tmpls, i) } } @@ -135,7 +142,7 @@ func (p *Pct) List(templatePath string, templateName string) []PuppetContentTemp log.Debug().Msgf("Found: %+v", file) i := p.readTemplateConfig(file).Template // Do not write id-less configs (ie, invalid, could not parse) to the return - if len(i.Id) > 0 { + if i.Id != "" { tmpls = append(tmpls, i) } } @@ -155,20 +162,21 @@ func (p *Pct) List(templatePath string, templateName string) []PuppetContentTemp func (*Pct) FormatTemplates(tmpls []PuppetContentTemplate, jsonOutput string) (string, error) { output := "" switch jsonOutput { - case "table": + case FormatTable: count := len(tmpls) - if count < 1 { + switch { + case count < 1: log.Warn().Msgf("Could not locate any templates at %+v", viper.GetString("templatepath")) - } else if count == 1 { + case count == 1: stringBuilder := &strings.Builder{} - stringBuilder.WriteString(fmt.Sprintf("DisplayName: %v\n", tmpls[0].Display)) - stringBuilder.WriteString(fmt.Sprintf("Author: %v\n", tmpls[0].Author)) - stringBuilder.WriteString(fmt.Sprintf("Name: %v\n", tmpls[0].Id)) - stringBuilder.WriteString(fmt.Sprintf("TemplateType: %v\n", tmpls[0].Type)) - stringBuilder.WriteString(fmt.Sprintf("TemplateURL: %v\n", tmpls[0].URL)) - stringBuilder.WriteString(fmt.Sprintf("TemplateVersion: %v\n", tmpls[0].Version)) + fmt.Fprintf(stringBuilder, "DisplayName: %v\n", tmpls[0].Display) + fmt.Fprintf(stringBuilder, "Author: %v\n", tmpls[0].Author) + fmt.Fprintf(stringBuilder, "Name: %v\n", tmpls[0].Id) + fmt.Fprintf(stringBuilder, "TemplateType: %v\n", tmpls[0].Type) + fmt.Fprintf(stringBuilder, "TemplateURL: %v\n", tmpls[0].URL) + fmt.Fprintf(stringBuilder, "TemplateVersion: %v\n", tmpls[0].Version) output = stringBuilder.String() - } else { + default: // > 1 stringBuilder := &strings.Builder{} table := tablewriter.NewTable(stringBuilder, tablewriter.WithRenderer(renderer.NewBlueprint(tw.Rendition{ @@ -177,12 +185,12 @@ func (*Pct) FormatTemplates(tmpls []PuppetContentTemplate, jsonOutput string) (s ) table.Header([]string{"DisplayName", "Author", "Name", "Type"}) for _, v := range tmpls { - table.Append([]string{v.Display, v.Author, v.Id, v.Type}) + _ = table.Append([]string{v.Display, v.Author, v.Id, v.Type}) } - table.Render() + _ = table.Render() output = stringBuilder.String() } - case "json": + case FormatJSON: j := jsoniter.ConfigFastest // This can't actually error because it's always getting a valid data struct; // if there are problems building the data struct for the template, we error @@ -199,7 +207,7 @@ func (*Pct) DisplayDefaults(defaults map[string]interface{}, format string) stri var prettyDefaults []byte switch format { - case "table": + case FormatTable: if len(defaults) == 0 { return "This template has no configuration options." } @@ -208,7 +216,7 @@ func (*Pct) DisplayDefaults(defaults map[string]interface{}, format string) stri if err != nil { log.Error().Msgf("Error converting to yaml: %v", err) } - case "json": + case FormatJSON: j := jsoniter.ConfigFastest prettyDefaults, err = j.MarshalIndent(defaults, "", " ") if err != nil { @@ -223,11 +231,11 @@ func (*Pct) DisplayDefaults(defaults map[string]interface{}, format string) stri // on the console in table format or json format. func (*Pct) FormatDeployment(deployed []string, jsonOutput string) error { switch jsonOutput { - case "table": + case FormatTable: for _, d := range deployed { log.Info().Msgf("Deployed: %v", d) } - case "json": + case FormatJSON: j := jsoniter.ConfigFastest prettyJSON, _ := j.MarshalIndent(deployed, "", " ") fmt.Printf("%s\n", prettyJSON) @@ -239,28 +247,28 @@ func (*Pct) FormatDeployment(deployed []string, jsonOutput string) error { // data from both the configuration inside the template and provided by the // User in their user config file func (p *Pct) Deploy(info DeployInfo) []string { - log.Trace().Msgf("PDKInfo: %+v", info.PdkInfo) log.Debug().Msgf("Template: %s", info.TemplateDirPath) tmpl := p.readTemplateConfig(filepath.Join(info.TemplateDirPath, TemplateConfigFileName)) log.Trace().Msgf("Parsed: %+v", tmpl) - if info.TargetName == "" && info.TargetOutputDir == "" { // pdk new foo-foo + switch { + case info.TargetName == "" && info.TargetOutputDir == "": // pdk new foo-foo cwd, _ := p.OsUtils.Getwd() info.TargetName = filepath.Base(cwd) info.TargetOutputDir = cwd - } else if info.TargetName != "" && info.TargetOutputDir == "" { // pdk new foo-foo -n wakka + case info.TargetName != "" && info.TargetOutputDir == "": // pdk new foo-foo -n wakka cwd, _ := p.OsUtils.Getwd() - if tmpl.Template.Type == "project" { + if tmpl.Template.Type == TemplateTypeProject { info.TargetOutputDir = filepath.Join(cwd, info.TargetName) } else { info.TargetOutputDir = cwd } - } else if info.TargetName == "" && info.TargetOutputDir != "" { // pdk new foo-foo -o /foo/bar/baz + case info.TargetName == "" && info.TargetOutputDir != "": // pdk new foo-foo -o /foo/bar/baz info.TargetName = filepath.Base(info.TargetOutputDir) - } else if info.TargetName != "" && info.TargetOutputDir != "" { // pdk new foo-foo -n wakka -o /foo/bar/baz - if tmpl.Template.Type == "project" { + default: // info.TargetName != "" && info.TargetOutputDir != "" // pdk new foo-foo -n wakka -o /foo/bar/baz + if tmpl.Template.Type == TemplateTypeProject { info.TargetOutputDir = filepath.Join(info.TargetOutputDir, info.TargetName) } } @@ -311,7 +319,7 @@ func (p *Pct) Deploy(info DeployInfo) []string { deployed = append(deployed, templateFile.TargetFilePath) } } else { - err := p.createTemplateFile(info, templateFile, tmpl.Template) + err := p.createTemplateFile(info, templateFile) if err != nil { log.Error().Msgf("%s", err) continue @@ -335,13 +343,9 @@ func (p *Pct) createTemplateDirectory(targetDir string) error { return nil } -func (p *Pct) createTemplateFile(info DeployInfo, templateFile PuppetContentTemplateFileInfo, tmpl PuppetContentTemplate) error { +func (p *Pct) createTemplateFile(info DeployInfo, templateFile PuppetContentTemplateFileInfo) error { log.Trace().Msgf("Creating: '%s'", templateFile.TargetFilePath) - config := p.processConfiguration( - info, - templateFile.TemplatePath, - tmpl, - ) + config := p.processConfiguration(info) text, err := p.renderFile(templateFile.TemplatePath, config) if err != nil { @@ -381,7 +385,7 @@ func (p *Pct) createTemplateFile(info DeployInfo, templateFile PuppetContentTemp return nil } -func (p *Pct) processConfiguration(info DeployInfo, projectTemplate string, tmpl PuppetContentTemplate) map[string]interface{} { +func (p *Pct) processConfiguration(info DeployInfo) map[string]interface{} { v := viper.New() log.Trace().Msgf("PDKInfo: %+v", info.PdkInfo) @@ -406,9 +410,9 @@ func (p *Pct) processConfiguration(info DeployInfo, projectTemplate string, tmpl // Convention based variables v.SetDefault("pct_name", info.TargetName) - user := p.getCurrentUser() - v.SetDefault("user", user) - v.SetDefault("puppet_module.author", user) + currentUser := p.getCurrentUser() + v.SetDefault("user", currentUser) + v.SetDefault("puppet_module.author", currentUser) // Machine based variables cwd, _ := os.Getwd() @@ -425,7 +429,6 @@ func (p *Pct) processConfiguration(info DeployInfo, projectTemplate string, tmpl configFile := filepath.Join(info.TemplateDirPath, TemplateConfigFileName) log.Trace().Msgf("Adding %v", filepath.Dir(configFile)) - // v.SetConfigFile(configFile) v.SetConfigName(TemplateConfigName) v.SetConfigType("yml") v.AddConfigPath(filepath.Dir(configFile)) @@ -483,10 +486,6 @@ func (p *Pct) readTemplateConfig(configFile string) PuppetContentTemplateInfo { v := viper.New() v.SetFs(p.AFS) v.SetConfigFile(configFile) - // userConfigFileBase := filepath.Base(configFile) - // v.AddConfigPath(filepath.Dir(configFile)) - // v.SetConfigName(strings.TrimSuffix(userConfigFileBase, filepath.Ext(userConfigFileBase))) - // v.SetConfigType("yml") if err := v.ReadInConfig(); err == nil { log.Trace().Msgf("Using template config file: %v", v.ConfigFileUsed()) @@ -518,7 +517,7 @@ func (p *Pct) renderFile(fileName string, vars interface{}) (string, error) { Funcs( template.FuncMap{ "toClassName": func(itemName string) string { - return strings.Title(strings.ToLower(itemName)) + return cases.Title(language.Und).String(itemName) }, }, ) @@ -597,10 +596,10 @@ func (p *Pct) filterNewestVersions(tt []PuppetContentTemplate) (ret []PuppetCont } func (p *Pct) getCurrentUser() string { - user, _ := user.Current() - if strings.Contains(user.Username, "\\") { - v := strings.Split(user.Username, "\\") + currentUser, _ := user.Current() + if strings.Contains(currentUser.Username, "\\") { + v := strings.Split(currentUser.Username, "\\") return v[1] } - return user.Username + return currentUser.Username } diff --git a/internal/pkg/pct/pct_test.go b/internal/pkg/pct/pct_test.go index f6706c0..2face1b 100644 --- a/internal/pkg/pct/pct_test.go +++ b/internal/pkg/pct/pct_test.go @@ -2,7 +2,7 @@ package pct_test import ( "encoding/json" - "io/ioutil" + "io" "os" "path/filepath" "reflect" @@ -20,7 +20,7 @@ import ( func TestMain(m *testing.M) { // hide logging output - log.Logger = zerolog.New(ioutil.Discard).With().Timestamp().Logger() + log.Logger = zerolog.New(io.Discard).With().Timestamp().Logger() os.Exit(m.Run()) } @@ -228,14 +228,14 @@ Summary: {{.example_replace.summary}}`, // Create the template contentDir := filepath.Join(tt.args.info.TemplateDirPath, "content") - afs.MkdirAll(contentDir, 0750) //nolint:errcheck + _ = afs.MkdirAll(contentDir, 0o0750) // Create template config config, _ := afs.Create(filepath.Join(tt.args.info.TemplateDirPath, "pct-config.yml")) - config.Write([]byte(tt.args.templateConfig)) //nolint:errcheck + _, _ = config.WriteString(tt.args.templateConfig) // Create the contents for file, content := range tt.args.templateContent { nf, _ := afs.Create(filepath.Join(contentDir, file)) - nf.Write([]byte(content)) //nolint:errcheck + _, _ = nf.WriteString(content) } p := &pct.Pct{ @@ -311,14 +311,14 @@ template: if tt.args.setup { // Create the template contentDir := filepath.Join(tt.args.templateDirPath, "content") - afs.MkdirAll(tt.args.templateDirPath, 0750) //nolint:errcheck + _ = afs.MkdirAll(tt.args.templateDirPath, 0o0750) // Create template config config, _ := afs.Create(filepath.Join(tt.args.templateDirPath, "pct-config.yml")) - config.Write([]byte(tt.args.templateConfig)) //nolint:errcheck + _, _ = config.WriteString(tt.args.templateConfig) // Create the contents for file, content := range tt.args.templateContent { nf, _ := afs.Create(filepath.Join(contentDir, file)) - nf.Write([]byte(content)) //nolint:errcheck + _, _ = nf.WriteString(content) } } @@ -434,7 +434,8 @@ func TestDisplayDefaults(t *testing.T) { var output map[string]interface{} var expected map[string]interface{} - if tt.format == "table" { + switch tt.format { + case "table": err := yaml.Unmarshal([]byte(returnString), &output) if err != nil { assert.Fail(t, "returned data is not YAML") @@ -444,7 +445,7 @@ func TestDisplayDefaults(t *testing.T) { if err != nil { assert.Fail(t, "expected data is not YAML") } - } else if tt.format == "json" { + case "json": err := json.Unmarshal([]byte(returnString), &output) if err != nil { assert.Fail(t, "returned data is not JSON") @@ -776,10 +777,10 @@ template: // Create the template for _, st := range tt.args.stubbedConfigs { templateDir := filepath.Join(tt.args.templatePath, st.relativeConfigPath) - afs.MkdirAll(templateDir, 0750) //nolint:errcheck + _ = afs.MkdirAll(templateDir, 0o0750) // Create template config config, _ := afs.Create(filepath.Join(templateDir, "pct-config.yml")) - config.Write([]byte(st.configContent)) //nolint:errcheck + _, _ = config.WriteString(st.configContent) } p := &pct.Pct{ @@ -951,7 +952,7 @@ template: // }, // }, // { -// name: "with a non existant config, returns default config", +// name: "with a non existent config, returns default config", // args: args{ // info: pct.DeployInfo{ // TargetName: "good-project", @@ -1023,7 +1024,7 @@ template: // }, // }, // { -// name: "returns empty struct from non-existant config file", +// name: "returns empty struct from non-existent config file", // args: args{ // configFile: "testdata/examples/does-not-exist-project/pct.yml", // }, @@ -1067,7 +1068,7 @@ template: // { // name: "returns nil if file does not exist", // args: args{ -// fileName: "testdata/examples/non-existant-project/content/notthere.txt.tmpl", +// fileName: "testdata/examples/non-existent-project/content/notthere.txt.tmpl", // vars: map[string]interface{}{ // "example_data": "wakka", // }, diff --git a/internal/pkg/pct_config_processor/pct_config_processor.go b/internal/pkg/pct_config_processor/pct_config_processor.go index 9222591..4ab698a 100644 --- a/internal/pkg/pct_config_processor/pct_config_processor.go +++ b/internal/pkg/pct_config_processor/pct_config_processor.go @@ -45,13 +45,13 @@ func (p *PctConfigProcessor) CheckConfig(configFile string) error { // These parts are essential for build and deployment. if info.Template.Id == "" { - msg = msg + " * id\n" + msg += " * id\n" } if info.Template.Author == "" { - msg = msg + " * author\n" + msg += " * author\n" } if info.Template.Version == "" { - msg = msg + " * version\n" + msg += " * version\n" } if msg != orig { return errors.New(msg) diff --git a/internal/pkg/pct_config_processor/pct_config_processor_test.go b/internal/pkg/pct_config_processor/pct_config_processor_test.go index 8b5c15d..0f804c2 100644 --- a/internal/pkg/pct_config_processor/pct_config_processor_test.go +++ b/internal/pkg/pct_config_processor/pct_config_processor_test.go @@ -118,9 +118,9 @@ foo: bar if tt.mockConfigFile { dir := filepath.Dir(tt.configFilePath) - afs.Mkdir(dir, 0750) //nolint:gosec,errcheck // this result is not used in a secure application - config, _ := afs.Create(tt.configFilePath) //nolint:gosec,errcheck // this result is not used in a secure application - config.Write([]byte(tt.configFileYaml)) //nolint:errcheck + _ = afs.Mkdir(dir, 0o0750) + config, _ := afs.Create(tt.configFilePath) + _, _ = config.WriteString(tt.configFileYaml) } configProcessor := pct_config_processor.PctConfigProcessor{AFS: afs} @@ -200,10 +200,10 @@ template: } // Create all useful directories - afs.MkdirAll(configParentPath, 0750) //nolint:gosec,errcheck + _ = afs.MkdirAll(configParentPath, 0o0750) if tt.templateConfig != "" { config, _ := afs.Create(tt.args.configFile) - config.Write([]byte(tt.templateConfig)) //nolint:errcheck + _, _ = config.WriteString(tt.templateConfig) } gotMetadata, err := p.GetConfigMetadata(tt.args.configFile) @@ -283,10 +283,10 @@ template: } // Create all useful directories - afs.MkdirAll(configParentPath, 0750) //nolint:gosec,errcheck + _ = afs.MkdirAll(configParentPath, 0o0750) if tt.templateConfig != "" { config, _ := afs.Create(tt.args.configFile) - config.Write([]byte(tt.templateConfig)) //nolint:errcheck + _, _ = config.WriteString(tt.templateConfig) } gotInfo, err := p.ReadConfig(tt.args.configFile) diff --git a/pkg/build/build_test.go b/pkg/build/build_test.go index 166d33b..48c2082 100644 --- a/pkg/build/build_test.go +++ b/pkg/build/build_test.go @@ -13,7 +13,6 @@ import ( ) func TestBuild(t *testing.T) { - type args struct { projectPath string targetDir string @@ -228,17 +227,16 @@ template: } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - fs := afero.NewMemMapFs() afs := &afero.Afero{Fs: fs} for _, path := range tt.mockDirs { - afs.Mkdir(path, 0750) //nolint:gosec,errcheck // this result is not used in a secure application + _ = afs.Mkdir(path, 0o0750) } for file, content := range tt.mockFiles { - config, _ := afs.Create(file) //nolint:gosec,errcheck // this result is not used in a secure application - config.Write([]byte(content)) //nolint:errcheck + config, _ := afs.Create(file) + _, _ = config.WriteString(content) } p := &build.Builder{ diff --git a/pkg/docs/docs.go b/pkg/docs/docs.go index 9f17ca0..c0ceffa 100644 --- a/pkg/docs/docs.go +++ b/pkg/docs/docs.go @@ -95,7 +95,7 @@ func (d *Docs) FindAndParse(docsFolderPath string) { if err != nil { log.Warn().Msgf("Could not parse %s", entryPath) // Some docs might need to be skipped in terminal - } else if skip, _ := fm["skipTerminal"]; skip != true { //nolint + } else if fm["skipTerminal"] != true { // Turn the tags into an array of strings for further use tagsAsInterface := fm["tags"].([]interface{}) tags := make([]string, len(tagsAsInterface)) diff --git a/pkg/exec_runner/exec_runner.go b/pkg/exec_runner/exec_runner.go index b4ae651..e0c660c 100644 --- a/pkg/exec_runner/exec_runner.go +++ b/pkg/exec_runner/exec_runner.go @@ -8,6 +8,10 @@ import ( "github.com/rs/zerolog/log" ) +const ( + GOOSWindows = "windows" +) + type ExecI interface { Command(name string, arg ...string) error Output() ([]byte, error) @@ -21,7 +25,7 @@ func (e *Exec) Command(name string, arg ...string) error { var pathToExecutable string var err error - if runtime.GOOS == "windows" { + if runtime.GOOS == GOOSWindows { pathToExecutable, err = exec.LookPath("cmd.exe") } else { pathToExecutable, err = exec.LookPath(name) @@ -49,7 +53,7 @@ func (e *Exec) Output() ([]byte, error) { func buildCommandArgs(commandName string, args []string) []string { var a []string - if runtime.GOOS == "windows" { + if runtime.GOOS == GOOSWindows { a = append(a, "/c") } a = append(a, commandName) diff --git a/pkg/gzip/gunzip_test.go b/pkg/gzip/gunzip_test.go index 06781bb..a797a6a 100644 --- a/pkg/gzip/gunzip_test.go +++ b/pkg/gzip/gunzip_test.go @@ -57,8 +57,8 @@ func TestGunzip(t *testing.T) { afs := &afero.Afero{Fs: fs} for file, content := range tt.mockFiles { - config, _ := afs.Create(file) //nolint:gosec,errcheck // this result is not used in a secure application - config.Write([]byte(content)) //nolint:errcheck + config, _ := afs.Create(file) + _, _ = config.Write(content) } g := &gzip.Gunzip{AFS: afs} @@ -72,8 +72,6 @@ func TestGunzip(t *testing.T) { _, err = afs.Stat(tt.expectedTarFilePath) assert.NoError(t, err) - }) } - } diff --git a/pkg/gzip/gzip.go b/pkg/gzip/gzip.go index bd20d18..9fe1d23 100644 --- a/pkg/gzip/gzip.go +++ b/pkg/gzip/gzip.go @@ -24,7 +24,7 @@ func (g *Gzip) Gzip(source, target string) (gzipFilePath string, err error) { return "", err } - err = g.AFS.MkdirAll(target, 0750) + err = g.AFS.MkdirAll(target, 0o0750) if err != nil { return "", err } diff --git a/pkg/gzip/gzip_test.go b/pkg/gzip/gzip_test.go index 39d2251..388af5f 100644 --- a/pkg/gzip/gzip_test.go +++ b/pkg/gzip/gzip_test.go @@ -36,10 +36,9 @@ func TestGzip(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - // mock the tarball f, _ := afs.Create(tt.args.source) - f.WriteString("tar contents") //nolint:errcheck + _, _ = f.WriteString("tar contents") // Initialize gzip with our mock filesystem g := &gzip.Gzip{ diff --git a/pkg/install/install.go b/pkg/install/install.go index 101022e..9999b4b 100644 --- a/pkg/install/install.go +++ b/pkg/install/install.go @@ -190,7 +190,7 @@ func (p *Installer) InstallFromConfig(configFile, targetDir string, force bool) // Create namespaced directory and move contents of temp folder to it installedPkgPath := filepath.Join(targetDir, info.Author, info.Id) - err = p.AFS.MkdirAll(installedPkgPath, 0750) + err = p.AFS.MkdirAll(installedPkgPath, 0o0750) if err != nil { return "", err } diff --git a/pkg/install/install_test.go b/pkg/install/install_test.go index ec497a6..3371146 100644 --- a/pkg/install/install_test.go +++ b/pkg/install/install_test.go @@ -3,14 +3,13 @@ package install_test import ( "bytes" "fmt" - "io/ioutil" + "io" "net/http" "path" "path/filepath" "testing" "github.com/jay7x/pct/pkg/config_processor" - "github.com/jay7x/pct/pkg/install" "github.com/jay7x/pct/pkg/mock" "github.com/spf13/afero" @@ -282,7 +281,7 @@ func TestInstall(t *testing.T) { RequestResponse: &http.Response{ StatusCode: 404, // We still need the body to exist and be a reader, just with empty bytes - Body: ioutil.NopCloser(bytes.NewReader([]byte{})), + Body: io.NopCloser(bytes.NewReader([]byte{})), }, }, }, @@ -316,7 +315,7 @@ func TestInstall(t *testing.T) { get: mock.GetResponse{ RequestResponse: &http.Response{ StatusCode: 200, - Body: ioutil.NopCloser(bytes.NewReader(tarballBytes)), + Body: io.NopCloser(bytes.NewReader(tarballBytes)), }, }, }, @@ -424,17 +423,16 @@ func TestInstall(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - fs := afero.NewMemMapFs() afs := &afero.Afero{Fs: fs} for _, path := range tt.mocks.dirs { - afs.Mkdir(path, 0750) //nolint:gosec,errcheck // this result is not used in a secure application + _ = afs.Mkdir(path, 0o0750) } for file, content := range tt.mocks.files { - config, _ := afs.Create(file) //nolint:gosec,errcheck // this result is not used in a secure application - config.Write([]byte(content)) //nolint:errcheck + config, _ := afs.Create(file) + _, _ = config.WriteString(content) } installer := &install.Installer{ @@ -497,7 +495,7 @@ func TestInstaller_InstallFromConfig(t *testing.T) { }, args: args{configFile: filepath.Join(extractionPath, "pct-config.yml"), targetDir: extractionPath}, expected: expected{ - filepath: filepath.Join(extractionPath, "puppetlabs/good-project/0.1.0"), + filepath: filepath.Join(extractionPath, "puppetlabs", "good-project", "0.1.0"), }, mocks: mocks{ dirs: []string{ @@ -526,71 +524,70 @@ func TestInstaller_InstallFromConfig(t *testing.T) { }, }, // Neither of these tests work. Most likely a problem with the AFS.Rename(path1, path2) function (pkg/install/install.go:202) - //{ - // name: "Force installs over a template with the same namespaced path", - // mockInstallConfig: mockInstallConfig{ - // metadata: config_processor.ConfigMetadata{ - // Author: "puppetlabs", - // Id: "good-project", - // Version: "0.1.0", - // }, - // expectedConfigFile: filepath.Join(extractionPath, "good-project", "pct-config.yml"), - // }, - // args: args{configFile: filepath.Join(extractionPath, "pct-config.yml"), targetDir: extractionPath, force: true}, - // expected: expected{ - // filepath: filepath.Join(extractionPath, "puppetlabs/good-project/0.1.0"), - // }, - // mocks: mocks{ - // dirs: []string{ - // extractionPath, - // }, - // files: map[string]string{ // Writes a config file to namespaced path to simulate a previously installed template - // filepath.Join(extractionPath, "puppetlabs/good-project/0.1.0/pct-config.yml"): "", - // filepath.Join(extractionPath, "good-project", "pct-config.yml"): "", - // }, - // }, - //}, - //{ - // name: "Fails to install as a template already exists on the namespaced path and force is false", - // mockInstallConfig: mockInstallConfig{ - // metadata: config_processor.ConfigMetadata{ - // Author: "puppetlabs", - // Id: "good-project", - // Version: "0.1.0", - // }, - // expectedConfigFile: filepath.Join(extractionPath, "good-project", "pct-config.yml"), - // }, - // args: args{configFile: filepath.Join(extractionPath, "good-project", "pct-config.yml"), targetDir: extractionPath, force: false}, - // expected: expected{ - // filepath: filepath.Join(extractionPath, "puppetlabs/good-project/0.1.0"), - // errorMsg: "Template already installed", - // }, - // mocks: mocks{ - // dirs: []string{ - // extractionPath, - // filepath.Join(extractionPath, "puppetlabs/good-project/0.1.0"), - // }, - // files: map[string]string{ // Writes a config file to namespaced path to simulate a previously installed template - // filepath.Join(extractionPath, "puppetlabs/good-project/0.1.0/pct-config.yml"): "test1", - // filepath.Join(extractionPath, "puppetlabs/good-project/0.1.0/content/testfile"): "test1", - // filepath.Join(extractionPath, "good-project", "pct-config.yml"): "test2", - // }, - // }, - //}, + // { + // name: "Force installs over a template with the same namespaced path", + // mockInstallConfig: mockInstallConfig{ + // metadata: config_processor.ConfigMetadata{ + // Author: "puppetlabs", + // Id: "good-project", + // Version: "0.1.0", + // }, + // expectedConfigFile: filepath.Join(extractionPath, "good-project", "pct-config.yml"), + // }, + // args: args{configFile: filepath.Join(extractionPath, "pct-config.yml"), targetDir: extractionPath, force: true}, + // expected: expected{ + // filepath: filepath.Join(extractionPath, "puppetlabs/good-project/0.1.0"), + // }, + // mocks: mocks{ + // dirs: []string{ + // extractionPath, + // }, + // files: map[string]string{ // Writes a config file to namespaced path to simulate a previously installed template + // filepath.Join(extractionPath, "puppetlabs/good-project/0.1.0/pct-config.yml"): "", + // filepath.Join(extractionPath, "good-project", "pct-config.yml"): "", + // }, + // }, + // }, + // { + // name: "Fails to install as a template already exists on the namespaced path and force is false", + // mockInstallConfig: mockInstallConfig{ + // metadata: config_processor.ConfigMetadata{ + // Author: "puppetlabs", + // Id: "good-project", + // Version: "0.1.0", + // }, + // expectedConfigFile: filepath.Join(extractionPath, "good-project", "pct-config.yml"), + // }, + // args: args{configFile: filepath.Join(extractionPath, "good-project", "pct-config.yml"), targetDir: extractionPath, force: false}, + // expected: expected{ + // filepath: filepath.Join(extractionPath, "puppetlabs/good-project/0.1.0"), + // errorMsg: "Template already installed", + // }, + // mocks: mocks{ + // dirs: []string{ + // extractionPath, + // filepath.Join(extractionPath, "puppetlabs/good-project/0.1.0"), + // }, + // files: map[string]string{ // Writes a config file to namespaced path to simulate a previously installed template + // filepath.Join(extractionPath, "puppetlabs/good-project/0.1.0/pct-config.yml"): "test1", + // filepath.Join(extractionPath, "puppetlabs/good-project/0.1.0/content/testfile"): "test1", + // filepath.Join(extractionPath, "good-project", "pct-config.yml"): "test2", + // }, + // }, + // }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - fs := afero.NewMemMapFs() afs := &afero.Afero{Fs: fs} for _, path := range tt.mocks.dirs { - afs.Mkdir(path, 0750) //nolint:gosec,errcheck // this result is not used in a secure application + _ = afs.Mkdir(path, 0o0750) } for file, content := range tt.mocks.files { - config, _ := afs.Create(file) //nolint:gosec,errcheck // this result is not used in a secure application - config.Write([]byte(content)) //nolint:errcheck + config, _ := afs.Create(file) + _, _ = config.WriteString(content) } p := &install.Installer{ diff --git a/pkg/mock/gunzip.go b/pkg/mock/gunzip.go index 2bd6089..aa02319 100644 --- a/pkg/mock/gunzip.go +++ b/pkg/mock/gunzip.go @@ -35,7 +35,7 @@ func (g *Gunzip) Gunzip(source, target string) (string, error) { if !g.GunzipResponse[g.gunzipCalled].Fail { afs := &afero.Afero{Fs: g.Fs} tar := strings.TrimSuffix(filepath.Join(target, filepath.Base(source)), ".gz") - afs.Create(tar) // nolint:errcheck // #nosec // this result is not used in a secure application + _, _ = afs.Create(tar) } path := g.GunzipResponse[g.gunzipCalled].FilePath diff --git a/pkg/mock/tar.go b/pkg/mock/tar.go index 7a79cf5..d6f3870 100644 --- a/pkg/mock/tar.go +++ b/pkg/mock/tar.go @@ -17,7 +17,6 @@ type Tar struct { } func (t *Tar) Tar(source, target string) (tarFilePath string, err error) { - if t.ErrResponse { return "", fmt.Errorf("tar error") } diff --git a/pkg/tar/tar.go b/pkg/tar/tar.go index 17cdb20..37c4e2a 100644 --- a/pkg/tar/tar.go +++ b/pkg/tar/tar.go @@ -129,7 +129,7 @@ func (t *Tar) Untar(tarball, target string) (outputDirPath string, err error) { path := filepath.Join(target, filepath.Clean(header.Name)) info := header.FileInfo() if info.IsDir() { - if err = t.AFS.MkdirAll(filepath.Clean(path), info.Mode()); err != nil { + if err := t.AFS.MkdirAll(filepath.Clean(path), info.Mode()); err != nil { return "", err } continue @@ -137,7 +137,7 @@ func (t *Tar) Untar(tarball, target string) (outputDirPath string, err error) { file, err := t.AFS.OpenFile(filepath.Clean(path), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, info.Mode()) - defer func() { + defer func() { //nolint:gocritic // this defer func() is in the loop by purpose (see t.AFS.OpenFile() above) if err := file.Close(); err != nil { log.Error().Msgf("Error closing file: %s", err) } diff --git a/pkg/tar/tar_test.go b/pkg/tar/tar_test.go index 1d80678..3229234 100644 --- a/pkg/tar/tar_test.go +++ b/pkg/tar/tar_test.go @@ -9,7 +9,6 @@ import ( ) func TestTar(t *testing.T) { - tempDir := t.TempDir() type args struct { @@ -35,13 +34,12 @@ func TestTar(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - fs := afero.NewMemMapFs() afs := &afero.Afero{Fs: fs} - afs.MkdirAll(tt.args.source, 0750) //nolint:errcheck + _ = afs.MkdirAll(tt.args.source, 0o0750) - tar := &tar.Tar{AFS: afs} - tarFilePath, err := tar.Tar(tt.args.source, tt.args.target) + myTar := &tar.Tar{AFS: afs} + tarFilePath, err := myTar.Tar(tt.args.source, tt.args.target) if err != nil != tt.wantErr { t.Errorf("Tar() error = %v, wantErr %v", err, tt.wantErr) @@ -55,7 +53,6 @@ func TestTar(t *testing.T) { } func TestUntar(t *testing.T) { - fs := afero.NewMemMapFs() afs := &afero.Afero{Fs: fs} @@ -88,7 +85,6 @@ func TestUntar(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - // mock the tarball f, _ := afs.Create(tt.args.tarball) tarballBytes := []byte{ @@ -381,11 +377,11 @@ func TestUntar(t *testing.T) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, } - f.Write(tarballBytes) //nolint:errcheck + _, _ = f.Write(tarballBytes) - tar := &tar.Tar{afs} + myTar := &tar.Tar{afs} - path, err := tar.Untar(tt.args.tarball, tt.args.target) + path, err := myTar.Untar(tt.args.tarball, tt.args.target) if (err != nil) != tt.wantErr { t.Errorf("Untar() error = %v, wantErr %v", err, tt.wantErr) } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index cba7d65..33c53ee 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -2,10 +2,11 @@ package utils import ( "fmt" - "github.com/rs/zerolog/log" "io" "os" "path/filepath" + + "github.com/rs/zerolog/log" ) // contains checks if a string is present in a slice