From 08f4cb711199e17ec4e49d296d747e7e2d99fa68 Mon Sep 17 00:00:00 2001 From: fabiante Date: Tue, 12 Dec 2023 12:03:45 +0100 Subject: [PATCH] Add ServerClient.PutStore --- r_put_store.go | 40 ++++++++++++++++++++++++++++++++++++++++ r_put_store_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 r_put_store.go create mode 100644 r_put_store_test.go 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) +}