Skip to content

Commit

Permalink
if a datavalue is null, then test the return behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
FraDiBen committed Sep 2, 2019
1 parent d6bbee2 commit 71f66d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions openapi/resource_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func (r resourceFactory) handlePollingIfConfigured(responsePayload *map[string]i
if ok {
*responsePayload = remoteDataCasted
} else {
return fmt.Errorf("failed to convert remote data (%s) to map[string]interface{}", reflect.TypeOf(remoteData)) //untested
return fmt.Errorf("failed to convert remote data (%s) to map[string]interface{}", reflect.TypeOf(remoteData))
}
}
return nil
Expand Down Expand Up @@ -600,7 +600,7 @@ func (r resourceFactory) createPayloadFromLocalStateData(resourceLocalData *sche

func (r resourceFactory) getPropertyPayload(input map[string]interface{}, property *specSchemaDefinitionProperty, dataValue interface{}) error {
if dataValue == nil {
return fmt.Errorf("property '%s' has a nil state dataValue", property.Name) //untested
return fmt.Errorf("property '%s' has a nil state dataValue", property.Name)
}
dataValueKind := reflect.TypeOf(dataValue).Kind()
switch dataValueKind {
Expand Down
12 changes: 11 additions & 1 deletion openapi/resource_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ func TestHandlePollingIfConfigured(t *testing.T) {
},
returnHTTPCode: http.StatusOK,
}

responsePayload := map[string]interface{}{}

responseStatusCode := http.StatusAccepted
Expand Down Expand Up @@ -918,7 +919,7 @@ func TestHandlePollingIfConfigured(t *testing.T) {
responses: map[int]*specResponse{},
}
err := r.handlePollingIfConfigured(nil, resourceData, client, operation, responseStatusCode, schema.TimeoutCreate)
Convey("Then the err returned should be nil", func() {
Convey("Then the err should be nil", func() {
So(err, ShouldBeNil)
})
})
Expand Down Expand Up @@ -1841,6 +1842,14 @@ func TestGetPropertyPayload(t *testing.T) {
So(func() { resourceFactory.getPropertyPayload(input, nil, dataValue) }, ShouldPanic)
})

Convey("Given a resource factory"+
"When getPropertyPayload is called with a nil datavalue"+
"Then it returns an error", t, func() {
input := map[string]interface{}{}
resourceFactory := resourceFactory{}
So(resourceFactory.getPropertyPayload(input, &specSchemaDefinitionProperty{Name: "buu"}, nil).Error(), ShouldEqual, `property 'buu' has a nil state dataValue`)
})

Convey("Given a resource factory"+
"When it is called with non-nil property and value for dataValue which cannot be cast to []interface{}"+
"Then it panics", t, func() {
Expand Down Expand Up @@ -2109,6 +2118,7 @@ func TestGetPropertyPayload(t *testing.T) {
So(err.Error(), ShouldEqual, "something is really wrong here...an object property with nested objects should have exactly one elem in the terraform state list")

})

Convey("When getPropertyPayload is called with an empty map, the property with nested object in the resource schema and it's corresponding terraform resourceData state data value", func() {
payload := map[string]interface{}{}
dataValue, _ := resourceData.GetOkExists(propertyWithNestedObject.getTerraformCompliantPropertyName())
Expand Down

0 comments on commit 71f66d4

Please sign in to comment.