-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from DEXPRO-Solutions-GmbH/feat/put-store
Add function to create store
- Loading branch information
Showing
5 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package easclient | ||
|
||
import "gopkg.in/resty.v1" | ||
|
||
type ServerClient struct { | ||
c *resty.Client | ||
} | ||
|
||
func NewServerClient(c *resty.Client) *ServerClient { | ||
return &ServerClient{c: c} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters