Skip to content

Commit

Permalink
Add ServerClient.PutStore
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiante committed Dec 12, 2023
1 parent 9135ff8 commit 08f4cb7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
40 changes: 40 additions & 0 deletions r_put_store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package easclient

import (
"context"
"fmt"
)

type ConfigurationParameter struct {
Name string `json:"name"`
Value string `json:"value"`
}

type ConfigurationTemplate struct {
Name string `json:"name"`
Parameters []ConfigurationParameter `json:"parameters"`
}

type PutStoreRequest struct {
ConfigurationTemplate `json:"configurationTemplate"`
}

func (c *ServerClient) PutStore(ctx context.Context, storeName string, request *PutStoreRequest) error {
req, err := newRequest(ctx, c.c)
if err != nil {
return err
}

req.SetBody(request)

res, err := req.Put("/" + storeName)
if err != nil {
return err
}

if status := res.StatusCode(); status != 201 {
return fmt.Errorf("unexpected response status %v", status)
}

return nil
}
33 changes: 33 additions & 0 deletions r_put_store_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package easclient_test

import (
"context"
"testing"

"github.com/DEXPRO-Solutions-GmbH/easclient"
"github.com/stretchr/testify/require"
)

func TestStoreClient_PutStore(t *testing.T) {
testPrelude(t)

ctx := context.Background()
user := easclient.NewUserClaims("[email protected]")
ctx = user.SetOnContext(ctx)

storeName := "random-store"

err := DefaultServerClient.PutStore(ctx, storeName, &easclient.PutStoreRequest{
ConfigurationTemplate: easclient.ConfigurationTemplate{
Name: "default",
Parameters: []easclient.ConfigurationParameter{
{
Name: "STORE_NAME",
Value: storeName,
},
},
},
})

require.NoError(t, err)
}

0 comments on commit 08f4cb7

Please sign in to comment.