mirror of https://gitlab.com/gitlab-org/cli.git
chore(dependency): update to github.com/google/renameio/v2
This commit is contained in:
parent
45ad6d8a4d
commit
49f06b73a1
2
go.mod
2
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
|
||||
|
|
4
go.sum
4
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=
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/google/renameio"
|
||||
"github.com/google/renameio/v2"
|
||||
)
|
||||
|
||||
// WriteFile to the path
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue