Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Reuven committed Dec 17, 2023
1 parent dab5bee commit 8357201
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
28 changes: 28 additions & 0 deletions load/source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package load_test

import (
"testing"

"github.com/stretchr/testify/require"
"github.com/tufin/oasdiff/load"
)

func TestSource_NewStdin(t *testing.T) {
require.True(t, load.NewSource("-").IsStdin())
}

func TestSource_NewFile(t *testing.T) {
require.True(t, load.NewSource("../spec.yaml").IsFile())
}

func TestSource_String(t *testing.T) {
require.Equal(t, "stdin", load.NewSource("-").String())
}

func TestSource_OutStdin(t *testing.T) {
require.Equal(t, `stdin`, load.NewSource("-").Out())
}

func TestSource_Out(t *testing.T) {
require.Equal(t, `"http://twitter.com"`, load.NewSource("http://twitter.com").Out())
}
35 changes: 29 additions & 6 deletions load/spec_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,55 @@ import (
"github.com/tufin/oasdiff/load"
)

func TestLoadSpecInfo(t *testing.T) {
func TestSpecInfo(t *testing.T) {
_, err := load.LoadSpecInfo(MockLoader{}, load.NewSource("../data/openapi-test1.yaml"))
require.NoError(t, err)
}

func TestLoadGlob_OK(t *testing.T) {
func TestSpecInfo_GlobOK(t *testing.T) {
_, err := load.FromGlob(MockLoader{}, "../data/*.yaml")
require.NoError(t, err)
}

func TestLoadGlob_InvalidSpec(t *testing.T) {
func TestSpecInfo_InvalidSpec(t *testing.T) {
_, err := load.FromGlob(MockLoader{}, "../data/ignore-err-example.txt")
require.EqualError(t, err, "error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go value of type openapi3.TBis")
}

func TestLoadGlob_Invalid(t *testing.T) {
func TestSpecInfo_InvalidGlob(t *testing.T) {
_, err := load.FromGlob(MockLoader{}, "[*")
require.EqualError(t, err, "syntax error in pattern")
}

func TestLoadGlob_URL(t *testing.T) {
func TestSpecInfo_URL(t *testing.T) {
_, err := load.FromGlob(MockLoader{}, "http://localhost/openapi-test1.yaml")
require.EqualError(t, err, "no matching files (should be a glob, not a URL)")
}

func TestLoadGlob_NoFiles(t *testing.T) {
func TestSpecInfo_GlobNoFiles(t *testing.T) {
_, err := load.FromGlob(MockLoader{}, "../data/*.xxx")
require.EqualError(t, err, "no matching files")
}

func TestSpecInfoPair(t *testing.T) {
spec, err := load.LoadSpecInfo(MockLoader{}, load.NewSource("../data/openapi-test1.yaml"))
require.NoError(t, err)

pair := load.NewSpecInfoPair(spec, spec)
require.Equal(t, "1.0.0", pair.GetBaseVersion())
require.Equal(t, "1.0.0", pair.GetRevisionVersion())
}

func TestSpecInfoPair_NA(t *testing.T) {
var pair *load.SpecInfoPair
require.Equal(t, "n/a", pair.GetBaseVersion())
require.Equal(t, "n/a", pair.GetRevisionVersion())
}

func TestSpecInfoPair_Nil(t *testing.T) {
var spec *load.SpecInfo
pair := load.NewSpecInfoPair(spec, spec)

require.Equal(t, "n/a", pair.GetBaseVersion())
require.Equal(t, "n/a", pair.GetRevisionVersion())
}

0 comments on commit 8357201

Please sign in to comment.