forked from knative/pkg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add helper function for converting basic type (knative#193)
* add helper function for converting basic type Co-authored-by: fm <mingfu@alauda.cn>
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Copyright 2021 The Katanomi Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package pointer | ||
|
||
// Bool is a helper routine that allocates a new bool value | ||
// to store v and returns a pointer to it. | ||
func Bool(v bool) *bool { return &v } | ||
|
||
// Int is a helper routine that allocates a new int value | ||
// to store v and returns a pointer to it. | ||
func Int(v int) *int { return &v } | ||
|
||
// Int64 is a helper routine that allocates a new int64 value | ||
// to store v and returns a pointer to it. | ||
func Int64(v int64) *int64 { return &v } | ||
|
||
// String is a helper routine that allocates a new string value | ||
// to store v and returns a pointer to it. | ||
func String(v string) *string { return &v } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Copyright 2021 The Katanomi Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package pointer | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestBool(t *testing.T) { | ||
g := NewGomegaWithT(t) | ||
input := true | ||
g.Expect(Bool(input)).To(Equal(&input)) | ||
} | ||
|
||
func TestInt(t *testing.T) { | ||
g := NewGomegaWithT(t) | ||
input := int(0) | ||
g.Expect(Int(input)).To(Equal(&input)) | ||
} | ||
|
||
func TestInt64(t *testing.T) { | ||
g := NewGomegaWithT(t) | ||
input := int64(0) | ||
g.Expect(Int64(input)).To(Equal(&input)) | ||
} | ||
|
||
func TestString(t *testing.T) { | ||
g := NewGomegaWithT(t) | ||
input := "" | ||
g.Expect(String(input)).To(Equal(&input)) | ||
} |