vendor: add github.com/Azure/azure-sdk-for-go and dependencies
This commit is contained in:
+133
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
Package to provides helpers to ease working with pointer values of marshalled structures.
|
||||
*/
|
||||
package to
|
||||
|
||||
// String returns a string value for the passed string pointer. It returns the empty string if the
|
||||
// pointer is nil.
|
||||
func String(s *string) string {
|
||||
if s != nil {
|
||||
return *s
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// StringPtr returns a pointer to the passed string.
|
||||
func StringPtr(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
// StringSlice returns a string slice value for the passed string slice pointer. It returns a nil
|
||||
// slice if the pointer is nil.
|
||||
func StringSlice(s *[]string) []string {
|
||||
if s != nil {
|
||||
return *s
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// StringSlicePtr returns a pointer to the passed string slice.
|
||||
func StringSlicePtr(s []string) *[]string {
|
||||
return &s
|
||||
}
|
||||
|
||||
// StringMap returns a map of strings built from the map of string pointers. The empty string is
|
||||
// used for nil pointers.
|
||||
func StringMap(msp map[string]*string) map[string]string {
|
||||
ms := make(map[string]string, len(msp))
|
||||
for k, sp := range msp {
|
||||
if sp != nil {
|
||||
ms[k] = *sp
|
||||
} else {
|
||||
ms[k] = ""
|
||||
}
|
||||
}
|
||||
return ms
|
||||
}
|
||||
|
||||
// StringMapPtr returns a pointer to a map of string pointers built from the passed map of strings.
|
||||
func StringMapPtr(ms map[string]string) *map[string]*string {
|
||||
msp := make(map[string]*string, len(ms))
|
||||
for k, s := range ms {
|
||||
msp[k] = StringPtr(s)
|
||||
}
|
||||
return &msp
|
||||
}
|
||||
|
||||
// Bool returns a bool value for the passed bool pointer. It returns false if the pointer is nil.
|
||||
func Bool(b *bool) bool {
|
||||
if b != nil {
|
||||
return *b
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// BoolPtr returns a pointer to the passed bool.
|
||||
func BoolPtr(b bool) *bool {
|
||||
return &b
|
||||
}
|
||||
|
||||
// Int returns an int value for the passed int pointer. It returns 0 if the pointer is nil.
|
||||
func Int(i *int) int {
|
||||
if i != nil {
|
||||
return *i
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// IntPtr returns a pointer to the passed int.
|
||||
func IntPtr(i int) *int {
|
||||
return &i
|
||||
}
|
||||
|
||||
// Int32 returns an int value for the passed int pointer. It returns 0 if the pointer is nil.
|
||||
func Int32(i *int32) int32 {
|
||||
if i != nil {
|
||||
return *i
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// Int32Ptr returns a pointer to the passed int32.
|
||||
func Int32Ptr(i int32) *int32 {
|
||||
return &i
|
||||
}
|
||||
|
||||
// Int64 returns an int value for the passed int pointer. It returns 0 if the pointer is nil.
|
||||
func Int64(i *int64) int64 {
|
||||
if i != nil {
|
||||
return *i
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// Int64Ptr returns a pointer to the passed int64.
|
||||
func Int64Ptr(i int64) *int64 {
|
||||
return &i
|
||||
}
|
||||
|
||||
// Float32 returns an int value for the passed int pointer. It returns 0.0 if the pointer is nil.
|
||||
func Float32(i *float32) float32 {
|
||||
if i != nil {
|
||||
return *i
|
||||
}
|
||||
return 0.0
|
||||
}
|
||||
|
||||
// Float32Ptr returns a pointer to the passed float32.
|
||||
func Float32Ptr(i float32) *float32 {
|
||||
return &i
|
||||
}
|
||||
|
||||
// Float64 returns an int value for the passed int pointer. It returns 0.0 if the pointer is nil.
|
||||
func Float64(i *float64) float64 {
|
||||
if i != nil {
|
||||
return *i
|
||||
}
|
||||
return 0.0
|
||||
}
|
||||
|
||||
// Float64Ptr returns a pointer to the passed float64.
|
||||
func Float64Ptr(i float64) *float64 {
|
||||
return &i
|
||||
}
|
||||
+220
@@ -0,0 +1,220 @@
|
||||
package to
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
v := ""
|
||||
if String(&v) != v {
|
||||
t.Fatalf("to: String failed to return the correct string -- expected %v, received %v",
|
||||
v, String(&v))
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringHandlesNil(t *testing.T) {
|
||||
if String(nil) != "" {
|
||||
t.Fatalf("to: String failed to correctly convert nil -- expected %v, received %v",
|
||||
"", String(nil))
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringPtr(t *testing.T) {
|
||||
v := ""
|
||||
if *StringPtr(v) != v {
|
||||
t.Fatalf("to: StringPtr failed to return the correct string -- expected %v, received %v",
|
||||
v, *StringPtr(v))
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringSlice(t *testing.T) {
|
||||
v := []string{}
|
||||
if out := StringSlice(&v); !reflect.DeepEqual(out, v) {
|
||||
t.Fatalf("to: StringSlice failed to return the correct slice -- expected %v, received %v",
|
||||
v, out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringSliceHandlesNil(t *testing.T) {
|
||||
if out := StringSlice(nil); out != nil {
|
||||
t.Fatalf("to: StringSlice failed to correctly convert nil -- expected %v, received %v",
|
||||
nil, out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringSlicePtr(t *testing.T) {
|
||||
v := []string{"a", "b"}
|
||||
if out := StringSlicePtr(v); !reflect.DeepEqual(*out, v) {
|
||||
t.Fatalf("to: StringSlicePtr failed to return the correct slice -- expected %v, received %v",
|
||||
v, *out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringMap(t *testing.T) {
|
||||
msp := map[string]*string{"foo": StringPtr("foo"), "bar": StringPtr("bar"), "baz": StringPtr("baz")}
|
||||
for k, v := range StringMap(msp) {
|
||||
if *msp[k] != v {
|
||||
t.Fatalf("to: StringMap incorrectly converted an entry -- expected [%s]%v, received[%s]%v",
|
||||
k, v, k, *msp[k])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringMapHandlesNil(t *testing.T) {
|
||||
msp := map[string]*string{"foo": StringPtr("foo"), "bar": nil, "baz": StringPtr("baz")}
|
||||
for k, v := range StringMap(msp) {
|
||||
if msp[k] == nil && v != "" {
|
||||
t.Fatalf("to: StringMap incorrectly converted a nil entry -- expected [%s]%v, received[%s]%v",
|
||||
k, v, k, *msp[k])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringMapPtr(t *testing.T) {
|
||||
ms := map[string]string{"foo": "foo", "bar": "bar", "baz": "baz"}
|
||||
for k, msp := range *StringMapPtr(ms) {
|
||||
if ms[k] != *msp {
|
||||
t.Fatalf("to: StringMapPtr incorrectly converted an entry -- expected [%s]%v, received[%s]%v",
|
||||
k, ms[k], k, *msp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBool(t *testing.T) {
|
||||
v := false
|
||||
if Bool(&v) != v {
|
||||
t.Fatalf("to: Bool failed to return the correct string -- expected %v, received %v",
|
||||
v, Bool(&v))
|
||||
}
|
||||
}
|
||||
|
||||
func TestBoolHandlesNil(t *testing.T) {
|
||||
if Bool(nil) != false {
|
||||
t.Fatalf("to: Bool failed to correctly convert nil -- expected %v, received %v",
|
||||
false, Bool(nil))
|
||||
}
|
||||
}
|
||||
|
||||
func TestBoolPtr(t *testing.T) {
|
||||
v := false
|
||||
if *BoolPtr(v) != v {
|
||||
t.Fatalf("to: BoolPtr failed to return the correct string -- expected %v, received %v",
|
||||
v, *BoolPtr(v))
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt(t *testing.T) {
|
||||
v := 0
|
||||
if Int(&v) != v {
|
||||
t.Fatalf("to: Int failed to return the correct string -- expected %v, received %v",
|
||||
v, Int(&v))
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntHandlesNil(t *testing.T) {
|
||||
if Int(nil) != 0 {
|
||||
t.Fatalf("to: Int failed to correctly convert nil -- expected %v, received %v",
|
||||
0, Int(nil))
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntPtr(t *testing.T) {
|
||||
v := 0
|
||||
if *IntPtr(v) != v {
|
||||
t.Fatalf("to: IntPtr failed to return the correct string -- expected %v, received %v",
|
||||
v, *IntPtr(v))
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt32(t *testing.T) {
|
||||
v := int32(0)
|
||||
if Int32(&v) != v {
|
||||
t.Fatalf("to: Int32 failed to return the correct string -- expected %v, received %v",
|
||||
v, Int32(&v))
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt32HandlesNil(t *testing.T) {
|
||||
if Int32(nil) != int32(0) {
|
||||
t.Fatalf("to: Int32 failed to correctly convert nil -- expected %v, received %v",
|
||||
0, Int32(nil))
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt32Ptr(t *testing.T) {
|
||||
v := int32(0)
|
||||
if *Int32Ptr(v) != v {
|
||||
t.Fatalf("to: Int32Ptr failed to return the correct string -- expected %v, received %v",
|
||||
v, *Int32Ptr(v))
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt64(t *testing.T) {
|
||||
v := int64(0)
|
||||
if Int64(&v) != v {
|
||||
t.Fatalf("to: Int64 failed to return the correct string -- expected %v, received %v",
|
||||
v, Int64(&v))
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt64HandlesNil(t *testing.T) {
|
||||
if Int64(nil) != int64(0) {
|
||||
t.Fatalf("to: Int64 failed to correctly convert nil -- expected %v, received %v",
|
||||
0, Int64(nil))
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt64Ptr(t *testing.T) {
|
||||
v := int64(0)
|
||||
if *Int64Ptr(v) != v {
|
||||
t.Fatalf("to: Int64Ptr failed to return the correct string -- expected %v, received %v",
|
||||
v, *Int64Ptr(v))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFloat32(t *testing.T) {
|
||||
v := float32(0)
|
||||
if Float32(&v) != v {
|
||||
t.Fatalf("to: Float32 failed to return the correct string -- expected %v, received %v",
|
||||
v, Float32(&v))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFloat32HandlesNil(t *testing.T) {
|
||||
if Float32(nil) != float32(0) {
|
||||
t.Fatalf("to: Float32 failed to correctly convert nil -- expected %v, received %v",
|
||||
0, Float32(nil))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFloat32Ptr(t *testing.T) {
|
||||
v := float32(0)
|
||||
if *Float32Ptr(v) != v {
|
||||
t.Fatalf("to: Float32Ptr failed to return the correct string -- expected %v, received %v",
|
||||
v, *Float32Ptr(v))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFloat64(t *testing.T) {
|
||||
v := float64(0)
|
||||
if Float64(&v) != v {
|
||||
t.Fatalf("to: Float64 failed to return the correct string -- expected %v, received %v",
|
||||
v, Float64(&v))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFloat64HandlesNil(t *testing.T) {
|
||||
if Float64(nil) != float64(0) {
|
||||
t.Fatalf("to: Float64 failed to correctly convert nil -- expected %v, received %v",
|
||||
0, Float64(nil))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFloat64Ptr(t *testing.T) {
|
||||
v := float64(0)
|
||||
if *Float64Ptr(v) != v {
|
||||
t.Fatalf("to: Float64Ptr failed to return the correct string -- expected %v, received %v",
|
||||
v, *Float64Ptr(v))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user