From 55e9f46ca3accf2454c10f7cdb9dc26955f8d328 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 20 Jun 2019 12:28:15 -0400 Subject: [PATCH] Allow Default for TimeDurationSecond values to be time.Duration (#6934) --- sdk/framework/backend.go | 2 ++ sdk/framework/backend_test.go | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/sdk/framework/backend.go b/sdk/framework/backend.go index e56c91a7b..bb670db9e 100644 --- a/sdk/framework/backend.go +++ b/sdk/framework/backend.go @@ -579,6 +579,8 @@ func (s *FieldSchema) DefaultOrZero() interface{} { return s.Type.Zero() } result = int(valInt64) + case time.Duration: + result = int(inp.Seconds()) default: return s.Type.Zero() } diff --git a/sdk/framework/backend_test.go b/sdk/framework/backend_test.go index f32e61cc6..36c251af5 100644 --- a/sdk/framework/backend_test.go +++ b/sdk/framework/backend_test.go @@ -564,6 +564,11 @@ func TestFieldSchemaDefaultOrZero(t *testing.T) { 60, }, + "default duration time.Duration": { + &FieldSchema{Type: TypeDurationSecond, Default: 60 * time.Second}, + 60, + }, + "default duration not set": { &FieldSchema{Type: TypeDurationSecond}, 0,