-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tidyup and testing of JSON Serialization Tests (#1710)
- Loading branch information
1 parent
290d399
commit 71269af
Showing
10 changed files
with
382 additions
and
143 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
package astmodel | ||
|
||
// TestCaseInjector is a utility for injecting function definitions into resources and objects | ||
type TestCaseInjector struct { | ||
// visitor is used to do the actual injection | ||
visitor TypeVisitor | ||
} | ||
|
||
// NewTestCaseInjector creates a new function injector for modifying resources and objects | ||
func NewTestCaseInjector() *TestCaseInjector { | ||
result := &TestCaseInjector{} | ||
|
||
result.visitor = TypeVisitorBuilder{ | ||
VisitObjectType: result.injectTestCaseIntoObject, | ||
VisitResourceType: result.injectTestCaseIntoResource, | ||
}.Build() | ||
|
||
return result | ||
} | ||
|
||
// Inject modifies the passed type definition by injecting the passed function | ||
func (fi *TestCaseInjector) Inject(def TypeDefinition, cases ...TestCase) (TypeDefinition, error) { | ||
result := def | ||
|
||
for _, fn := range cases { | ||
var err error | ||
result, err = fi.visitor.VisitDefinition(result, fn) | ||
if err != nil { | ||
return TypeDefinition{}, err | ||
} | ||
} | ||
|
||
return result, nil | ||
} | ||
|
||
// injectTestCaseIntoObject takes the function provided as a context and includes it on the | ||
// provided object type | ||
func (_ *TestCaseInjector) injectTestCaseIntoObject( | ||
_ *TypeVisitor, ot *ObjectType, ctx interface{}) (Type, error) { | ||
fn := ctx.(TestCase) | ||
return ot.WithTestCase(fn), nil | ||
} | ||
|
||
// injectTestCaseIntoResource takes the function provided as a context and includes it on the | ||
// provided resource type | ||
func (_ *TestCaseInjector) injectTestCaseIntoResource( | ||
_ *TypeVisitor, rt *ResourceType, ctx interface{}) (Type, error) { | ||
fn := ctx.(TestCase) | ||
return rt.WithTestCase(fn), nil | ||
} |
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
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
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
Oops, something went wrong.