Skip to content

Commit

Permalink
some more dry up
Browse files Browse the repository at this point in the history
  • Loading branch information
dikhan committed Sep 20, 2019
1 parent 18b8389 commit 427e2af
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
8 changes: 0 additions & 8 deletions openapi/openapi_spec_resource_schema_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,6 @@ func TestCreateDataSourceSchema(t *testing.T) {
}
}

func assertDataSourceSchemaProperty(t *testing.T, actual *schema.Schema, expectedType schema.ValueType, msgAndArgs ...interface{}) {
assert.NotNil(t, actual, msgAndArgs)
assert.Equal(t, expectedType, actual.Type, msgAndArgs)
assert.False(t, actual.Required, msgAndArgs)
assert.True(t, actual.Optional, msgAndArgs)
assert.True(t, actual.Computed, msgAndArgs)
}

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
14 changes: 2 additions & 12 deletions openapi/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,8 @@ definitions:
resourceName := fmt.Sprintf("%s_cdn_datasource_v1", providerName)
So(tfProvider.DataSourcesMap, ShouldContainKey, resourceName)

// TODO: dry out the assertions
So(tfProvider.DataSourcesMap[resourceName].Schema, ShouldContainKey, "label")
So(tfProvider.DataSourcesMap[resourceName].Schema["label"].Type, ShouldEqual, schema.TypeString)
So(tfProvider.DataSourcesMap[resourceName].Schema["label"].Required, ShouldBeFalse)
So(tfProvider.DataSourcesMap[resourceName].Schema["label"].Optional, ShouldBeTrue)
So(tfProvider.DataSourcesMap[resourceName].Schema["label"].Computed, ShouldBeTrue)

So(tfProvider.DataSourcesMap[resourceName].Schema, ShouldContainKey, "owners")
So(tfProvider.DataSourcesMap[resourceName].Schema["owners"].Type, ShouldEqual, schema.TypeList)
So(tfProvider.DataSourcesMap[resourceName].Schema["owners"].Required, ShouldBeFalse)
So(tfProvider.DataSourcesMap[resourceName].Schema["owners"].Optional, ShouldBeTrue)
So(tfProvider.DataSourcesMap[resourceName].Schema["owners"].Computed, ShouldBeTrue)
assertDataSourceSchemaProperty(t, tfProvider.DataSourcesMap[resourceName].Schema["label"], schema.TypeString)
assertDataSourceSchemaProperty(t, tfProvider.DataSourcesMap[resourceName].Schema["owners"], schema.TypeList)

So(tfProvider.DataSourcesMap[resourceName].Schema, ShouldContainKey, "filter")
So(tfProvider.DataSourcesMap[resourceName].Schema["filter"].Type, ShouldEqual, schema.TypeSet)
Expand Down
9 changes: 9 additions & 0 deletions openapi/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package openapi
import (
"encoding/json"
"github.com/hashicorp/terraform/helper/schema"
"github.com/stretchr/testify/assert"
"io/ioutil"
"log"
"os"
Expand Down Expand Up @@ -161,3 +162,11 @@ func initAPISpecFile(swaggerContent string) *os.File {
}
return file
}

func assertDataSourceSchemaProperty(t *testing.T, actual *schema.Schema, expectedType schema.ValueType, msgAndArgs ...interface{}) {
assert.NotNil(t, actual, msgAndArgs)
assert.Equal(t, expectedType, actual.Type, msgAndArgs)
assert.False(t, actual.Required, msgAndArgs)
assert.True(t, actual.Optional, msgAndArgs)
assert.True(t, actual.Computed, msgAndArgs)
}

0 comments on commit 427e2af

Please sign in to comment.