Skip to content

Commit

Permalink
test: test that SCIM only parsing and fallback parsing work as meant
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
  • Loading branch information
leodido committed Jan 26, 2024
1 parent 29c23fc commit 1de818a
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func exec(t *testing.T, testCases []testCase) {
func TestDefaultParsingMode(t *testing.T) {
m := NewMachine()
require.NotNil(t, m)
require.IsType(t, &machine{}, m)
require.Equal(t, DefaultParsingMode, m.(*machine).parsingMode)
}

func exec(t *testing.T, testCases []testCase, mode ParsingMode) {
for ii, tt := range testCases {
urn, err := NewMachine().Parse([]byte(tt.in))
urn, err := NewMachine(WithParsingMode(mode)).Parse([]byte(tt.in))
ok := err == nil

if ok {
Expand All @@ -18,18 +26,32 @@ func exec(t *testing.T, testCases []testCase) {
assert.Equal(t, tt.obj.SS, urn.SS, herror(ii, tt))
assert.Equal(t, tt.str, urn.String(), herror(ii, tt))
assert.Equal(t, tt.norm, urn.Normalize().String(), herror(ii, tt))
if mode == All || mode == RFC7643Only {
assert.Equal(t, tt.isSCIM, urn.IsSCIM(), herror(ii, tt))
// if tt.isSCIM {
// spew.Dump(urn.SCIM())
// }
}
} else {
assert.False(t, tt.ok, herror(ii, tt))
assert.Empty(t, urn, herror(ii, tt))
assert.Equal(t, tt.estr, err.Error())
assert.Equal(t, tt.estr, err.Error(), herror(ii, tt))
}
}
}

func TestParse(t *testing.T) {
exec(t, genericTestCases)
func TestParse2141Only(t *testing.T) {
exec(t, urn2141OnlyTestCases, RFC2141Only)
}

func TestParseUrnLex2141Only(t *testing.T) {
exec(t, urnlexTestCases, RFC2141Only)
}

func TestSCIMOnly(t *testing.T) {
exec(t, scimOnlyTestCases, RFC7643Only)
}

func TestParseUrnLex(t *testing.T) {
exec(t, urnlexTestCases)
func TestFallbackMode(t *testing.T) {
exec(t, fallbackTestCases, All)
}

0 comments on commit 1de818a

Please sign in to comment.