go-ceph/rgw/admin/utils_test.go
Sebastian Riese f8830413c0 rgw/admin: Extend the testing of buildQueryPath
Only one of the two code paths of buildQueryPath was tested so far.
This makes the test harness tight by testing the second one (where
the path already contains a query parameter).

Signed-off-by: Sebastian Riese <sebastian.riese@cloudandheat.com>
2022-03-17 17:47:25 +00:00

46 lines
1.1 KiB
Go

package admin
import (
"net/url"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func getDefaultValue() url.Values {
values := url.Values{}
values.Add("format", "json")
return values
}
func TestBuildQueryPath(t *testing.T) {
queryPath := buildQueryPath("http://192.168.0.1", "/user", getDefaultValue().Encode())
assert.Equal(t, "http://192.168.0.1/admin/user?format=json", queryPath)
queryPath = buildQueryPath("http://192.168.0.1", "/user?foo", getDefaultValue().Encode())
assert.Equal(t, "http://192.168.0.1/admin/user?foo&format=json", queryPath)
}
func TestValueToURLParams(t *testing.T) {
type args struct {
i interface{}
}
tests := []struct {
name string
args args
want string
}{
{"default", args{User{ID: "leseb", Email: "leseb@example.com"}}, "format=json&uid=leseb"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := valueToURLParams(tt.args.i, []string{"uid"})
if !reflect.DeepEqual(got.Encode(), tt.want) {
t.Errorf("valueToURLParams() = %v, want %v", got.Encode(), tt.want)
}
})
}
}