From 56d2c8b6f7570f267655c625ebde5c9404c7b0fd Mon Sep 17 00:00:00 2001 From: Kirill Zhuravlev Date: Fri, 3 Jan 2025 21:21:44 +0100 Subject: [PATCH 01/13] tests for Duration --- cmd/toolset/main.go | 45 ++----------------------- internal/timeh/duration.go | 58 +++++++++++++++++++++++++++++++++ internal/timeh/duration_test.go | 56 +++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 42 deletions(-) create mode 100644 internal/timeh/duration.go create mode 100644 internal/timeh/duration_test.go diff --git a/cmd/toolset/main.go b/cmd/toolset/main.go index a7b2514..ce8ca38 100644 --- a/cmd/toolset/main.go +++ b/cmd/toolset/main.go @@ -7,6 +7,8 @@ import ( "strings" "time" + "github.com/kazhuravlev/toolset/internal/timeh" + "github.com/kazhuravlev/optional" "github.com/kazhuravlev/toolset/internal/fsh" @@ -454,7 +456,7 @@ func cmdList(c *cli.Context) error { for _, ts := range tools { lastUse := "---" if val, ok := ts.LastUse.Get(); ok { - lastUse = duration(time.Since(val)) + lastUse = timeh.Duration(time.Since(val)) } rows = append(rows, table.Row{ @@ -553,44 +555,3 @@ func cmdRemove(c *cli.Context) error { return nil } - -func duration(d time.Duration) string { - if d == 0 { - return "0s" - } - - days := d / (24 * time.Hour) - d -= days * 24 * time.Hour - - hours := d / time.Hour - d -= hours * time.Hour - - minutes := d / time.Minute - d -= minutes * time.Minute - - seconds := d / time.Second - - // Build the human-readable string - var result string - if days > 0 { - result += fmt.Sprintf("%dd ", days) - } - - if hours > 0 { - result += fmt.Sprintf("%dh ", hours) - } - - if minutes > 0 { - result += fmt.Sprintf("%dm ", minutes) - } - - if seconds > 0 { - result += fmt.Sprintf("%ds ", seconds) - } - - if result == "" { - return "1s" - } - - return result -} diff --git a/internal/timeh/duration.go b/internal/timeh/duration.go new file mode 100644 index 0000000..29146d7 --- /dev/null +++ b/internal/timeh/duration.go @@ -0,0 +1,58 @@ +package timeh + +import ( + "fmt" + "strings" + "time" +) + +func Duration(d time.Duration) string { + if d == 0 { + return "0s" + } + + days := d / (24 * time.Hour) + d -= days * 24 * time.Hour + + hours := d / time.Hour + d -= hours * time.Hour + + minutes := d / time.Minute + d -= minutes * time.Minute + + seconds := d / time.Second + + // Build the human-readable string + var result string + if days > 0 { + result += fmt.Sprintf("%dd ", days) + } + + if hours > 0 { + result += fmt.Sprintf("%dh ", hours) + } + + if minutes > 0 { + result += fmt.Sprintf("%dm ", minutes) + } + + if seconds > 0 { + result += fmt.Sprintf("%ds ", seconds) + } + + if result == "" { + if d < 0 { + return "-1s" + } + + return "1s" + } + + result = strings.TrimSpace(result) + + if d < 0 { + return "-" + result + } + + return result +} diff --git a/internal/timeh/duration_test.go b/internal/timeh/duration_test.go new file mode 100644 index 0000000..1098c06 --- /dev/null +++ b/internal/timeh/duration_test.go @@ -0,0 +1,56 @@ +package timeh + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" +) + +func TestDuration(t *testing.T) { + type args struct { + d time.Duration + } + tests := []struct { + name string + in time.Duration + exp string + }{ + { + name: "negative_duration", + in: -1 * time.Second, + exp: "-1s", + }, + { + name: "zero_duration", + in: 0, + exp: "0s", + }, + { + name: "less_than_second", + in: time.Second - 1, + exp: "1s", // FIXME: it should be 0s actually + }, + { + name: "less_than_minute", + in: time.Minute - 1, + exp: "59s", + }, + { + name: "less_than_hour", + in: time.Hour - 1, + exp: "59m 59s", + }, + { + name: "less_than_day", + in: 24*time.Hour - 1, + exp: "23h 59m 59s", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + res := Duration(tt.in) + require.Equal(t, tt.exp, res) + }) + } +} From 1c01abd136cc9e0447210572e1ef0271896210c5 Mon Sep 17 00:00:00 2001 From: Kirill Zhuravlev Date: Fri, 3 Jan 2025 21:25:17 +0100 Subject: [PATCH 02/13] fix negative representation --- internal/timeh/duration.go | 10 ++++++++-- internal/timeh/duration_test.go | 8 +++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/timeh/duration.go b/internal/timeh/duration.go index 29146d7..f1e9ce8 100644 --- a/internal/timeh/duration.go +++ b/internal/timeh/duration.go @@ -2,6 +2,7 @@ package timeh import ( "fmt" + "math" "strings" "time" ) @@ -11,6 +12,11 @@ func Duration(d time.Duration) string { return "0s" } + isNegative := math.Signbit(float64(d)) + if isNegative { + d = -d + } + days := d / (24 * time.Hour) d -= days * 24 * time.Hour @@ -41,7 +47,7 @@ func Duration(d time.Duration) string { } if result == "" { - if d < 0 { + if isNegative { return "-1s" } @@ -50,7 +56,7 @@ func Duration(d time.Duration) string { result = strings.TrimSpace(result) - if d < 0 { + if isNegative { return "-" + result } diff --git a/internal/timeh/duration_test.go b/internal/timeh/duration_test.go index 1098c06..128f559 100644 --- a/internal/timeh/duration_test.go +++ b/internal/timeh/duration_test.go @@ -8,9 +8,6 @@ import ( ) func TestDuration(t *testing.T) { - type args struct { - d time.Duration - } tests := []struct { name string in time.Duration @@ -21,6 +18,11 @@ func TestDuration(t *testing.T) { in: -1 * time.Second, exp: "-1s", }, + { + name: "negative_duration_2", + in: -1 * time.Hour, + exp: "-1h", + }, { name: "zero_duration", in: 0, From 21af6b714351ab6621ab4146c16c39cb81ec80ab Mon Sep 17 00:00:00 2001 From: Kirill Zhuravlev Date: Fri, 3 Jan 2025 21:35:58 +0100 Subject: [PATCH 03/13] extract repeated code to wrapper --- cmd/toolset/main.go | 108 ++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 79 deletions(-) diff --git a/cmd/toolset/main.go b/cmd/toolset/main.go index ce8ca38..5a3218f 100644 --- a/cmd/toolset/main.go +++ b/cmd/toolset/main.go @@ -71,7 +71,7 @@ func main() { At this point tool will not be installed. In order to install added tool please run $ toolset sync`, - Action: cmdAdd, + Action: withWorkdir(cmdAdd), Flags: []cli.Flag{ &cli.StringFlag{ Name: keyCopyFrom, @@ -94,7 +94,7 @@ At this point tool will not be installed. In order to install added tool please { Name: "sync", Usage: "install all required tools from toolset file", - Action: cmdSync, + Action: withWorkdir(cmdSync), Flags: []cli.Flag{ flagParallel, &cli.StringSliceFlag{ @@ -107,13 +107,13 @@ At this point tool will not be installed. In order to install added tool please { Name: "run", Usage: "run installed tool by its name", - Action: cmdRun, + Action: withWorkdir(cmdRun), Args: true, }, { Name: "upgrade", Usage: "upgrade deps to the latest versions", - Action: cmdUpgrade, + Action: withWorkdir(cmdUpgrade), Flags: []cli.Flag{ flagParallel, &cli.StringSliceFlag{ @@ -134,18 +134,18 @@ At this point tool will not be installed. In order to install added tool please Value: false, }, }, - Action: cmdList, + Action: withWorkdir(cmdList), }, { Name: "which", Usage: "show path to the actual binary", - Action: cmdWhich, + Action: withWorkdir(cmdWhich), Args: true, }, { Name: "remove", Usage: "remove tool", - Action: cmdRemove, + Action: withWorkdir(cmdRemove), Args: true, }, { @@ -158,13 +158,13 @@ At this point tool will not be installed. In order to install added tool please Description: `Install runtime in local project dir. $ toolset runtime add go@1.22`, - Action: cmdRuntimeAdd, + Action: withWorkdir(cmdRuntimeAdd), Args: true, }, { Name: "list", Usage: "list all runtimes", - Action: cmdRuntimeList, + Action: withWorkdir(cmdRuntimeList), }, }, }, @@ -212,15 +212,21 @@ func cmdInit(c *cli.Context) error { return nil } -func cmdAdd(c *cli.Context) error { - fs := fsh.NewRealFS() +func withWorkdir(fn func(c *cli.Context, wd *workdir.Workdir) error) func(c *cli.Context) error { + return func(c *cli.Context) error { + fs := fsh.NewRealFS() - tags := c.StringSlice(keyTags) + wd, err := workdir.New(c.Context, fs, "./") + if err != nil { + return fmt.Errorf("new workdir: %w", err) + } - wd, err := workdir.New(c.Context, fs, "./") - if err != nil { - return fmt.Errorf("new workdir: %w", err) + return fn(c, wd) } +} + +func cmdAdd(c *cli.Context, wd *workdir.Workdir) error { + tags := c.StringSlice(keyTags) if val := c.String(keyCopyFrom); val != "" { count, err := wd.CopySource(c.Context, val, tags) @@ -279,14 +285,7 @@ func cmdAdd(c *cli.Context) error { return nil } -func cmdRuntimeAdd(c *cli.Context) error { - fs := fsh.NewRealFS() - - wd, err := workdir.New(c.Context, fs, "./") - if err != nil { - return fmt.Errorf("new workdir: %w", err) - } - +func cmdRuntimeAdd(c *cli.Context, wd *workdir.Workdir) error { runtime := c.Args().First() if err := wd.RuntimeAdd(c.Context, runtime); err != nil { @@ -300,14 +299,7 @@ func cmdRuntimeAdd(c *cli.Context) error { return nil } -func cmdRuntimeList(c *cli.Context) error { - fs := fsh.NewRealFS() - - wd, err := workdir.New(c.Context, fs, "./") - if err != nil { - return fmt.Errorf("new workdir: %w", err) - } - +func cmdRuntimeList(c *cli.Context, wd *workdir.Workdir) error { t := table.NewWriter() t.AppendHeader(table.Row{ "Runtime", @@ -328,19 +320,12 @@ func cmdRuntimeList(c *cli.Context) error { return nil } -func cmdRun(c *cli.Context) error { - fs := fsh.NewRealFS() - +func cmdRun(c *cli.Context, wd *workdir.Workdir) error { target := c.Args().First() if target == "" { return fmt.Errorf("target is required") } - wd, err := workdir.New(c.Context, fs, "./") - if err != nil { - return fmt.Errorf("new workdir: %w", err) - } - if err := wd.RunTool(c.Context, target, c.Args().Tail()...); err != nil { if errors.Is(err, workdir.ErrToolNotFoundInSpec) { fmt.Println("tool not added. Run `toolset add --help` to add this tool") @@ -366,19 +351,12 @@ func cmdRun(c *cli.Context) error { return nil } -func cmdSync(c *cli.Context) error { - fs := fsh.NewRealFS() - +func cmdSync(c *cli.Context, wd *workdir.Workdir) error { ctx := c.Context maxWorkers := c.Int(keyParallel) tags := c.StringSlice(keyTags) - wd, err := workdir.New(ctx, fs, "./") - if err != nil { - return fmt.Errorf("new workdir: %w", err) - } - if err := wd.Sync(ctx, maxWorkers, tags); err != nil { return fmt.Errorf("sync: %w", err) } @@ -390,19 +368,12 @@ func cmdSync(c *cli.Context) error { return nil } -func cmdUpgrade(c *cli.Context) error { - fs := fsh.NewRealFS() - +func cmdUpgrade(c *cli.Context, wd *workdir.Workdir) error { ctx := c.Context maxWorkers := c.Int(keyParallel) tags := c.StringSlice(keyTags) - wd, err := workdir.New(ctx, fs, "./") - if err != nil { - return fmt.Errorf("new workdir: %w", err) - } - if err := wd.Upgrade(c.Context, tags); err != nil { return fmt.Errorf("upgrade: %w", err) } @@ -422,18 +393,11 @@ func cmdUpgrade(c *cli.Context) error { return nil } -func cmdList(c *cli.Context) error { - fs := fsh.NewRealFS() - +func cmdList(c *cli.Context, wd *workdir.Workdir) error { ctx := c.Context onlyUnused := c.Bool(keyUnused) - wd, err := workdir.New(ctx, fs, "./") - if err != nil { - return fmt.Errorf("new workdir: %w", err) - } - tools, err := wd.GetTools(ctx) if err != nil { return fmt.Errorf("get tools: %w", err) @@ -493,19 +457,12 @@ func cmdList(c *cli.Context) error { return nil } -func cmdWhich(c *cli.Context) error { - fs := fsh.NewRealFS() - +func cmdWhich(c *cli.Context, wd *workdir.Workdir) error { targets := c.Args().Slice() if len(targets) == 0 { return fmt.Errorf("target is required") } - wd, err := workdir.New(c.Context, fs, "./") - if err != nil { - return fmt.Errorf("new workdir: %w", err) - } - for _, target := range targets { ts, err := wd.FindTool(target) if err != nil { @@ -530,19 +487,12 @@ func cmdWhich(c *cli.Context) error { return nil } -func cmdRemove(c *cli.Context) error { - fs := fsh.NewRealFS() - +func cmdRemove(c *cli.Context, wd *workdir.Workdir) error { targets := c.Args().Slice() if len(targets) == 0 { return fmt.Errorf("target is required") } - wd, err := workdir.New(c.Context, fs, "./") - if err != nil { - return fmt.Errorf("new workdir: %w", err) - } - for _, target := range targets { if err := wd.RemoveTool(c.Context, target); err != nil { return fmt.Errorf("remove tool (%s): %w", target, err) From a86d09b65d1ed1c753c09e31f98ef64616a5beba Mon Sep 17 00:00:00 2001 From: Kirill Zhuravlev Date: Fri, 3 Jan 2025 21:42:09 +0100 Subject: [PATCH 04/13] ++ --- Taskfile.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Taskfile.yaml b/Taskfile.yaml index b7aa4c7..85d7f45 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -61,6 +61,7 @@ tasks: cmds: - task: "init" - "{{.TOOLSET}} sync" + - "{{.TOOLSET}} which goimports gofumpt" - "{{.TOOLSET}} list" - "{{.TOOLSET}} remove goimports gofumpt" - "{{.TOOLSET}} list" From eb6ad1b7b055a715db33406549956dd435d97f2a Mon Sep 17 00:00:00 2001 From: Kirill Zhuravlev Date: Fri, 3 Jan 2025 21:46:18 +0100 Subject: [PATCH 05/13] test memfs --- internal/fsh/mem_fs_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 internal/fsh/mem_fs_test.go diff --git a/internal/fsh/mem_fs_test.go b/internal/fsh/mem_fs_test.go new file mode 100644 index 0000000..68fd0b6 --- /dev/null +++ b/internal/fsh/mem_fs_test.go @@ -0,0 +1,31 @@ +package fsh_test + +import ( + "github.com/kazhuravlev/toolset/internal/fsh" + "github.com/stretchr/testify/require" + "testing" +) + +func TestMemFS_GetTree(t *testing.T) { + fs := fsh.NewMemFS(map[string]string{ + "/dir/file1.txt": `Hello 1!`, + "/dir/file2.txt": `Hello 2!`, + "/dir/dir2/file3.txt": `Hello 3!`, + }) + + tree, err := fs.GetTree("/dir") + require.NoError(t, err) + require.Equal(t, []string{ + "/dir", + "/dir/dir2", + "/dir/dir2/file3.txt", + "/dir/file1.txt", + "/dir/file2.txt", + }, tree) +} + +func TestMemFS_SymlinkIfPossible(t *testing.T) { + fs := fsh.NewMemFS(nil) + + require.NoError(t, fs.SymlinkIfPossible("/tmp/a", "/tmp/a")) +} From 06d7ebb178007c14d7a3bc8e5591b9ebe4dbd783 Mon Sep 17 00:00:00 2001 From: Kirill Zhuravlev Date: Fri, 3 Jan 2025 23:39:23 +0100 Subject: [PATCH 06/13] fmt --- internal/fsh/mem_fs_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/fsh/mem_fs_test.go b/internal/fsh/mem_fs_test.go index 68fd0b6..9bff04b 100644 --- a/internal/fsh/mem_fs_test.go +++ b/internal/fsh/mem_fs_test.go @@ -1,9 +1,10 @@ package fsh_test import ( + "testing" + "github.com/kazhuravlev/toolset/internal/fsh" "github.com/stretchr/testify/require" - "testing" ) func TestMemFS_GetTree(t *testing.T) { From 3c113410553d67935122a33b18fd5294b77ae7b4 Mon Sep 17 00:00:00 2001 From: Kirill Zhuravlev Date: Fri, 3 Jan 2025 23:39:32 +0100 Subject: [PATCH 07/13] fetchModule: smoke test --- .../runtimes/runtime-go/private_test.go | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/internal/workdir/runtimes/runtime-go/private_test.go b/internal/workdir/runtimes/runtime-go/private_test.go index a429e8f..391c959 100644 --- a/internal/workdir/runtimes/runtime-go/private_test.go +++ b/internal/workdir/runtimes/runtime-go/private_test.go @@ -5,6 +5,8 @@ import ( "os/exec" "testing" + "github.com/kazhuravlev/toolset/internal/fsh" + "github.com/kazhuravlev/toolset/internal/prog" "github.com/stretchr/testify/require" ) @@ -44,3 +46,30 @@ func Test_parse(t *testing.T) { IsPrivate: false, }) } + +func Test_fetchModule(t *testing.T) { + fs := fsh.NewRealFS() + goBin, err := exec.LookPath("go") + require.NoError(t, err, "install go") + + f := func(name, link string, exp moduleInfo) { + t.Run(name, func(t *testing.T) { + ctx := context.Background() + mod, err := fetchModule(ctx, fs, goBin, link) + require.NoError(t, err) + require.NotEmpty(t, mod) + require.Equal(t, exp, *mod) + }) + } + + f("with_ver", "github.com/bufbuild/buf/cmd/buf@v1.47.2", moduleInfo{ + Mod: prog.NewVer("github.com/bufbuild/buf/cmd/buf", "v1.47.2"), + Program: "buf", + IsPrivate: false, + }) + f("v2_version", "github.com/goreleaser/goreleaser/v2@v2.5.1", moduleInfo{ + Mod: prog.NewVer("github.com/goreleaser/goreleaser/v2", "v2.5.1"), + Program: "goreleaser", + IsPrivate: false, + }) +} From cea819f4a570513339c31265e970ca8feeda56bd Mon Sep 17 00:00:00 2001 From: Kirill Zhuravlev Date: Fri, 3 Jan 2025 23:41:42 +0100 Subject: [PATCH 08/13] get go version --- internal/workdir/runtimes/runtime-go/private_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/workdir/runtimes/runtime-go/private_test.go b/internal/workdir/runtimes/runtime-go/private_test.go index 391c959..26d980e 100644 --- a/internal/workdir/runtimes/runtime-go/private_test.go +++ b/internal/workdir/runtimes/runtime-go/private_test.go @@ -3,6 +3,7 @@ package runtimego import ( "context" "os/exec" + "strings" "testing" "github.com/kazhuravlev/toolset/internal/fsh" @@ -73,3 +74,14 @@ func Test_fetchModule(t *testing.T) { IsPrivate: false, }) } + +func Test_getGoVersion(t *testing.T) { + goBin, err := exec.LookPath("go") + require.NoError(t, err, "install go") + + ctx := context.Background() + goVersion, err := getGoVersion(ctx, goBin) + require.NoError(t, err) + require.NotEmpty(t, goVersion) + require.True(t, strings.HasPrefix(goVersion, "1.")) // NOTE(zhuravlev): should looks like 1.23.4 +} From 065e325b472da8503a167f1fca90cf1da9d7f310 Mon Sep 17 00:00:00 2001 From: Kirill Zhuravlev Date: Sat, 4 Jan 2025 00:00:02 +0100 Subject: [PATCH 09/13] rename Install -> EnsureInstalled --- internal/workdir/runtimes/runtimes.go | 4 ++-- internal/workdir/workdir.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/workdir/runtimes/runtimes.go b/internal/workdir/runtimes/runtimes.go index 3599258..80c7670 100644 --- a/internal/workdir/runtimes/runtimes.go +++ b/internal/workdir/runtimes/runtimes.go @@ -58,14 +58,14 @@ func (r *Runtimes) Get(runtime string) (IRuntime, error) { // GetInstall will get installed runtime or try to install it in other case. func (r *Runtimes) GetInstall(ctx context.Context, runtime string) (IRuntime, error) { - if err := r.Install(ctx, runtime); err != nil { + if err := r.EnsureInstalled(ctx, runtime); err != nil { return nil, err } return r.Get(runtime) } -func (r *Runtimes) Install(ctx context.Context, runtime string) error { +func (r *Runtimes) EnsureInstalled(ctx context.Context, runtime string) error { if _, err := r.Get(runtime); err == nil { // Already installed return nil diff --git a/internal/workdir/workdir.go b/internal/workdir/workdir.go index 9ad26aa..ad99c75 100644 --- a/internal/workdir/workdir.go +++ b/internal/workdir/workdir.go @@ -500,7 +500,7 @@ func (c *Workdir) GetTools(ctx context.Context) ([]structs.ToolState, error) { } func (c *Workdir) RuntimeAdd(ctx context.Context, runtime string) error { - if err := c.runtimes.Install(ctx, runtime); err != nil { + if err := c.runtimes.EnsureInstalled(ctx, runtime); err != nil { return fmt.Errorf("install runtime: %w", err) } From b5adc6fb1804bd20d280ef461baf880f5ad21e5a Mon Sep 17 00:00:00 2001 From: Kirill Zhuravlev Date: Sat, 4 Jan 2025 00:00:12 +0100 Subject: [PATCH 10/13] add remotes check --- internal/workdir/structs/structs.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/workdir/structs/structs.go b/internal/workdir/structs/structs.go index 8bf4915..93ab155 100644 --- a/internal/workdir/structs/structs.go +++ b/internal/workdir/structs/structs.go @@ -217,6 +217,10 @@ type Lock struct { } func (l *Lock) FromSpec(spec *Spec) { + if l.Remotes == nil { + l.Remotes = make([]RemoteSpec, 0) + } + l.Tools = make(Tools, 0, len(spec.Tools)) for _, tool := range spec.Tools { l.Tools.Add(tool) From 4fffa525133f417f2ac697502f9cd82c8c95be2a Mon Sep 17 00:00:00 2001 From: Kirill Zhuravlev Date: Sat, 4 Jan 2025 00:00:23 +0100 Subject: [PATCH 11/13] add simple test for FromSpec --- internal/workdir/structs/structs_test.go | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/internal/workdir/structs/structs_test.go b/internal/workdir/structs/structs_test.go index 169681b..e282fcf 100644 --- a/internal/workdir/structs/structs_test.go +++ b/internal/workdir/structs/structs_test.go @@ -112,6 +112,35 @@ func TestTools(t *testing.T) { }) } +func TestLock_FromSpec(t *testing.T) { + spec := structs.Spec{ + Dir: "/tmp", + Tools: structs.Tools{ + { + Runtime: "sample", + Module: "example", + Alias: optional.New("hello"), + Tags: []string{"tag1"}, + }, + }, + Includes: nil, + } + lock := structs.Lock{} + lock.FromSpec(&spec) + + require.Equal(t, structs.Lock{ + Tools: structs.Tools{ + { + Runtime: "sample", + Module: "example", + Alias: optional.New("hello"), + Tags: []string{"tag1"}, + }, + }, + Remotes: []structs.RemoteSpec{}, + }, lock) +} + func Tool(runtime, module string, alias optional.Val[string], tags []string) structs.Tool { return structs.Tool{ Runtime: runtime, From 6bdea46cf9310d1e1f19e7091acfad8a6c34571a Mon Sep 17 00:00:00 2001 From: Kirill Zhuravlev Date: Sat, 4 Jan 2025 00:05:52 +0100 Subject: [PATCH 12/13] skip windows --- internal/fsh/filesystem_helpers_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/fsh/filesystem_helpers_test.go b/internal/fsh/filesystem_helpers_test.go index 3457e90..8e75463 100644 --- a/internal/fsh/filesystem_helpers_test.go +++ b/internal/fsh/filesystem_helpers_test.go @@ -2,6 +2,7 @@ package fsh_test import ( "os" + "runtime" "testing" "github.com/kazhuravlev/toolset/internal/fsh" @@ -69,6 +70,10 @@ func TestWriteJson(t *testing.T) { func TestReadOrCreateJson(t *testing.T) { t.Run("auto_create_file_when_not_exists", func(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("skip for Windows") + } + fs := fsh.NewMemFS(nil) // 1. file not exists From 9ef75cc72873403f2b8046523424202e287265a1 Mon Sep 17 00:00:00 2001 From: Kirill Zhuravlev Date: Sat, 4 Jan 2025 00:08:21 +0100 Subject: [PATCH 13/13] skip windows --- internal/fsh/mem_fs_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/fsh/mem_fs_test.go b/internal/fsh/mem_fs_test.go index 9bff04b..de72313 100644 --- a/internal/fsh/mem_fs_test.go +++ b/internal/fsh/mem_fs_test.go @@ -1,6 +1,7 @@ package fsh_test import ( + "runtime" "testing" "github.com/kazhuravlev/toolset/internal/fsh" @@ -8,6 +9,10 @@ import ( ) func TestMemFS_GetTree(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("skip for Windows") + } + fs := fsh.NewMemFS(map[string]string{ "/dir/file1.txt": `Hello 1!`, "/dir/file2.txt": `Hello 2!`, @@ -26,6 +31,10 @@ func TestMemFS_GetTree(t *testing.T) { } func TestMemFS_SymlinkIfPossible(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("skip for Windows") + } + fs := fsh.NewMemFS(nil) require.NoError(t, fs.SymlinkIfPossible("/tmp/a", "/tmp/a"))