knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/ptr/ptr_test.go (about) 1 /* 2 Copyright 2019 The Knative Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package ptr 18 19 import ( 20 "testing" 21 "time" 22 ) 23 24 func TestInt32(t *testing.T) { 25 const want = 55 26 gotPtr := Int32(want) 27 if want != *gotPtr { 28 t.Errorf("Int32() = &%v, wanted %v", *gotPtr, want) 29 } 30 } 31 32 func TestInt64(t *testing.T) { 33 const want = 55 34 gotPtr := Int64(want) 35 if want != *gotPtr { 36 t.Errorf("Int64() = &%v, wanted %v", *gotPtr, want) 37 } 38 } 39 40 func TestFloat32(t *testing.T) { 41 const want = 1.25 42 gotPtr := Float32(want) 43 if want != *gotPtr { 44 t.Errorf("Float32() = &%v, wanted %v", *gotPtr, want) 45 } 46 } 47 48 func TestFloat64(t *testing.T) { 49 const want = 1.25 50 gotPtr := Float64(want) 51 if want != *gotPtr { 52 t.Errorf("Float64() = &%v, wanted %v", *gotPtr, want) 53 } 54 } 55 56 func TestBool(t *testing.T) { 57 const want = true 58 gotPtr := Bool(want) 59 if want != *gotPtr { 60 t.Errorf("Bool() = &%v, wanted %v", *gotPtr, want) 61 } 62 } 63 64 func TestString(t *testing.T) { 65 const want = "should be a pointer" 66 gotPtr := String(want) 67 if want != *gotPtr { 68 t.Errorf("String() = &%v, wanted %v", *gotPtr, want) 69 } 70 } 71 72 func TestTime(t *testing.T) { 73 want := time.Now().Add(time.Minute) 74 if got, want := *Time(want), want; got != want { 75 t.Errorf("got = %v, want: %v", got, want) 76 } 77 } 78 79 func TestDurationWithConst(t *testing.T) { 80 const want = 42 * time.Second 81 gotPtr := Duration(want) 82 if want != *gotPtr { 83 t.Errorf("Duration() = &%v, wanted %v", *gotPtr, want) 84 } 85 }