Skip to content

Commit

Permalink
add test TestCreateDataSourceSchema_Subresources
Browse files Browse the repository at this point in the history
- this test covers and documents that parent id properties are not
overriden in terms of the configuration.
  • Loading branch information
dikhan committed Sep 20, 2019
1 parent f53c126 commit 0a1ff7e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
1 change: 0 additions & 1 deletion openapi/openapi_spec_resource_schema_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func (s *specSchemaDefinition) createDataSourceSchema() (map[string]*schema.Sche
return nil, err
}
for propertyName := range terraformSchema {
// TODO: to be tested
p, err := s.getPropertyBasedOnTerraformName(propertyName)
if err != nil {
return nil, err
Expand Down
34 changes: 34 additions & 0 deletions openapi/openapi_spec_resource_schema_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,40 @@ func TestCreateDataSourceSchema(t *testing.T) {
}
}

func TestCreateDataSourceSchema_Subresources(t *testing.T) {
t.Run("happy path -- data source schema dor sub-resoruce contains all schema properties configured as computed but parent properties", func(t *testing.T) {

specSchemaDef := specSchemaDefinition{
Properties: specSchemaDefinitionProperties{
&specSchemaDefinitionProperty{
Name: "id",
Type: typeString,
ReadOnly: false,
Required: true,
},
&specSchemaDefinitionProperty{
Name: "parent_id",
Type: typeString,
ReadOnly: false,
Required: true,
IsParentProperty: true,
},
},
}

// get the Terraform schema which represents a Data Source
s, err := specSchemaDef.createDataSourceSchema()

assert.NotNil(t, s)
assert.NoError(t, err)

assert.Equal(t, schema.TypeString, s["parent_id"].Type)
assert.True(t, s["parent_id"].Required)
assert.False(t, s["parent_id"].Optional)
assert.False(t, s["parent_id"].Computed)
})
}

func TestCreateDataSourceSchema_ForNestedObjects(t *testing.T) {
t.Run("happy path -- a data soruce can be derived from a nested object keeping all the properies attributes as expected", func(t *testing.T) {
// set up the schema for the nested object
Expand Down

0 comments on commit 0a1ff7e

Please sign in to comment.