helper/schema: generate strings for ValueType
This commit is contained in:
parent
c9e7c63600
commit
689cbc8b5b
16
Makefile
16
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
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ func TestValueType_Zero(t *testing.T) {
|
|||
}{
|
||||
{TypeBool, false},
|
||||
{TypeInt, 0},
|
||||
{TypeFloat, 0.0},
|
||||
{TypeString, ""},
|
||||
{TypeList, []interface{}{}},
|
||||
{TypeMap, map[string]interface{}{}},
|
||||
|
|
|
@ -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]]
|
||||
}
|
Loading…
Reference in New Issue