Skip to content

Commit

Permalink
Remove the Result struct from the reponse types
Browse files Browse the repository at this point in the history
  • Loading branch information
anjannath committed Feb 3, 2022
1 parent 0edca1b commit 0bad8c2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 71 deletions.
20 changes: 2 additions & 18 deletions pkg/crc/api/api_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,31 +105,15 @@ func TestStart(t *testing.T) {
func TestSetup(t *testing.T) {
client := newTestClient()
defer client.Close()
stopResult, err := client.Stop()
err := client.Stop()
assert.NoError(t, err)
assert.Equal(
t,
apiClient.Result{
Success: true,
Error: "",
},
stopResult,
)
}

func TestDelete(t *testing.T) {
client := newTestClient()
defer client.Close()
deleteResult, err := client.Delete()
err := client.Delete()
assert.NoError(t, err)
assert.Equal(
t,
apiClient.Result{
Success: true,
Error: "",
},
deleteResult,
)
}

func TestConfigGet(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion pkg/crc/api/api_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func empty() response {
statusCode: 200,
protoMajor: 1,
protoMinor: 1,
body: `{"Success":true,"Error":""}`,
}
}

Expand Down
43 changes: 8 additions & 35 deletions pkg/crc/api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -70,30 +69,14 @@ func (c *Client) Start(config StartConfig) (StartResult, error) {
return sr, nil
}

func (c *Client) Stop() (Result, error) {
var sr = Result{}
body, err := c.sendGetRequest("/stop")
if err != nil {
return sr, err
}
err = json.Unmarshal(body, &sr)
if err != nil {
return sr, err
}
return sr, nil
func (c *Client) Stop() error {
_, err := c.sendGetRequest("/stop")
return err
}

func (c *Client) Delete() (Result, error) {
var dr = Result{}
body, err := c.sendGetRequest("/delete")
if err != nil {
return dr, err
}
err = json.Unmarshal(body, &dr)
if err != nil {
return dr, err
}
return dr, nil
func (c *Client) Delete() error {
_, err := c.sendGetRequest("/delete")
return err
}

func (c *Client) WebconsoleURL() (ConsoleResult, error) {
Expand Down Expand Up @@ -180,19 +163,9 @@ func (c *Client) Telemetry(action string) error {
return fmt.Errorf("Failed to encode data to JSON: %w", err)
}

body, err := c.sendPostRequest("/telemetry", bytes.NewReader(data))
if err != nil {
return err
}
_, err = c.sendPostRequest("/telemetry", bytes.NewReader(data))

var res Result
if err = json.Unmarshal(body, &res); err != nil {
return err
}
if res.Error != "" {
return errors.New(res.Error)
}
return nil
return err
}

func (c *Client) IsPullSecretDefined() (bool, error) {
Expand Down
5 changes: 0 additions & 5 deletions pkg/crc/api/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ type VersionResult struct {
OpenshiftVersion string
}

type Result struct {
Success bool
Error string
}

type StartResult struct {
Status string
ClusterConfig types.ClusterConfig
Expand Down
16 changes: 4 additions & 12 deletions pkg/crc/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ func (h *Handler) Stop(c *context) error {
if err != nil {
return err
}
return c.JSON(http.StatusOK, client.Result{
Success: true,
})
return c.Code(http.StatusOK)
}

func (h *Handler) PowerOff(c *context) error {
Expand All @@ -81,9 +79,7 @@ func (h *Handler) PowerOff(c *context) error {
if err := h.Client.PowerOff(); err != nil {
return err
}
return c.JSON(http.StatusOK, client.Result{
Success: true,
})
return c.Code(http.StatusOK)
}

func (h *Handler) Start(c *context) error {
Expand Down Expand Up @@ -136,9 +132,7 @@ func (h *Handler) Delete(c *context) error {
if err != nil {
return err
}
return c.JSON(http.StatusOK, client.Result{
Success: true,
})
return c.Code(http.StatusOK)
}

func (h *Handler) GetWebconsoleInfo(c *context) error {
Expand Down Expand Up @@ -252,7 +246,5 @@ func (h *Handler) UploadTelemetry(c *context) error {
if err := h.Telemetry.UploadAction(req.Action, req.Source, req.Status); err != nil {
return err
}
return c.JSON(http.StatusOK, client.Result{
Success: true,
})
return c.Code(http.StatusOK)
}

0 comments on commit 0bad8c2

Please sign in to comment.