Skip to content

Commit

Permalink
improve coverage (#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
reuvenharrison authored Apr 18, 2024
1 parent 051d11e commit 54c568b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions internal/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func Test_NoRevision(t *testing.T) {
require.Equal(t, 100, internal.Run(cmdToArgs("oasdiff diff base.yaml"), io.Discard, io.Discard))
}

func Test_ExtraRevision(t *testing.T) {
var stderr bytes.Buffer
require.Equal(t, 100, internal.Run(cmdToArgs("oasdiff diff 1 2 3"), io.Discard, &stderr))
require.Equal(t, "Error: invalid arguments after base and revision\n", stderr.String())
}

func Test_InvalidFlag(t *testing.T) {
require.Equal(t, 100, internal.Run(cmdToArgs("oasdiff diff data/openapi-test1.yaml data/openapi-test1.yaml --invalid"), io.Discard, io.Discard))
}
Expand Down Expand Up @@ -201,6 +207,12 @@ func Test_ComposedMode(t *testing.T) {
require.Equal(t, map[string]interface{}{"paths": map[string]interface{}{"deleted": []interface{}{"/api/old-test"}}}, bc)
}

func Test_ComposedModeStdin(t *testing.T) {
var stderr bytes.Buffer
require.Equal(t, 100, internal.Run(cmdToArgs("oasdiff diff - - --composed"), io.Discard, &stderr))
require.Equal(t, "Error: can't read from stdin in composed mode\n", stderr.String())
}

func Test_Help(t *testing.T) {
var stdout bytes.Buffer
require.Zero(t, internal.Run(cmdToArgs("oasdiff --help"), &stdout, io.Discard))
Expand Down Expand Up @@ -301,3 +313,14 @@ func Test_ColorWithNonTextFormat(t *testing.T) {
require.Equal(t, 100, internal.Run(cmdToArgs("oasdiff changelog ../data/allof/simple.yaml ../data/allof/revision.yaml -f yaml --color always"), io.Discard, &stderr))
require.Equal(t, "Error: --color flag is only relevant with 'text' or 'singleline' formats\n", stderr.String())
}

func Test_QR(t *testing.T) {
require.Zero(t, internal.Run(cmdToArgs("oasdiff qr"), io.Discard, io.Discard))
}

func Test_InvalidEnumValue(t *testing.T) {
var stderr bytes.Buffer
require.Equal(t, 100, internal.Run(cmdToArgs("oasdiff diff ../data/openapi-test1.yaml ../data/openapi-test3.yaml --exclude-elements xxx"), io.Discard, &stderr))
require.Equal(t, `Error: invalid argument "xxx" for "-e, --exclude-elements" flag: xxx is not one of the allowed values: description, endpoints, examples, extensions, summary, or title
`, stderr.String())
}

0 comments on commit 54c568b

Please sign in to comment.