2020-04-28 02:42:44 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2023-03-03 15:36:45 +02:00
|
|
|
"os"
|
2020-04-28 02:42:44 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCheckConfig(t *testing.T) {
|
2021-04-25 19:20:49 +02:00
|
|
|
cmd := newCheckCmd()
|
2020-04-28 02:42:44 +02:00
|
|
|
cmd.cmd.SetArgs([]string{"-f", "testdata/good.yml"})
|
|
|
|
require.NoError(t, cmd.cmd.Execute())
|
|
|
|
}
|
|
|
|
|
2023-05-24 05:32:37 +02:00
|
|
|
func TestCheckConfigNoArgs(t *testing.T) {
|
|
|
|
cmd := newCheckCmd()
|
|
|
|
cmd.cmd.SetArgs(nil)
|
|
|
|
require.NoError(t, cmd.cmd.Execute())
|
|
|
|
require.Equal(t, 1, cmd.checked)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckConfigMultipleFiles(t *testing.T) {
|
|
|
|
cmd := newCheckCmd()
|
|
|
|
cmd.cmd.SetArgs([]string{"testdata/good.yml", "testdata/invalid.yml"})
|
|
|
|
require.Error(t, cmd.cmd.Execute())
|
|
|
|
require.Equal(t, 2, cmd.checked)
|
|
|
|
}
|
|
|
|
|
2020-04-28 02:42:44 +02:00
|
|
|
func TestCheckConfigThatDoesNotExist(t *testing.T) {
|
2021-04-25 19:20:49 +02:00
|
|
|
cmd := newCheckCmd()
|
2020-04-28 02:42:44 +02:00
|
|
|
cmd.cmd.SetArgs([]string{"-f", "testdata/nope.yml"})
|
2023-03-03 15:36:45 +02:00
|
|
|
require.ErrorIs(t, cmd.cmd.Execute(), os.ErrNotExist)
|
2023-05-24 05:32:37 +02:00
|
|
|
require.Equal(t, 0, cmd.checked)
|
2020-04-28 02:42:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckConfigUnmarshalError(t *testing.T) {
|
2021-04-25 19:20:49 +02:00
|
|
|
cmd := newCheckCmd()
|
2020-04-28 02:42:44 +02:00
|
|
|
cmd.cmd.SetArgs([]string{"-f", "testdata/unmarshal_error.yml"})
|
2024-05-25 19:09:49 +02:00
|
|
|
require.EqualError(t, cmd.cmd.Execute(), "yaml: unmarshal errors:\n line 2: field foo not found in type config.Project")
|
2023-05-24 05:32:37 +02:00
|
|
|
require.Equal(t, 0, cmd.checked)
|
2020-04-28 02:42:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckConfigInvalid(t *testing.T) {
|
2021-04-25 19:20:49 +02:00
|
|
|
cmd := newCheckCmd()
|
2020-04-28 02:42:44 +02:00
|
|
|
cmd.cmd.SetArgs([]string{"-f", "testdata/invalid.yml"})
|
2023-05-04 04:28:55 +02:00
|
|
|
require.Error(t, cmd.cmd.Execute())
|
2023-05-24 05:32:37 +02:00
|
|
|
require.Equal(t, 1, cmd.checked)
|
2020-04-28 02:42:44 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 03:47:32 +02:00
|
|
|
func TestCheckConfigInvalidQuiet(t *testing.T) {
|
|
|
|
cmd := newCheckCmd()
|
|
|
|
cmd.cmd.SetArgs([]string{"-f", "testdata/invalid.yml", "-q"})
|
|
|
|
require.Error(t, cmd.cmd.Execute())
|
2023-05-24 05:32:37 +02:00
|
|
|
require.Equal(t, 1, cmd.checked)
|
2021-05-21 03:47:32 +02:00
|
|
|
}
|
|
|
|
|
2020-04-28 02:42:44 +02:00
|
|
|
func TestCheckConfigDeprecated(t *testing.T) {
|
2021-04-25 19:20:49 +02:00
|
|
|
cmd := newCheckCmd()
|
2020-04-28 02:42:44 +02:00
|
|
|
cmd.cmd.SetArgs([]string{"-f", "testdata/good.yml", "--deprecated"})
|
2023-05-04 04:28:55 +02:00
|
|
|
require.Error(t, cmd.cmd.Execute())
|
2023-05-24 05:32:37 +02:00
|
|
|
require.Equal(t, 1, cmd.checked)
|
2020-04-28 02:42:44 +02:00
|
|
|
}
|