Skip to content

Commit

Permalink
Addressed review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredoconnell committed Mar 19, 2024
1 parent a206faa commit 28b929e
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion schema/any.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (a *AnySchema) ApplyScope(scope Scope, namespace string) {
}

func (a *AnySchema) ValidateReferences() error {
// Not applicable
// No references in this type. No work to do.
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions schema/bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ func (b BoolSchema) ApplyScope(scope Scope, namespace string) {

}

func (a BoolSchema) ValidateReferences() error {
// Not applicable
func (b BoolSchema) ValidateReferences() error {
// No references in this type. No work to do.
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion schema/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (e EnumSchema[T]) ApplyScope(scope Scope, namespace string) {
}

func (e EnumSchema[T]) ValidateReferences() error {
// Not applicable
// No references in this type. No work to do.
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion schema/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (f FloatSchema) ApplyScope(scope Scope, namespace string) {
}

func (f FloatSchema) ValidateReferences() error {
// Not applicable
// No references in this type. No work to do.
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion schema/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (i IntSchema) ApplyScope(scope Scope, namespace string) {
}

func (i IntSchema) ValidateReferences() error {
// Not applicable
// No references in this type. No work to do.
return nil
}

Expand Down
1 change: 1 addition & 0 deletions schema/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (m MapSchema[K, V]) ApplyScope(scope Scope, namespace string) {
m.KeysValue.ApplyScope(scope, namespace)
m.ValuesValue.ApplyScope(scope, namespace)
}

func (m MapSchema[K, V]) ValidateReferences() error {
err := m.KeysValue.ValidateReferences()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions schema/oneof.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (o OneOfSchema[KeyType]) ApplyScope(scope Scope, namespace string) {
panic(err)
}
}

func (o OneOfSchema[KeyType]) ValidateReferences() error {
for _, t := range o.TypesValue {
err := t.ValidateReferences()
Expand Down
2 changes: 1 addition & 1 deletion schema/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (p PatternSchema) ApplyScope(scope Scope, namespace string) {
}

func (p PatternSchema) ValidateReferences() error {
// Not applicable
// No references in this type. No work to do.
return nil
}

Expand Down
18 changes: 9 additions & 9 deletions schema/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@ func (r *RefSchema) ApplyScope(scope Scope, namespace string) {
}

func (r *RefSchema) ValidateReferences() error {
if r.referencedObjectCache != nil {
return nil
if r.referencedObjectCache == nil {
return BadArgumentError{
Message: fmt.Sprintf(
"Ref object reference could not find an object with ID %q in namespace %q",
r.IDValue,
r.ObjectNamespace,
),
}
}

return BadArgumentError{
Message: fmt.Sprintf(
"Ref object reference could not find an object with ID %q in namespace %q",
r.IDValue,
r.ObjectNamespace,
),
}
return nil
}

func (r *RefSchema) Unserialize(data any) (any, error) {
Expand Down
2 changes: 1 addition & 1 deletion schema/schema_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ var basicObjects = []*ObjectSchema{
nil,
nil,
nil,
PointerTo(""),
PointerTo(DEFAULT_NAMESPACE),
nil,
),
"display": displayProperty,
Expand Down
15 changes: 9 additions & 6 deletions schema/scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func TestUnserialization(t *testing.T) {
assert.NoError(t, err)
unserialized2, err := scopeTestObjectAType.Unserialize(serialized)
assert.NoError(t, err)
// test reversiblity
// test reversibility
assert.Equals(t, unserialized2, result)

// Now as a ptr
Expand Down Expand Up @@ -316,14 +316,15 @@ func TestSelfSerialization(t *testing.T) {

//nolint:funlen
func TestApplyingExternalNamespace(t *testing.T) {
// This test tests applying with scopes, properties, and objects, maps, and lists.
// It must be passed through all of those types. Validating this makes sure that
// it gets applied all the way down, and errors are propagated up.
// This test tests applying a scope to a schema that contains scopes,
// properties, objects, maps, and lists.
// The applied scope must be passed through all of those types, validating
// that the scope gets applied all the way down and that errors are propagated up.
var testScope = schema.NewScopeSchema(
schema.NewObjectSchema(
"scopeTestObjectA",
map[string]*schema.PropertySchema{
"b": schema.NewPropertySchema(
"ref-b": schema.NewPropertySchema(
schema.NewNamespacedRefSchema("scopeTestObjectB", "test-namespace", nil),
nil,
true,
Expand Down Expand Up @@ -383,7 +384,9 @@ func TestApplyingExternalNamespace(t *testing.T) {
),
)
// Not applied yet
assert.Error(t, testScope.ValidateReferences())
err := testScope.ValidateReferences()
assert.Error(t, err)
assert.Contains(t, err.Error(), "could not find an object")
testScope.ApplyScope(externalScope, "test-namespace")
// Now it's applied, so the error should be resolved.
assert.NoError(t, testScope.ValidateReferences())
Expand Down
2 changes: 1 addition & 1 deletion schema/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s StringSchema) ApplyScope(scope Scope, namespace string) {
}

func (s StringSchema) ValidateReferences() error {
// Not applicable
// No references in this type. No work to do.
return nil
}

Expand Down

0 comments on commit 28b929e

Please sign in to comment.