Skip to content

Commit

Permalink
Check if application properties and properties.env are not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
vinayada1 committed Nov 30, 2023
1 parent e73a398 commit e982e0a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/corerp/api/v20231001preview/application_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ import (
// ConvertTo converts from the versioned Application resource to version-agnostic datamodel.
func (src *ApplicationResource) ConvertTo() (v1.DataModelInterface, error) {
// Note: SystemData conversion isn't required since this property comes ARM and datastore.

if src.Properties == nil {
return nil, &v1.ErrModelConversion{PropertyName: "$.properties", ValidValue: "not nil"}
}

if src.Properties.Environment == nil {
return nil, &v1.ErrModelConversion{PropertyName: "$.properties.environment", ValidValue: "not nil"}
}

converted := &datamodel.Application{
BaseResource: v1.BaseResource{
TrackedResource: v1.TrackedResource{
Expand Down
10 changes: 10 additions & 0 deletions pkg/corerp/api/v20231001preview/application_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ func TestApplicationConvertVersionedToDataModel(t *testing.T) {
err: nil,
emptyExt: true,
},
{
filename: "applicationresource-no-properties.json",
err: &v1.ErrModelConversion{PropertyName: "$.properties", ValidValue: "not nil"},
emptyExt: true,
},
{
filename: "applicationresource-no-env.json",
err: &v1.ErrModelConversion{PropertyName: "$.properties.environment", ValidValue: "not nil"},
emptyExt: true,
},
}

for _, tt := range conversionTests {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/radius-test-rg/providers/Applications.Core/applications/app0",
"name": "app0",
"type": "Applications.Core/applications",
"properties": {
"extensions": [
{
"kind": "kubernetesMetadata",
"annotations": {
"prometheus.io/scrape": "true",
"prometheus.io/port": "80"
},
"labels": {
"foo/bar/team": "credit",
"foo/bar/contact": "radiususer"
}
},
{
"kind": "kubernetesNamespace",
"namespace": "app0-ns"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "myapp"
}
3 changes: 3 additions & 0 deletions pkg/corerp/datamodel/converter/application_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func ApplicationDataModelFromVersioned(content []byte, version string) (*datamod
return nil, err
}
dm, err := am.ConvertTo()
if err != nil {
return nil, err
}
return dm.(*datamodel.Application), err

default:
Expand Down

0 comments on commit e982e0a

Please sign in to comment.