2020-04-27 21:42:44 -03:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestInit(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
var folder = t.TempDir()
|
2020-04-27 21:42:44 -03:00
|
|
|
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) {
|
2020-12-12 13:27:35 -03:00
|
|
|
var folder = t.TempDir()
|
2020-04-27 21:42:44 -03:00
|
|
|
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) {
|
2020-12-12 13:27:35 -03:00
|
|
|
var folder = t.TempDir()
|
2020-04-27 21:42:44 -03:00
|
|
|
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")
|
|
|
|
}
|