From 689cbc8b5b8fb6fa2918a28f51b6a17f81b84661 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 10 Jan 2015 15:51:53 -0800 Subject: [PATCH] helper/schema: generate strings for ValueType --- Makefile | 16 ++++++++++------ helper/schema/schema.go | 4 +++- helper/schema/schema_test.go | 1 + helper/schema/valuetype_string.go | 16 ++++++++++++++++ 4 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 helper/schema/valuetype_string.go diff --git a/Makefile b/Makefile index f931f08f8..cfc16cb07 100644 --- a/Makefile +++ b/Makefile @@ -2,26 +2,27 @@ TEST?=./... default: test -bin: config/y.go +bin: config/y.go generate @sh -c "'$(CURDIR)/scripts/build.sh'" -dev: config/y.go +dev: config/y.go generate @TF_DEV=1 sh -c "'$(CURDIR)/scripts/build.sh'" -test: config/y.go +test: config/y.go generate TF_ACC= go test $(TEST) $(TESTARGS) -timeout=10s -parallel=4 -testacc: config/y.go +testacc: config/y.go generate @if [ "$(TEST)" = "./..." ]; then \ echo "ERROR: Set TEST to a specific package"; \ exit 1; \ fi TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 45m -testrace: config/y.go +testrace: config/y.go generate TF_ACC= go test -race $(TEST) $(TESTARGS) updatedeps: config/y.go + go get -u golang.org/x/tools/cmd/stringer # Go 1.4 changed the format of `go get` a bit by requiring the # canonical full path. We work around this and just force. @if [ $(shell go version | cut -f3 -d" " | cut -f2 -d.) -lt 4 ]; then \ @@ -37,4 +38,7 @@ config/y.go: config/expr.y clean: rm config/y.go -.PHONY: bin clean default test updatedeps +generate: + go generate ./... + +.PHONY: bin clean default generate test updatedeps diff --git a/helper/schema/schema.go b/helper/schema/schema.go index e041951ed..ac777f872 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -11,6 +11,8 @@ // A good starting point is to view the Provider structure. package schema +//go:generate stringer -type=ValueType + import ( "fmt" "reflect" @@ -56,7 +58,7 @@ func (t ValueType) Zero() interface{} { case typeObject: return map[string]interface{}{} default: - panic(fmt.Sprintf("unknown type %#v", t)) + panic(fmt.Sprintf("unknown type %s", t)) } } diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index f741ad56c..9f56d386f 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -15,6 +15,7 @@ func TestValueType_Zero(t *testing.T) { }{ {TypeBool, false}, {TypeInt, 0}, + {TypeFloat, 0.0}, {TypeString, ""}, {TypeList, []interface{}{}}, {TypeMap, map[string]interface{}{}}, diff --git a/helper/schema/valuetype_string.go b/helper/schema/valuetype_string.go new file mode 100644 index 000000000..0648f8e0f --- /dev/null +++ b/helper/schema/valuetype_string.go @@ -0,0 +1,16 @@ +// generated by stringer -type=ValueType; DO NOT EDIT + +package schema + +import "fmt" + +const _ValueType_name = "TypeInvalidTypeBoolTypeIntTypeStringTypeListTypeMapTypeSettypeObject" + +var _ValueType_index = [...]uint8{0, 11, 19, 26, 36, 44, 51, 58, 68} + +func (i ValueType) String() string { + if i < 0 || i+1 >= ValueType(len(_ValueType_index)) { + return fmt.Sprintf("ValueType(%d)", i) + } + return _ValueType_name[_ValueType_index[i]:_ValueType_index[i+1]] +}