Skip to content

Commit

Permalink
add tests for addSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmeranda committed Oct 25, 2024
1 parent 1258eee commit 6c28360
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions types/schemas_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package types

import (
"testing"

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

func TestSchemas(t *testing.T) {
version := APIVersion{
Group: "meta.cattle.io",
Version: "v1",
Path: "/shire",
}

s := NewSchemas().
AddSchema(Schema{
ID: "baggins",
PluralName: "bagginses",
Version: version,
CollectionMethods: []string{},
ResourceMethods: []string{},
ResourceFields: map[string]Field{},
}).
AddSchema(Schema{
ID: "hobbit",
PluralName: "hobbits",
Embed: true,
EmbedType: "baggins",
Version: version,
CollectionMethods: []string{},
ResourceMethods: []string{},
ResourceFields: map[string]Field{
"breakfasts": {Type: "int"},
"name": {Type: "string"},
},
})

expected := []*Schema{
{
ID: "hobbit",
PluralName: "hobbits",
Embed: true,
EmbedType: "baggins",
Version: version,
CollectionMethods: []string{},
ResourceMethods: []string{},
ResourceFields: map[string]Field{
"breakfasts": {Type: "int"},
"name": {Type: "string"},
},
CodeName: "Hobbit",
CodeNamePlural: "Hobbits",
BaseType: "hobbit",
Type: "/meta/schemas/schema",
},
{
ID: "baggins",
PluralName: "bagginses",
Version: version,
CollectionMethods: []string{},
ResourceMethods: []string{},
ResourceFields: map[string]Field{
"breakfasts": {Type: "int"},
"name": {Type: "string"},
},
CodeName: "Baggins",
CodeNamePlural: "Bagginses",
BaseType: "baggins",
Type: "/meta/schemas/schema",
},
}
actual := s.Schemas()

assert.ElementsMatch(t, expected, actual)
}

0 comments on commit 6c28360

Please sign in to comment.