mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
mcclient: options: test marshal string ptr
This commit is contained in:
@@ -37,6 +37,10 @@ func Bool(v bool) *bool {
|
||||
return &v
|
||||
}
|
||||
|
||||
func String(v string) *string {
|
||||
return &v
|
||||
}
|
||||
|
||||
// IntV returns the integer value as pointed to by the argument if it's
|
||||
// non-nil, return 0 otherwise
|
||||
func IntV(p *int) int {
|
||||
@@ -55,6 +59,13 @@ func BoolV(p *bool) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func StringV(p *string) string {
|
||||
if p != nil {
|
||||
return *p
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type IParamsOptions interface {
|
||||
Params() (*jsonutils.JSONDict, error)
|
||||
}
|
||||
|
||||
@@ -142,6 +142,26 @@ func TestOptionsStructToParams(t *testing.T) {
|
||||
}
|
||||
testSs(t, cases)
|
||||
})
|
||||
t.Run("string ptr", func(t *testing.T) {
|
||||
type s struct {
|
||||
String *string `json:",allowempty"`
|
||||
}
|
||||
cases := []*S{
|
||||
{
|
||||
In: &s{},
|
||||
Want: `{}`,
|
||||
},
|
||||
{
|
||||
In: &s{String("")},
|
||||
Want: `{"string": ""}`,
|
||||
},
|
||||
{
|
||||
In: &s{String("holy")},
|
||||
Want: `{string: "holy"}`,
|
||||
},
|
||||
}
|
||||
testSs(t, cases)
|
||||
})
|
||||
t.Run("string slice", func(t *testing.T) {
|
||||
type s struct {
|
||||
StringSlice []string
|
||||
|
||||
Reference in New Issue
Block a user