1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-22 04:08:49 +02:00
goreleaser/cmd/init_test.go
Carlos Alexandro Becker 92f52ac406
refactor(test): use testing.TB Cleanup and Tempdir (#1945)
* refactor: use t.Cleanup instead of defer

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* refactor: use t.Cleanup instead of defer

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* refactor: use t.Cleanup instead of defer

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* refactor: use t.Cleanup instead of defer

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: filepath

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
2020-12-12 13:27:35 -03:00

38 lines
938 B
Go

package cmd
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
func TestInit(t *testing.T) {
var folder = t.TempDir()
var cmd = newInitCmd().cmd
var path = filepath.Join(folder, "foo.yaml")
cmd.SetArgs([]string{"-f", path})
require.NoError(t, cmd.Execute())
require.FileExists(t, path)
}
func TestInitFileExists(t *testing.T) {
var folder = t.TempDir()
var cmd = newInitCmd().cmd
var path = filepath.Join(folder, "twice.yaml")
cmd.SetArgs([]string{"-f", path})
require.NoError(t, cmd.Execute())
require.EqualError(t, cmd.Execute(), "open "+path+": file exists")
require.FileExists(t, path)
}
func TestInitFileError(t *testing.T) {
var folder = t.TempDir()
var cmd = newInitCmd().cmd
var path = filepath.Join(folder, "nope.yaml")
require.NoError(t, os.Chmod(folder, 0000))
cmd.SetArgs([]string{"-f", path})
require.EqualError(t, cmd.Execute(), "open "+path+": permission denied")
}