From f0ee26b1f80db1f750957c270246e16c7f3f91e5 Mon Sep 17 00:00:00 2001 From: Reuven Date: Wed, 28 Feb 2024 19:14:04 +0200 Subject: [PATCH] separate windows and unix tests --- internal/run_test.go | 19 ------------------- internal/run_unix_test.go | 22 ++++++++++++++++++++++ internal/run_windows_test.go | 22 ++++++++++++++++++++++ 3 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 internal/run_unix_test.go create mode 100644 internal/run_windows_test.go diff --git a/internal/run_test.go b/internal/run_test.go index b734ac90..59a4a3c9 100644 --- a/internal/run_test.go +++ b/internal/run_test.go @@ -74,15 +74,6 @@ func Test_Summary(t *testing.T) { require.Contains(t, stdout.String(), `diff: true`) } -func Test_InvalidFile(t *testing.T) { - var stderr bytes.Buffer - require.Equal(t, 102, internal.Run(cmdToArgs("oasdiff diff no-file ../data/openapi-test3.yaml"), io.Discard, &stderr)) - require.Condition(t, func() (success bool) { - return stderr.String() == "Error: failed to load base spec from \"no-file\": open no-file: no such file or directory\n" || - stderr.String() == "Error: failed to load base spec from \"no-file\": open no-file: The system cannot find the file specified.\n" // windows - }, stderr.String()) -} - func Test_InvalidGlob(t *testing.T) { var stderr bytes.Buffer require.Equal(t, 103, internal.Run(cmdToArgs(`oasdiff diff -c "a[" ../data/openapi-test3.yaml`), io.Discard, &stderr)) @@ -202,16 +193,6 @@ func Test_ComposedMode(t *testing.T) { require.Equal(t, map[string]interface{}{"paths": map[string]interface{}{"deleted": []interface{}{"/api/old-test"}}}, bc) } -func Test_ComposedModeInvalidFile(t *testing.T) { - var stderr bytes.Buffer - require.Equal(t, 103, internal.Run(cmdToArgs("oasdiff diff ../data/allof/* ../data/allof/* --composed --flatten"), io.Discard, &stderr)) - - require.Condition(t, func() (success bool) { - return stderr.String() == "Error: failed to load base specs from glob \"../data/allof/*\": failed to flatten allOf in \"../data/allof/invalid.yaml\": unable to resolve Type conflict: all Type values must be identical\n" || - stderr.String() == "Error: failed to load base specs from glob \"../data/allof/*\": failed to flatten allOf in \"..\\data\\allof\\invalid.yaml\": unable to resolve Type conflict: all Type values must be identical" // windows - }, stderr.String()) -} - func Test_Help(t *testing.T) { var stdout bytes.Buffer require.Zero(t, internal.Run(cmdToArgs("oasdiff --help"), &stdout, io.Discard)) diff --git a/internal/run_unix_test.go b/internal/run_unix_test.go new file mode 100644 index 00000000..a28f2643 --- /dev/null +++ b/internal/run_unix_test.go @@ -0,0 +1,22 @@ +package internal_test + +import ( + "bytes" + "io" + "testing" + + "github.com/stretchr/testify/require" + "github.com/tufin/oasdiff/internal" +) + +func Test_InvalidFile(t *testing.T) { + var stderr bytes.Buffer + require.Equal(t, 102, internal.Run(cmdToArgs("oasdiff diff no-file ../data/openapi-test3.yaml"), io.Discard, &stderr)) + require.Equal(t, "Error: failed to load base spec from \"no-file\": open no-file: no such file or directory\n", stderr.String()) +} + +func Test_ComposedModeInvalidFile(t *testing.T) { + var stderr bytes.Buffer + require.Equal(t, 103, internal.Run(cmdToArgs("oasdiff diff ../data/allof/* ../data/allof/* --composed --flatten"), io.Discard, &stderr)) + require.Equal(t, "Error: failed to load base specs from glob \"../data/allof/*\": failed to flatten allOf in \"../data/allof/invalid.yaml\": unable to resolve Type conflict: all Type values must be identical\n", stderr.String()) +} diff --git a/internal/run_windows_test.go b/internal/run_windows_test.go new file mode 100644 index 00000000..24f85e9d --- /dev/null +++ b/internal/run_windows_test.go @@ -0,0 +1,22 @@ +package internal_test + +import ( + "bytes" + "io" + "testing" + + "github.com/stretchr/testify/require" + "github.com/tufin/oasdiff/internal" +) + +func Test_InvalidFile(t *testing.T) { + var stderr bytes.Buffer + require.Equal(t, 102, internal.Run(cmdToArgs("oasdiff diff no-file ../data/openapi-test3.yaml"), io.Discard, &stderr)) + require.Equal(t, "Error: failed to load base spec from \"no-file\": open no-file: The system cannot find the file specified.\n", stderr.String()) +} + +func Test_ComposedModeInvalidFile(t *testing.T) { + var stderr bytes.Buffer + require.Equal(t, 103, internal.Run(cmdToArgs("oasdiff diff ../data/allof/* ../data/allof/* --composed --flatten"), io.Discard, &stderr)) + require.Equal(t, "Error: failed to load base specs from glob \"../data/allof/*\": failed to flatten allOf in \"..\\data\\allof\\invalid.yaml\": unable to resolve Type conflict: all Type values must be identical\n", stderr.String()) +}