1+ package admin
2+
3+ import (
4+ "bytes"
5+ "context"
6+ "encoding/json"
7+ "errors"
8+ "fmt"
9+ "io"
10+ "net/http"
11+ "os"
12+ "slices"
13+ "testing"
14+
15+ "github.com/stretchr/testify/assert"
16+ )
17+
18+ func (suite * RadosGWTestSuite ) TestAccount () {
19+ suite .SetupConnection ()
20+ co , err := New (suite .endpoint , suite .accessKey , suite .secretKey , newDebugHTTPClient (http .DefaultClient ))
21+ assert .NoError (suite .T (), err )
22+
23+ suite .T ().Run ("fail to create account since no ID provided" , func (_ * testing.T ) {
24+ _ , err := co .CreateAccount (context .Background (), Account {Name : "test-account" })
25+ assert .ErrorIs (suite .T (), err , ErrInvalidArgument )
26+ })
27+
28+ suite .T ().Run ("fail to create account since no Name provided" , func (_ * testing.T ) {
29+ _ , err := co .CreateAccount (context .Background (), Account {ID : "RGW12345678901234567" })
30+ assert .ErrorIs (suite .T (), err , ErrInvalidArgument )
31+ })
32+
33+ suite .T ().Run ("fail to create account since invalid ID provided" , func (_ * testing.T ) {
34+ _ , err := co .CreateAccount (context .Background (), Account {ID : "INVALID_ID_12345" , Name : "test-account" })
35+ assert .ErrorIs (suite .T (), err , ErrInvalidArgument )
36+ })
37+
38+ suite .T ().Run ("successfully create account" , func (_ * testing.T ) {
39+ account , err := co .CreateAccount (context .Background (), Account {ID : "RGW12345678901234567" , Name : "test-account" })
40+ assert .NoError (suite .T (), err )
41+ assert .Equal (suite .T (), "RGW12345678901234567" , account .ID )
42+ assert .Equal (suite .T (), "test-account" , account .Name )
43+ })
44+
45+ suite .T ().Run ("fail to get account since no ID provided" , func (_ * testing.T ) {
46+ _ , err := co .GetAccount (context .Background (), "" )
47+ assert .ErrorIs (suite .T (), err , ErrInvalidArgument )
48+ })
49+
50+ suite .T ().Run ("successfully get account" , func (_ * testing.T ) {
51+ account , err := co .GetAccount (context .Background (), "RGW12345678901234567" )
52+ assert .NoError (suite .T (), err )
53+ assert .Equal (suite .T (), "RGW12345678901234567" , account .ID )
54+ assert .Equal (suite .T (), "test-account" , account .Name )
55+ })
56+
57+ suite .T ().Run ("fail to modify account since no ID provided" , func (_ * testing.T ) {
58+ _ , err := co .ModifyAccount (context .Background (), Account {Name : "modified-account" })
59+ assert .ErrorIs (suite .T (), err , ErrInvalidArgument )
60+ })
61+
62+ suite .T ().Run ("successfully modify account" , func (_ * testing.T ) {
63+ account , err := co .ModifyAccount (context .Background (), Account {ID : "RGW12345678901234567" , Name : "modified-account" })
64+ assert .NoError (suite .T (), err )
65+ assert .Equal (suite .T (), "RGW12345678901234567" , account .ID )
66+ assert .Equal (suite .T (), "modified-account" , account .Name )
67+ })
68+
69+ suite .T ().Run ("fail to delete account since no ID provided" , func (_ * testing.T ) {
70+ err := co .DeleteAccount (context .Background (), "" )
71+ assert .ErrorIs (suite .T (), err , ErrInvalidArgument )
72+ })
73+
74+ suite .T ().Run ("successfully delete account" , func (_ * testing.T ) {
75+ err := co .DeleteAccount (context .Background (), "RGW12345678901234567" )
76+ assert .NoError (suite .T (), err )
77+ })
78+ }
0 commit comments