Skip to content

Commit e60455c

Browse files
authored
option to auto-detect format (#53)
* option to auto-detect format * better user testing
1 parent 8edfe02 commit e60455c

3 files changed

Lines changed: 79 additions & 19 deletions

File tree

option/format.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ func WithCSVFormat(columnNames []string, columnTypes []ColumnType, options ...CS
5757
}
5858
}
5959

60+
// WithAutoFormat sets the format to auto-detect JSON, Parquet, XLS or PDF.
61+
func WithAutoFormat() Format {
62+
return func(f *openapi.FormatParams) {
63+
// sets nothing as it is the default behavior
64+
}
65+
}
66+
6067
// WithJSONFormat sets the format to JSON.
6168
func WithJSONFormat() Format {
6269
return func(f *openapi.FormatParams) {

users.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,27 @@ func (rc *RockClient) GetCurrentUser(ctx context.Context) (openapi.User, error)
7171
return *user, nil
7272
}
7373

74+
// GetUser gets a user.
75+
//
76+
// REST API documentation https://docs.rockset.com/rest-api/#getuser
77+
func (rc *RockClient) GetUser(ctx context.Context, email string) (openapi.User, error) {
78+
var err error
79+
var user *openapi.User
80+
81+
q := rc.UsersApi.GetUser(ctx, email)
82+
83+
err = rc.Retry(ctx, func() error {
84+
user, _, err = q.Execute()
85+
return err
86+
})
87+
88+
if err != nil {
89+
return openapi.User{}, err
90+
}
91+
92+
return *user, nil
93+
}
94+
7495
// ListUsers lists all users.
7596
//
7697
// REST API documentation https://docs.rockset.com/rest-api/#listusers

users_test.go

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,76 @@
11
package rockset_test
22

33
import (
4+
"github.com/stretchr/testify/suite"
45
"testing"
56

6-
"github.com/rs/zerolog"
7-
"github.com/stretchr/testify/assert"
87
"github.com/stretchr/testify/require"
98

109
"github.com/rockset/rockset-go-client"
1110
)
1211

13-
func TestRockClient_ListUsers(t *testing.T) {
14-
skipUnlessIntegrationTest(t)
12+
const CIUser = "pme+circleci@rockset.com"
1513

16-
ctx := testCtx()
17-
log := zerolog.Ctx(ctx)
14+
type UserTestSuite struct {
15+
suite.Suite
16+
rc *rockset.RockClient
17+
email string
18+
}
19+
20+
func TestUserTestSuite(t *testing.T) {
21+
skipUnlessIntegrationTest(t)
1822

1923
rc, err := rockset.NewClient()
2024
require.NoError(t, err)
2125

22-
users, err := rc.ListUsers(ctx)
23-
require.NoError(t, err)
26+
s := UserTestSuite{
27+
rc: rc,
28+
email: "pme+testuser@rockset.com",
29+
}
30+
suite.Run(t, &s)
31+
}
2432

25-
assert.NotEmpty(t, users)
33+
func (s *UserTestSuite) TearDownSuite() {
34+
ctx := testCtx()
2635

27-
for _, user := range users {
28-
log.Debug().Str("user", user.Email).Send()
29-
}
36+
err := s.rc.DeleteUser(ctx, s.email)
37+
s.Require().NoError(err)
3038
}
3139

32-
func TestRockClient_GetCurrentUser(t *testing.T) {
33-
skipUnlessIntegrationTest(t)
40+
func (s *UserTestSuite) TestCreateUser() {
41+
ctx := testCtx()
3442

43+
_, err := s.rc.CreateUser(ctx, s.email, []string{"read-only"})
44+
s.Require().NoError(err)
45+
}
46+
47+
func (s *UserTestSuite) TestGetCurrentUser() {
3548
ctx := testCtx()
3649

37-
rc, err := rockset.NewClient()
38-
require.NoError(t, err)
50+
user, err := s.rc.GetCurrentUser(ctx)
51+
s.Require().NoError(err)
52+
s.Assert().Equal(CIUser, user.Email)
53+
}
3954

40-
user, err := rc.GetCurrentUser(ctx)
41-
require.NoError(t, err)
55+
func (s *UserTestSuite) TestGetUser() {
56+
ctx := testCtx()
4257

43-
assert.Equal(t, "pme+circleci@rockset.com", user.Email)
58+
user, err := s.rc.GetUser(ctx, s.email)
59+
s.Require().NoError(err)
60+
s.Assert().Equal(s.email, user.Email)
61+
}
62+
63+
func (s *UserTestSuite) TestListUsers() {
64+
ctx := testCtx()
65+
66+
users, err := s.rc.ListUsers(ctx)
67+
s.Require().NoError(err)
68+
69+
var found bool
70+
for _, user := range users {
71+
if user.Email == CIUser {
72+
found = true
73+
}
74+
}
75+
s.Assert().True(found)
4476
}

0 commit comments

Comments
 (0)