From 49f06b73a11d5613df2f0ae695b816fec1282bd6 Mon Sep 17 00:00:00 2001 From: Mikel Date: Tue, 9 Jan 2024 15:52:48 +0000 Subject: [PATCH] chore(dependency): update to github.com/google/renameio/v2 --- go.mod | 2 +- go.sum | 4 +- internal/config/writefile.go | 2 +- internal/config/writefile_test.go | 83 ++++++++++++++++++++----------- 4 files changed, 58 insertions(+), 33 deletions(-) diff --git a/go.mod b/go.mod index 48ae589e..234e1417 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/charmbracelet/glamour v0.6.0 github.com/dustin/go-humanize v1.0.1 github.com/gdamore/tcell/v2 v2.6.0 - github.com/google/renameio v1.0.1 + github.com/google/renameio/v2 v2.0.0 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 github.com/gosuri/uilive v0.0.4 github.com/hashicorp/go-multierror v1.1.1 diff --git a/go.sum b/go.sum index c790d13e..9998bb75 100644 --- a/go.sum +++ b/go.sum @@ -173,8 +173,8 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/renameio v1.0.1 h1:Lh/jXZmvZxb0BBeSY5VKEfidcbcbenKjZFzM/q0fSeU= -github.com/google/renameio v1.0.1/go.mod h1:t/HQoYBZSsWSNK35C6CO/TpPLDVWvxOHboWUAweKUpk= +github.com/google/renameio/v2 v2.0.0 h1:UifI23ZTGY8Tt29JbYFiuyIU3eX+RNFtUwefq9qAhxg= +github.com/google/renameio/v2 v2.0.0/go.mod h1:BtmJXm5YlszgC+TD4HOEEUFgkJP3nLxehU6hfe7jRt4= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= diff --git a/internal/config/writefile.go b/internal/config/writefile.go index 84111c51..302d4c04 100644 --- a/internal/config/writefile.go +++ b/internal/config/writefile.go @@ -7,7 +7,7 @@ import ( "os" "path/filepath" - "github.com/google/renameio" + "github.com/google/renameio/v2" ) // WriteFile to the path diff --git a/internal/config/writefile_test.go b/internal/config/writefile_test.go index aa1d59de..7dd8d6ce 100644 --- a/internal/config/writefile_test.go +++ b/internal/config/writefile_test.go @@ -1,7 +1,6 @@ package config import ( - "fmt" "os" "path/filepath" "testing" @@ -18,38 +17,64 @@ func Test_WriteFile(t *testing.T) { t.Cleanup(func() { os.RemoveAll(dir) }) - fpath := filepath.Join(dir, "test-file") - t.Run("regular", func(t *testing.T) { - require.Nilf(t, - WriteFile(fpath, []byte("profclems/glab"), 0o644), - "unexpected error = %s", err, - ) + testCases := []struct { + name string + filePath string + content string + permissions os.FileMode + isSymlink bool + }{ + { + name: "regular", + filePath: "test-file", + content: "profclems/glab", + permissions: 0o644, + isSymlink: false, + }, + { + name: "config", + filePath: "config-file", + content: "profclems/glab/config", + permissions: 0o600, + isSymlink: false, + }, + { + name: "symlink", + filePath: "test-file", + content: "profclems/glab/symlink", + permissions: 0o644, + isSymlink: true, + }, + } - result, err := os.ReadFile(fpath) - require.Nilf(t, err, "failed to read file %q due to %q", fpath, err) - assert.Equal(t, "profclems/glab", string(result)) + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + fullPath := filepath.Join(dir, tc.filePath) - permissions, err := os.Stat(fpath) - require.Nilf(t, err, "failed to get stats for file %q due to %q", fpath, err) - // TODO: - assert.Equal(t, "0644", fmt.Sprintf("%04o", permissions.Mode())) - }) + if tc.isSymlink { + symPath := filepath.Join(dir, "test-symlink") + require.Nil(t, os.Symlink(tc.filePath, symPath), "failed to create a symlink") + fullPath = symPath + } - t.Run("symlink", func(t *testing.T) { - symPath := filepath.Join(dir, "test-symlink") - require.Nil(t, os.Symlink(fpath, symPath), "failed to create a symlink") - require.Nilf(t, - WriteFile(symPath, []byte("profclems/glab/symlink"), 0o644), - "unexpected error = %s", err, - ) + require.Nilf(t, + WriteFile(fullPath, []byte(tc.content), tc.permissions), + "unexpected error for testCase %q", tc.name, + ) - result, err := os.ReadFile(symPath) - require.Nilf(t, err, "failed to read file %q due to %q", symPath, err) - assert.Equal(t, "profclems/glab/symlink", string(result)) + result, err := os.ReadFile(fullPath) + require.Nilf(t, err, "failed to read file %q due to %q", fullPath, err) + assert.Equal(t, tc.content, string(result)) - permissions, err := os.Lstat(symPath) - require.Nil(t, err, "failed to get info about the smylink", err) - assert.Equal(t, os.ModeSymlink, permissions.Mode()&os.ModeSymlink, "this file should be a symlink") - }) + fileInfo, err := os.Lstat(fullPath) + require.Nil(t, err, "failed to get info about the file", err) + + if tc.isSymlink { + assert.Equal(t, os.ModeSymlink, fileInfo.Mode()&os.ModeSymlink, "this file should be a symlink") + } else { + assert.Equal(t, tc.permissions, fileInfo.Mode()) + } + }) + } }