mirror of https://github.com/knative/pkg.git
Adding Duration ptr helper. (#519)
* Adding Time and Duration ptr helpers. * use do duration. * nit picky reviwers get nit picky comments.
This commit is contained in:
parent
a7dbe91220
commit
540853ba6b
|
@ -16,6 +16,8 @@ limitations under the License.
|
|||
|
||||
package ptr
|
||||
|
||||
import "time"
|
||||
|
||||
// Int32 is a helper for turning integers into pointers for use in
|
||||
// API types that want *int32.
|
||||
func Int32(i int32) *int32 {
|
||||
|
@ -39,3 +41,9 @@ func Bool(b bool) *bool {
|
|||
func String(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
// Duration is a helper for turning time.Duration into pointers for use in
|
||||
// API types that want *time.Duration.
|
||||
func Duration(t time.Duration) *time.Duration {
|
||||
return &t
|
||||
}
|
||||
|
|
|
@ -16,7 +16,10 @@ limitations under the License.
|
|||
|
||||
package ptr
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestInt32(t *testing.T) {
|
||||
want := int32(55)
|
||||
|
@ -49,3 +52,19 @@ func TestString(t *testing.T) {
|
|||
t.Errorf("String() = &%v, wanted %v", *gotPtr, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDuration(t *testing.T) {
|
||||
want := 42 * time.Second
|
||||
gotPtr := Duration(want)
|
||||
if want != *gotPtr {
|
||||
t.Errorf("Duration() = &%v, wanted %v", *gotPtr, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDurationWithConst(t *testing.T) {
|
||||
const want = 42 * time.Second
|
||||
gotPtr := Duration(want)
|
||||
if want != *gotPtr {
|
||||
t.Errorf("Duration() = &%v, wanted %v", *gotPtr, want)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue