diff --git a/r_put_store.go b/r_put_store.go new file mode 100644 index 0000000..da1ddd0 --- /dev/null +++ b/r_put_store.go @@ -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 +} diff --git a/r_put_store_test.go b/r_put_store_test.go new file mode 100644 index 0000000..299ef19 --- /dev/null +++ b/r_put_store_test.go @@ -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("test@dexpro.de") + 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) +}