Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a fix for nil pointer issue in converter. #5742

Merged
merged 4 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func DaprInvokeHttpRouteDataModelFromVersioned(content []byte, version string) (
return nil, err
}
dm, err := am.ConvertTo()
if err != nil {
return nil, err
}
return dm.(*datamodel.DaprInvokeHttpRoute), err

default:
Expand Down
3 changes: 3 additions & 0 deletions pkg/linkrp/datamodel/converter/daprsecretstore_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func DaprSecretStoreDataModelFromVersioned(content []byte, version string) (*dat
return nil, err
}
dm, err := am.ConvertTo()
if err != nil {
return nil, err
}
return dm.(*datamodel.DaprSecretStore), err

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func TestDaprSecretStoreDataModelFromVersioned(t *testing.T) {
"2022-03-15-privatepreview",
errors.New("json: cannot unmarshal number into Go struct field DaprSecretStoreProperties.properties.version of type string"),
},
{
"../../api/v20220315privatepreview/testdata/daprsecretstore_invalidvalues_resource.json",
"2022-03-15-privatepreview",
&v1.ErrClientRP{Code: "BadRequest", Message: "multiple errors were found:\n\trecipe details cannot be specified when resourceProvisioning is set to manual\n\tmetadata must be specified when resourceProvisioning is set to manual\n\ttype must be specified when resourceProvisioning is set to manual\n\tversion must be specified when resourceProvisioning is set to manual"},
},
{
"",
"unsupported",
Expand Down
3 changes: 3 additions & 0 deletions pkg/linkrp/datamodel/converter/extender_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func ExtenderDataModelFromVersioned(content []byte, version string) (*datamodel.
return nil, err
}
dm, err := am.ConvertTo()
if err != nil {
return nil, err
}
return dm.(*datamodel.Extender), err

default:
Expand Down
3 changes: 3 additions & 0 deletions pkg/linkrp/datamodel/converter/mongodatabase_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func MongoDatabaseDataModelFromVersioned(content []byte, version string) (*datam
return nil, err
}
dm, err := versioned.ConvertTo()
if err != nil {
return nil, err
}
return dm.(*datamodel.MongoDatabase), err

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func TestMongoDatabaseDataModelToVersioned(t *testing.T) {
})
}
}

func TestMongoDatabaseDataModelFromVersioned(t *testing.T) {
testset := []struct {
versionedModelFile string
Expand All @@ -81,6 +80,11 @@ func TestMongoDatabaseDataModelFromVersioned(t *testing.T) {
"2022-03-15-privatepreview",
errors.New("json: cannot unmarshal number into Go struct field MongoDatabaseProperties.properties.resource of type string"),
},
{
"../../api/v20220315privatepreview/testdata/mongodatabaseresource-missinginputs.json",
"2022-03-15-privatepreview",
&v1.ErrClientRP{Code: "BadRequest", Message: "multiple errors were found:\n\thost must be specified when resourceProvisioning is set to manual\n\tport must be specified when resourceProvisioning is set to manual\n\tdatabase must be specified when resourceProvisioning is set to manual"},
},
{
"",
"unsupported",
Expand Down
3 changes: 3 additions & 0 deletions pkg/linkrp/datamodel/converter/rabbitmq_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func RabbitMQMessageQueueDataModelFromVersioned(content []byte, version string)
return nil, err
}
dm, err := versioned.ConvertTo()
if err != nil {
return nil, err
}
return dm.(*datamodel.RabbitMQMessageQueue), err

default:
Expand Down
5 changes: 5 additions & 0 deletions pkg/linkrp/datamodel/converter/rabbitmq_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func TestRabbitMQMessageQueueDataModelFromVersioned(t *testing.T) {
"2022-03-15-privatepreview",
errors.New("json: cannot unmarshal number into Go struct field RabbitMQMessageQueueProperties.properties.resource of type string"),
},
{
"../../api/v20220315privatepreview/testdata/rabbitmq_invalid_properties_resource.json",
"2022-03-15-privatepreview",
&v1.ErrClientRP{Code: "BadRequest", Message: "queue is required when resourceProvisioning is manual"},
},
{
"",
"unsupported",
Expand Down
3 changes: 3 additions & 0 deletions pkg/linkrp/datamodel/converter/rediscache_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func RedisCacheDataModelFromVersioned(content []byte, version string) (*datamode
return nil, err
}
dm, err := versioned.ConvertTo()
if err != nil {
return nil, err
}
return dm.(*datamodel.RedisCache), err

default:
Expand Down
5 changes: 5 additions & 0 deletions pkg/linkrp/datamodel/converter/rediscache_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func TestRedisCacheDataModelFromVersioned(t *testing.T) {
"2022-03-15-privatepreview",
errors.New("json: cannot unmarshal number into Go struct field RedisCacheProperties.properties.host of type string"),
},
{
"../../api/v20220315privatepreview/testdata/rediscacheresource-invalid2.json",
"2022-03-15-privatepreview",
&v1.ErrClientRP{Code: "BadRequest", Message: "multiple errors were found:\n\thost must be specified when resourceProvisioning is set to manual\n\tport must be specified when resourceProvisioning is set to manual"},
},
{
"",
"unsupported",
Expand Down
3 changes: 3 additions & 0 deletions pkg/linkrp/datamodel/converter/sqldatabase_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func SqlDatabaseDataModelFromVersioned(content []byte, version string) (*datamod
return nil, err
}
dm, err := am.ConvertTo()
if err != nil {
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for checking the others. I was about to ask.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have tests that cover these cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for pointing this out, the invalid tests we had were not covering this case. added tests for this case

return dm.(*datamodel.SqlDatabase), err

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ func TestSqlDatabaseDataModelFromVersioned(t *testing.T) {
"2022-03-15-privatepreview",
errors.New("json: cannot unmarshal number into Go struct field SqlDatabaseProperties.properties.database of type string"),
},
{
"../../api/v20220315privatepreview/testdata/sqldatabase_invalid_properties_resource.json",
"2022-03-15-privatepreview",
&v1.ErrClientRP{Code: v1.CodeInvalid, Message: "multiple errors were found:\n\tserver must be specified when resourceProvisioning is set to manual\n\tport must be specified when resourceProvisioning is set to manual\n\tdatabase must be specified when resourceProvisioning is set to manual"},
},
{
"",
"unsupported",
Expand Down