Skip to content

Commit

Permalink
fix postgres flex user creation path (#49)
Browse files Browse the repository at this point in the history
* fix psql flex user creation path

* fix test

Co-authored-by: Dean Oren <[email protected]>
  • Loading branch information
do87 and Dean Oren authored Nov 14, 2022
1 parent 5818e89 commit c0b1364
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pkg/api/v1/postgres-flex/users/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// constants
const (
apiPathList = consts.API_PATH_POSTGRES_FLEX_USERS
apiPathCreate = consts.API_PATH_POSTGRES_FLEX_USER
apiPathCreate = consts.API_PATH_POSTGRES_FLEX_USERS
apiPathGet = consts.API_PATH_POSTGRES_FLEX_USER
)

Expand Down Expand Up @@ -104,13 +104,13 @@ func (svc *PostgresUsersService) Get(ctx context.Context, projectID, instanceID,

// Create adds a new Postgres user and returns the server response (CreateResponse) and error if occurred
// See also https://api.stackit.schwarz/postgres-flex-service/openapi.html#tag/users/paths/~1projects~1{projectId}~1instances~1{instanceId}~1users~1{userId}/post
func (svc *PostgresUsersService) Create(ctx context.Context, projectID, instanceID, userID, username, database string, roles []string) (res CreateResponse, err error) {
func (svc *PostgresUsersService) Create(ctx context.Context, projectID, instanceID, username, database string, roles []string) (res CreateResponse, err error) {

// build body
data, _ := svc.buildCreateRequest(username, database, roles)

// prepare request
req, err := svc.Client.Request(ctx, http.MethodPost, fmt.Sprintf(apiPathCreate, projectID, instanceID, userID), data)
req, err := svc.Client.Request(ctx, http.MethodPost, fmt.Sprintf(apiPathCreate, projectID, instanceID), data)
if err != nil {
return
}
Expand Down
8 changes: 3 additions & 5 deletions pkg/api/v1/postgres-flex/users/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
// constants
const (
apiPathList = consts.API_PATH_POSTGRES_FLEX_USERS
apiPathCreate = consts.API_PATH_POSTGRES_FLEX_USER
apiPathCreate = consts.API_PATH_POSTGRES_FLEX_USERS
apiPathGet = consts.API_PATH_POSTGRES_FLEX_USER
)

Expand Down Expand Up @@ -148,7 +148,7 @@ func TestPostgresUsersService_Create(t *testing.T) {
instanceID := "efg"
userID := "123"

mux.HandleFunc(fmt.Sprintf(apiPathGet, projectID, instanceID, userID), func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc(fmt.Sprintf(apiPathCreate, projectID, instanceID), func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
t.Error("wrong method")
}
Expand All @@ -174,7 +174,6 @@ func TestPostgresUsersService_Create(t *testing.T) {
ctx context.Context
projectID string
instanceID string
userID string
username string
database string
roles []string
Expand All @@ -191,7 +190,6 @@ func TestPostgresUsersService_Create(t *testing.T) {
instanceID,
userID,
"string",
"string",
[]string{"string"},
}, users.CreateResponse{
Item: users.User{
Expand All @@ -210,7 +208,7 @@ func TestPostgresUsersService_Create(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotRes, err := postgres.Users.Create(tt.args.ctx, tt.args.projectID, tt.args.instanceID, tt.args.userID, tt.args.username, tt.args.database, tt.args.roles)
gotRes, err := postgres.Users.Create(tt.args.ctx, tt.args.projectID, tt.args.instanceID, tt.args.username, tt.args.database, tt.args.roles)
if (err != nil) != tt.wantErr {
t.Errorf("PostgresUsersService.Create() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down

0 comments on commit c0b1364

Please sign in to comment.