-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove s.schemas in doRemoveSchema * add tests for addSchema * use slices pkg to search for candidates --------- Co-authored-by: joshmeranda <[email protected]>
- Loading branch information
1 parent
6fe644a
commit b4a72e5
Showing
2 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |