-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor(rapi client): remove http client abstraction * refactor: extract instance details into component Co-authored-by: Julian Geywitz <[email protected]> Co-authored-by: Rudolph Bott <[email protected]>
- Loading branch information
Showing
31 changed files
with
1,164 additions
and
274 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 |
---|---|---|
|
@@ -19,6 +19,7 @@ jobs: | |
run: | | ||
cd web | ||
yarn install | ||
yarn test --watchAll=false | ||
yarn build | ||
- name: Set up Go 1.x | ||
|
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,45 @@ | ||
package actions | ||
|
||
import ( | ||
"fmt" | ||
"gnt-cc/rapi_client" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
type rapiActionToMethodMap map[string](func(string, string, interface{}) (rapi_client.Response, error)) | ||
|
||
type InstanceActions struct { | ||
RAPIClient rapi_client.Client | ||
} | ||
|
||
func (actions *InstanceActions) PerformSimpleInstanceAction(clusterName string, instanceName string, rapiAction string) (int, error) { | ||
rapiActionToMethodMapping := rapiActionToMethodMap{ | ||
"startup": actions.RAPIClient.Put, | ||
"reboot": actions.RAPIClient.Post, | ||
"shutdown": actions.RAPIClient.Put, | ||
"migrate": actions.RAPIClient.Put, | ||
"failover": actions.RAPIClient.Put, | ||
} | ||
|
||
rapiMethod, exists := rapiActionToMethodMapping[rapiAction] | ||
|
||
if !exists { | ||
return 0, fmt.Errorf("cannot find rapiClient function for action '%s'", rapiAction) | ||
} | ||
|
||
slug := fmt.Sprintf("/2/instances/%s/%s", instanceName, rapiAction) | ||
response, err := rapiMethod(clusterName, slug, nil) | ||
|
||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
jobID, err := strconv.Atoi(strings.TrimSpace(response.Body)) | ||
|
||
if err != nil { | ||
return 0, fmt.Errorf("cannot parse RAPI response") | ||
} | ||
|
||
return jobID, 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,57 @@ | ||
package actions_test | ||
|
||
import ( | ||
"errors" | ||
"gnt-cc/actions" | ||
"gnt-cc/mocking" | ||
"gnt-cc/rapi_client" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
var rapiActions = []string{ | ||
"startup", | ||
"reboot", | ||
"shutdown", | ||
} | ||
|
||
func TestInstanceMethodReturnsError_WhenRAPIReturnsError(t *testing.T) { | ||
client := mocking.NewRAPIClient() | ||
client.On("Post", "testClusterName", mock.Anything, nil). | ||
Return(rapi_client.Response{}, errors.New("expected error")) | ||
client.On("Put", "testClusterName", mock.Anything, nil). | ||
Return(rapi_client.Response{}, errors.New("expected error")) | ||
|
||
actions := actions.InstanceActions{RAPIClient: client} | ||
|
||
for _, rapiAction := range rapiActions { | ||
_, err := actions.PerformSimpleInstanceAction("testClusterName", "testInstanceName", rapiAction) | ||
assert.EqualError(t, err, "expected error") | ||
} | ||
} | ||
|
||
func TestRAPIEndpointIsCalled_WhenInvokingInstanceMethod(t *testing.T) { | ||
client := mocking.NewRAPIClient() | ||
client.On("Put", "testClusterName", "/2/instances/testInstanceName/startup", nil). | ||
Once().Return(rapi_client.Response{ | ||
Body: "423458", | ||
}, nil) | ||
client.On("Post", "testClusterName", "/2/instances/testInstanceName/reboot", nil). | ||
Once().Return(rapi_client.Response{ | ||
Body: "423458", | ||
}, nil) | ||
client.On("Put", "testClusterName", "/2/instances/testInstanceName/shutdown", nil). | ||
Once().Return(rapi_client.Response{ | ||
Body: "423458", | ||
}, nil) | ||
|
||
actions := actions.InstanceActions{RAPIClient: client} | ||
|
||
for _, rapiAction := range rapiActions { | ||
jobId, err := actions.PerformSimpleInstanceAction("testClusterName", "testInstanceName", rapiAction) | ||
assert.Nil(t, err) | ||
assert.Equal(t, jobId, 423458) | ||
} | ||
} |
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
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
Oops, something went wrong.