Skip to content

Commit

Permalink
Merge branch 'gofumpt'
Browse files Browse the repository at this point in the history
  • Loading branch information
fho committed Nov 12, 2024
2 parents 02bd4d6 + e8f217a commit b78444b
Show file tree
Hide file tree
Showing 44 changed files with 72 additions and 85 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ linters:
- errorlint
- gocritic
- godox
- gofumpt
- goimports
- goprintffuncname
- gosimple
Expand All @@ -36,3 +37,6 @@ linters-settings:
godox:
keywords:
- FIXME
gofumpt:
module-path: github.com/simplesurance/baur/v5
extra-rules: true
16 changes: 9 additions & 7 deletions internal/command/diff_inputs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import (
"github.com/simplesurance/baur/v5/internal/testutils/repotest"
)

var appOneName = "app-one"
var appTwoName = "app-two"
var buildTaskName = "build"
var testTaskName = "test"
var appOneWithBuildTask = fmt.Sprintf("%s.%s", appOneName, buildTaskName)
var appOneWithTestTask = fmt.Sprintf("%s.%s", appOneName, testTaskName)
var appTwoWithBuildTask = fmt.Sprintf("%s.%s", appTwoName, buildTaskName)
var (
appOneName = "app-one"
appTwoName = "app-two"
buildTaskName = "build"
testTaskName = "test"
appOneWithBuildTask = fmt.Sprintf("%s.%s", appOneName, buildTaskName)
appOneWithTestTask = fmt.Sprintf("%s.%s", appOneName, testTaskName)
appTwoWithBuildTask = fmt.Sprintf("%s.%s", appTwoName, buildTaskName)
)

func doInitDb(t *testing.T) {
t.Helper()
Expand Down
3 changes: 1 addition & 2 deletions internal/command/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ func mustNewCompatibleStorage(uri string) storage.Storer {
fatal("baur postgresql database not found\n" +
" - ensure that the postgresql URL is correct,\n" +
" - run 'baur init db' to create the database and schema")

}
clt.Close()
exitOnErr(err)
Expand Down Expand Up @@ -315,7 +314,7 @@ func mustTaskRepoRelPath(repositoryDir string, task *baur.Task) string {
return path
}

func subStr(input string, start int, length int) string {
func subStr(input string, start, length int) string {
asRunes := []rune(input)

if start >= len(asRunes) {
Expand Down
1 change: 0 additions & 1 deletion internal/command/ls_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func newLsAppsCmd() *lsAppsCmd {
}

return &cmd

}

func (c *lsAppsCmd) createHeader() []string {
Expand Down
3 changes: 0 additions & 3 deletions internal/command/ls_runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ func (c *lsRunsCmd) run(_ *cobra.Command, args []string) {
return nil
},
)

if err != nil {
if errors.Is(err, storage.ErrNotExist) {
stderr.Println("no matching task runs exist")
Expand Down Expand Up @@ -253,7 +252,6 @@ func (c *lsRunsCmd) getFilters() []*storage.Filter {
}

if c.input != "" {

if strings.HasPrefix(c.input, "string:") {
filters = append(filters, &storage.Filter{
Field: storage.FieldInputString,
Expand All @@ -267,7 +265,6 @@ func (c *lsRunsCmd) getFilters() []*storage.Filter {
Value: c.input,
})
}

}

return filters
Expand Down
16 changes: 10 additions & 6 deletions internal/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ var rootCmd = &cobra.Command{
PersistentPreRun: initSb,
}

var verboseFlag bool
var cpuProfilingFlag bool
var noColorFlag bool
var repositoryPath string
var (
verboseFlag bool
cpuProfilingFlag bool
noColorFlag bool
repositoryPath string
)

var defCPUProfFile = filepath.Join(os.TempDir(), "baur-cpu.prof")

var ctx = context.Background()

var stdout = term.NewStream(os.Stdout)
var stderr = term.NewStream(os.Stderr)
var (
stdout = term.NewStream(os.Stdout)
stderr = term.NewStream(os.Stderr)
)

var exitFunc = func(code int) { os.Exit(code) }

Expand Down
15 changes: 7 additions & 8 deletions internal/command/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestRunSimultaneously(t *testing.T) {
// checkScript is exected by the tasks, it logs the start and end
// timestamp of the script to file.
// The test checks if all task start/endtimestamps are in the same period.
var checkScript = []byte(`#!/usr/bin/env bash
checkScript := []byte(`#!/usr/bin/env bash
set -veu -o pipefail
runtime_logfile="$1"
Expand All @@ -48,7 +48,7 @@ date +%s >> "$runtime_logfile"
err := os.WriteFile(
filepath.Join(r.Dir, fmt.Sprintf("checkscript%d.sh", i)),
checkScript,
0755,
0o755,
)
require.NoError(t, err)

Expand Down Expand Up @@ -129,13 +129,12 @@ func TestRunShowOutput(t *testing.T) {
scriptPath, []byte(`#/usr/bin/env bash
echo "greetings from script.sh"
`),
0755)
0o755)
require.NoError(t, err)

appCfg := cfg.App{
Name: "testapp",
Tasks: cfg.Tasks{{

Name: "build",
Command: []string{"bash", scriptPath},
Input: cfg.Input{
Expand Down Expand Up @@ -172,13 +171,12 @@ func TestRunShowOutputOnErrorOutputIsPrintedOnce(t *testing.T) {
echo "I will fail!"
exit 1
`),
0755)
0o755)
require.NoError(t, err)

appCfg := cfg.App{
Name: "testapp",
Tasks: cfg.Tasks{{

Name: "build",
Command: []string{"bash", scriptPath},
Input: cfg.Input{
Expand Down Expand Up @@ -221,7 +219,7 @@ func createEnvVarTestApp(t *testing.T, appName, taskName string, envVarsCfg []cf
scriptPath, []byte(`#/usr/bin/env bash
exit 0
`),
0755)
0o755)
require.NoError(t, err)
doInitDb(t)

Expand Down Expand Up @@ -286,7 +284,8 @@ func TestEnvVarInput_Required(t *testing.T) {
stdout, _ = interceptCmdOutput(t)
statusCmd := newStatusCmd()
statusCmd.SetArgs([]string{
"--format=csv", "-q", "-f", "run-id", fmt.Sprintf("%s.%s", appName, taskName)},
"--format=csv", "-q", "-f", "run-id", fmt.Sprintf("%s.%s", appName, taskName),
},
)
require.NoError(t, statusCmd.Execute())
runID := strings.TrimSpace(stdout.String())
Expand Down
1 change: 0 additions & 1 deletion internal/command/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func TestShowArgs(t *testing.T) {

showCmd.Command.Run(&showCmd.Command, []string{"."})
})

}

func TestShowWithRepositoryArg(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/command/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func (c *statusCmd) statusCreateHeader() []string {

return headers
}

func (c *statusCmd) jsonFieldNames() []string {
headers := make([]string, 0, len(c.fields.Fields))

Expand Down Expand Up @@ -299,7 +300,6 @@ func (c *statusCmd) assembleRow(repositoryDir string, task *baur.Task, taskRun *
row = append(row, nil)
}
}

}
return row
}
2 changes: 1 addition & 1 deletion internal/command/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestStatusTaskSpecArgParsing(t *testing.T) {
},
preRun: func(t *testing.T) {
childDir := filepath.Join(repoDir, "app3", uuid.New().String())
require.NoError(t, os.Mkdir(childDir, 0700))
require.NoError(t, os.Mkdir(childDir, 0o700))

t.Cleanup(func() {
require.NoError(t, os.RemoveAll(childDir))
Expand Down
1 change: 1 addition & 0 deletions internal/command/term/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func evalOptions(opts []FormatOption) *fmtSettings {

return &s
}

func FormatSize(bytes uint64, opts ...FormatOption) string {
if evalOptions(opts).baseUnitWithoutUnitName {
return fmt.Sprint(bytes)
Expand Down
1 change: 0 additions & 1 deletion internal/command/upgrade_configs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func TestUpgrade(t *testing.T) {
require.NoError(t, err)
require.EqualValues(t, repoCfg.Database, repoCfgLoaded.Database)
require.EqualValues(t, repoCfg.Discover, repoCfgLoaded.Discover)

})
}
}
1 change: 0 additions & 1 deletion internal/digest/digest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ func TestFromString(t *testing.T) {
if d.String() != shash {
t.Errorf("String() returned %q expected %q", d.String(), shash)
}

}
6 changes: 4 additions & 2 deletions internal/exec/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (
"github.com/fatih/color"
)

const maxErrOutputBytesPerStream = 16 * 1024
const outputStreamLineReaderBufSiz = 512 * 1024
const (
maxErrOutputBytesPerStream = 16 * 1024
outputStreamLineReaderBufSiz = 512 * 1024
)

type PrintfFn func(format string, a ...any)

Expand Down
2 changes: 0 additions & 2 deletions internal/exec/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func TestCombinedStdoutOutput(t *testing.T) {
var err error
if runtime.GOOS == "windows" {
res, err = Command("bash", "-c", fmt.Sprintf("echo -n '%s'", echoStr)).RunCombinedOut(ctx)

} else {
res, err = Command("echo", "-n", echoStr).RunCombinedOut(ctx)
}
Expand Down Expand Up @@ -71,5 +70,4 @@ func TestOutputStream(t *testing.T) {
LogFn(func(f string, a ...any) { fmt.Fprintf(&buf, f, a...) }).ExpectSuccess().Run(ctx)
require.NoError(t, err)
require.Contains(t, buf.String(), echoStr)

}
3 changes: 1 addition & 2 deletions internal/exec/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type ExitCodeError struct {

type SprintFn func(...any) string

func (e *ExitCodeError) ColoredError(highlightFn SprintFn, errorFn SprintFn, withCmdOutput bool) string {
func (e *ExitCodeError) ColoredError(highlightFn, errorFn SprintFn, withCmdOutput bool) string {
var result strings.Builder
var stdoutExists bool

Expand Down Expand Up @@ -58,7 +58,6 @@ func (e *ExitCodeError) ColoredError(highlightFn SprintFn, errorFn SprintFn, wit
// Error returns the error description.
func (e *ExitCodeError) Error() string {
return e.ColoredError(fmt.Sprint, fmt.Sprint, true)

}

// Result describes the result of a run Cmd.
Expand Down
1 change: 0 additions & 1 deletion internal/fs/fileglob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ func Test_Resolve(t *testing.T) {

checkFilesInResolvedFiles(t, tempdir, resolvedFiles, tc)
}

}

func TestGlobMatch(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func FileSize(path string) (int64, error) {

// Mkdir creates recursively directories
func Mkdir(path string) error {
return os.MkdirAll(path, os.FileMode(0755))
return os.MkdirAll(path, os.FileMode(0o755))
}

// AbsPaths ensures that all elements in paths are absolute paths.
Expand All @@ -225,7 +225,7 @@ func AbsPaths(rootPath string, paths []string) []string {

// AbsPath ensures that path is an absolute path.
// If it isn't, it is joined with rootPath.
func AbsPath(rootPath string, path string) string {
func AbsPath(rootPath, path string) string {
if filepath.IsAbs(path) {
return path
}
Expand Down
2 changes: 1 addition & 1 deletion internal/fs/fs_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ func FileHasOwnerExecPerm(p string) (bool, error) {

// OwnerHasExecPerm returns true if the executable mode bit in m is set.
func OwnerHasExecPerm(m fs.FileMode) bool {
return m&0100 == 0100
return m&0o100 == 0o100
}
6 changes: 4 additions & 2 deletions internal/output/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import (
)

// DefaultRegistry is the registry for that authentication data is used
const DefaultRegistry = "https://index.docker.io/v1/"
const dockerRegistryDefaultPort = "5000"
const (
DefaultRegistry = "https://index.docker.io/v1/"
dockerRegistryDefaultPort = "5000"
)

// Client is a docker client
type Client struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/output/filecopy/filecopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func copyFile(src, dst string) error {
// If the destination directory does not exist, it is created.
// If the destination path exist and is not a regular file an error is returned.
// If it exists, is a file and it differs the file is overwritten.
func (c *Client) Upload(src string, dst string) (string, error) {
func (c *Client) Upload(src, dst string) (string, error) {
destDir := filepath.Dir(dst)

isDir, err := fs.IsDir(destDir)
Expand Down
2 changes: 1 addition & 1 deletion internal/output/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (c *Client) Upload(filepath, bucket, key string) (string, error) {
}

func (c *Client) Download(ctx context.Context, bucket, key, filepath string) error {
f, err := os.OpenFile(filepath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0640)
f, err := os.OpenFile(filepath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o640)
if err != nil {
return err
}
Expand Down
6 changes: 4 additions & 2 deletions internal/resolve/gosource/gosource.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import (
"github.com/simplesurance/baur/v5/internal/fs"
)

const globQueryPrefix = "fileglob="
const fileQueryPrefix = "file="
const (
globQueryPrefix = "fileglob="
fileQueryPrefix = "file="
)

var defLogFn = func(string, ...any) {}

Expand Down
1 change: 0 additions & 1 deletion internal/routines/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func TestScheduleAndWait(t *testing.T) {
for i := range workDone {
assert.Equal(t, int32(1), atomic.LoadInt32(&workDone[i]), "work %d not done", i)
}

}

func TestQueuePanicsAfterWait(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions internal/testutils/fstest/fstest.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import (
// If an error happens, t.Fatal() is called.
func WriteExecutable(t *testing.T, data []byte, path string) {
t.Helper()
writeToFile(t, data, path, 0755)
writeToFile(t, data, path, 0o755)
}

// WriteToFile writes data to a file.
// Directories that are in the path but do not exist are created.
// If an error happens, t.Fatal() is called.
func WriteToFile(t *testing.T, data []byte, path string) {
t.Helper()
writeToFile(t, data, path, 0644)
writeToFile(t, data, path, 0o644)
}

func writeToFile(t *testing.T, data []byte, path string, perm fs.FileMode) {
Expand All @@ -37,7 +37,7 @@ func writeToFile(t *testing.T, data []byte, path string, perm fs.FileMode) {
}

func MkdirAll(t *testing.T, path string) {
err := os.MkdirAll(path, 0775)
err := os.MkdirAll(path, 0o775)
if err != nil {
t.Fatal(err)
}
Expand Down
Loading

0 comments on commit b78444b

Please sign in to comment.