go-ceph/rgw/admin/utils_test.go
Sébastien Han 6be8d370cb rgwadmin: add support for RadosGW Admin Ops API
Following this discussion #492

This commit introduces a new package "rgw/admin" which helps you interact
with the [RadosGW Admin Ops API](https://docs.ceph.com/en/latest/radosgw/adminops).
Not all the API capabilities are covered by this commit, but this is a
solid foundation for adding code on top. I'm expecting a few more
iterations to make 100% complete. Also, the RadosGW Admin API is going
to implement new functions soon (like bucket creation). So this library
will live on and keep catching up.

As many unit tests as possible have been added. A new integration test
suite also runs. The "micro-osd.sh" now deploys a RGW and the
integration suite tests on it. Thus the CI should cover it.

Shout out to @QuentinPerez and @IrekFasikhov for their existing
libraries. They were a very good inspiration to get started.

Co-authored-by: Irek Fasikhov <malmyzh@gmail.com>
Co-authored-by: Quentin Perez <qperez42@gmail.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
2021-05-31 17:45:31 +02:00

43 lines
867 B
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)
}
func TestValueToURLParams(t *testing.T) {
type args struct {
i interface{}
}
tests := []struct {
name string
args args
want string
}{
{"default", args{User{ID: "leseb"}}, "format=json&uid=leseb"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := valueToURLParams(tt.args.i)
if !reflect.DeepEqual(got.Encode(), tt.want) {
t.Errorf("valueToURLParams() = %v, want %v", got.Encode(), tt.want)
}
})
}
}