Adding string pointer. (#380)

This commit is contained in:
Scott Nichols 2019-04-10 10:06:58 -07:00 committed by Knative Prow Robot
parent dd77be3b9f
commit 5eb61f623a
2 changed files with 14 additions and 0 deletions

View File

@ -27,3 +27,9 @@ func Int64(i int64) *int64 {
func Bool(b bool) *bool {
return &b
}
// String is a helper for turning strings into pointers for use in
// API types that want *string.
func String(s string) *string {
return &s
}

View File

@ -33,3 +33,11 @@ func TestBool(t *testing.T) {
t.Errorf("Bool() = &%v, wanted %v", *gotPtr, want)
}
}
func TestString(t *testing.T) {
want := "should be a pointer"
gotPtr := String(want)
if want != *gotPtr {
t.Errorf("String() = &%v, wanted %v", *gotPtr, want)
}
}