Skip to content

Commit

Permalink
Issue #2468 remove Error and Success from response structs
Browse files Browse the repository at this point in the history
  • Loading branch information
anjannath committed Feb 3, 2022
1 parent 14861ab commit 538de9e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 61 deletions.
18 changes: 0 additions & 18 deletions pkg/crc/api/api_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func TestVersion(t *testing.T) {
CrcVersion: version.GetCRCVersion(),
OpenshiftVersion: version.GetBundleVersion(),
CommitSha: version.GetCommitSha(),
Success: true,
},
vr,
)
Expand All @@ -72,7 +71,6 @@ func TestStatus(t *testing.T) {
PodmanVersion: "3.3.1",
DiskUse: int64(10000000000),
DiskSize: int64(20000000000),
Success: true,
Preset: preset.OpenShift,
},
statusResult,
Expand All @@ -89,9 +87,7 @@ func TestStart(t *testing.T) {
t,
apiClient.StartResult{
Status: "",
Error: "",
KubeletStarted: true,
Success: true,
ClusterConfig: types.ClusterConfig{
ClusterType: "openshift",
ClusterCACert: "MIIDODCCAiCgAwIBAgIIRVfCKNUa1wIwDQYJ",
Expand Down Expand Up @@ -144,8 +140,6 @@ func TestConfigGet(t *testing.T) {
assert.Equal(
t,
apiClient.GetConfigResult{
Success: true,
Error: "",
Configs: map[string]interface{}{
"cpus": float64(4),
},
Expand All @@ -166,8 +160,6 @@ func TestConfigSet(t *testing.T) {
assert.Equal(
t,
apiClient.SetOrUnsetConfigResult{
Success: true,
Error: "",
Properties: []string{"cpus"},
},
configSetResult,
Expand All @@ -179,8 +171,6 @@ func TestConfigSet(t *testing.T) {
assert.Equal(
t,
apiClient.GetConfigResult{
Success: true,
Error: "",
Configs: map[string]interface{}{
"cpus": float64(5),
},
Expand All @@ -197,8 +187,6 @@ func TestConfigUnset(t *testing.T) {
assert.Equal(
t,
apiClient.SetOrUnsetConfigResult{
Success: true,
Error: "",
Properties: []string{"cpus"},
},
configUnsetResult,
Expand All @@ -224,8 +212,6 @@ func TestConfigGetAll(t *testing.T) {
assert.Equal(
t,
apiClient.GetConfigResult{
Success: true,
Error: "",
Configs: configs,
},
allConfigGetResult,
Expand All @@ -241,8 +227,6 @@ func TestConfigGetMultiple(t *testing.T) {
assert.Equal(
t,
apiClient.GetConfigResult{
Success: true,
Error: "",
Configs: map[string]interface{}{
"cpus": float64(4),
"memory": float64(9216),
Expand All @@ -261,8 +245,6 @@ func TestConfigGetEscaped(t *testing.T) {
assert.Equal(
t,
apiClient.GetConfigResult{
Success: true,
Error: "",
Configs: map[string]interface{}{
"a&a": "foo",
"b&&&b": "bar",
Expand Down
18 changes: 9 additions & 9 deletions pkg/crc/api/api_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ var testCases = []testCase{
// start
{
request: post("start"),
response: jSon(`{"Success":true,"Status":"","Error":"","ClusterConfig":{"ClusterType":"openshift","ClusterCACert":"MIIDODCCAiCgAwIBAgIIRVfCKNUa1wIwDQYJ","KubeConfig":"/tmp/kubeconfig","KubeAdminPass":"foobar","ClusterAPI":"https://foo.testing:6443","WebConsoleURL":"https://console.foo.testing:6443","ProxyConfig":null},"KubeletStarted":true}`),
response: jSon(`{"Status":"","ClusterConfig":{"ClusterType":"openshift","ClusterCACert":"MIIDODCCAiCgAwIBAgIIRVfCKNUa1wIwDQYJ","KubeConfig":"/tmp/kubeconfig","KubeAdminPass":"foobar","ClusterAPI":"https://foo.testing:6443","WebConsoleURL":"https://console.foo.testing:6443","ProxyConfig":null},"KubeletStarted":true}`),
},
{
request: get("start"),
response: jSon(`{"Success":true,"Status":"","Error":"","ClusterConfig":{"ClusterType":"openshift","ClusterCACert":"MIIDODCCAiCgAwIBAgIIRVfCKNUa1wIwDQYJ","KubeConfig":"/tmp/kubeconfig","KubeAdminPass":"foobar","ClusterAPI":"https://foo.testing:6443","WebConsoleURL":"https://console.foo.testing:6443","ProxyConfig":null},"KubeletStarted":true}`),
response: jSon(`{"Status":"","ClusterConfig":{"ClusterType":"openshift","ClusterCACert":"MIIDODCCAiCgAwIBAgIIRVfCKNUa1wIwDQYJ","KubeConfig":"/tmp/kubeconfig","KubeAdminPass":"foobar","ClusterAPI":"https://foo.testing:6443","WebConsoleURL":"https://console.foo.testing:6443","ProxyConfig":null},"KubeletStarted":true}`),
},

// start with failure
Expand Down Expand Up @@ -228,7 +228,7 @@ var testCases = []testCase{
// status
{
request: get("status"),
response: jSon(`{"CrcStatus":"Running","OpenshiftStatus":"Running","OpenshiftVersion":"4.5.1","PodmanVersion":"3.3.1","DiskUse":10000000000,"DiskSize":20000000000,"Error":"","Success":true,"Preset":"openshift"}`),
response: jSon(`{"CrcStatus":"Running","OpenshiftStatus":"Running","OpenshiftVersion":"4.5.1","PodmanVersion":"3.3.1","DiskUse":10000000000,"DiskSize":20000000000,"Preset":"openshift"}`),
},

// status with failure
Expand Down Expand Up @@ -266,15 +266,15 @@ var testCases = []testCase{
// version
{
request: get("version"),
response: jSon(fmt.Sprintf(`{"CrcVersion":"%s","CommitSha":"%s","OpenshiftVersion":"%s","Success":true}`, version.GetCRCVersion(), version.GetCommitSha(), version.GetBundleVersion())),
response: jSon(fmt.Sprintf(`{"CrcVersion":"%s","CommitSha":"%s","OpenshiftVersion":"%s"}`, version.GetCRCVersion(), version.GetCommitSha(), version.GetBundleVersion())),
},

// version never fails

// webconsoleurl
{
request: get("webconsoleurl"),
response: jSon(`{"ClusterConfig":{"ClusterType":"openshift","ClusterCACert":"MIIDODCCAiCgAwIBAgIIRVfCKNUa1wIwDQYJ","KubeConfig":"/tmp/kubeconfig","KubeAdminPass":"foobar","ClusterAPI":"https://foo.testing:6443","WebConsoleURL":"https://console.foo.testing:6443","ProxyConfig":null},"Success":true,"Error":""}`),
response: jSon(`{"ClusterConfig":{"ClusterType":"openshift","ClusterCACert":"MIIDODCCAiCgAwIBAgIIRVfCKNUa1wIwDQYJ","KubeConfig":"/tmp/kubeconfig","KubeAdminPass":"foobar","ClusterAPI":"https://foo.testing:6443","WebConsoleURL":"https://console.foo.testing:6443","ProxyConfig":null}}`),
},

// webconsoleurl with failure
Expand All @@ -288,7 +288,7 @@ var testCases = []testCase{
// config
{
request: get("config?cpus"),
response: jSon(`{"Success":true,"Error":"","Configs":{"cpus":4}}`),
response: jSon(`{"Configs":{"cpus":4}}`),
},
{
request: post("config?cpus").withBody("xx"),
Expand All @@ -300,13 +300,13 @@ var testCases = []testCase{
},
{
request: get("config?cpus").withBody("xx"),
response: jSon(`{"Success":true,"Error":"","Configs":{"cpus":4}}`),
response: jSon(`{"Configs":{"cpus":4}}`),
},

// logs
{
request: get("logs"),
response: jSon(`{"Success":true,"Messages":["message 1","message 2","message 3"]}`),
response: jSon(`{"Messages":["message 1","message 2","message 3"]}`),
},

// logs never fails
Expand Down Expand Up @@ -367,7 +367,7 @@ var testCases = []testCase{
// config
{
request: get("config?cpus"),
response: jSon(`{"Success":true,"Error":"","Configs":{"cpus":4}}`),
response: jSon(`{"Configs":{"cpus":4}}`),
},
}

Expand Down
11 changes: 0 additions & 11 deletions pkg/crc/api/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ type VersionResult struct {
CrcVersion string
CommitSha string
OpenshiftVersion string
Success bool
}

type Result struct {
Expand All @@ -18,9 +17,7 @@ type Result struct {
}

type StartResult struct {
Success bool
Status string
Error string
ClusterConfig types.ClusterConfig
KubeletStarted bool
}
Expand All @@ -32,29 +29,21 @@ type ClusterStatusResult struct {
PodmanVersion string
DiskUse int64
DiskSize int64
Error string
Success bool
Preset preset.Preset
}

type ConsoleResult struct {
ClusterConfig types.ClusterConfig
Success bool
Error string
}

// setOrUnsetConfigResult struct is used to return the result of
// setconfig/unsetconfig command
type SetOrUnsetConfigResult struct {
Success bool
Error string
Properties []string
}

// getConfigResult struct is used to return the result of getconfig command
type GetConfigResult struct {
Success bool
Error string
Configs map[string]interface{}
}

Expand Down
23 changes: 6 additions & 17 deletions pkg/crc/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ type Telemetry interface {
UploadAction(action, source, status string) error
}

type loggerResult struct {
Messages []string
}

func (h *Handler) Logs(c *context) error {
return c.JSON(http.StatusOK, &loggerResult{
Success: true,
Messages: h.Logger.Messages(),
})
}
Expand All @@ -57,7 +60,6 @@ func (h *Handler) Status(c *context) error {
PodmanVersion: res.PodmanVersion,
DiskUse: res.DiskUse,
DiskSize: res.DiskSize,
Success: true,
Preset: res.Preset,
})
}
Expand Down Expand Up @@ -102,7 +104,6 @@ func (h *Handler) Start(c *context) error {
return err
}
return c.JSON(http.StatusOK, client.StartResult{
Success: true,
Status: string(res.Status),
ClusterConfig: res.ClusterConfig,
KubeletStarted: res.KubeletStarted,
Expand All @@ -127,7 +128,6 @@ func (h *Handler) GetVersion(c *context) error {
CrcVersion: version.GetCRCVersion(),
CommitSha: version.GetCommitSha(),
OpenshiftVersion: version.GetBundleVersion(),
Success: true,
})
}

Expand All @@ -148,7 +148,6 @@ func (h *Handler) GetWebconsoleInfo(c *context) error {
}
return c.JSON(http.StatusOK, client.ConsoleResult{
ClusterConfig: res.ClusterConfig,
Success: true,
})
}

Expand All @@ -159,10 +158,7 @@ func (h *Handler) SetConfig(c *context) error {
}

if len(req.Properties) == 0 {
return c.JSON(http.StatusBadRequest, client.SetOrUnsetConfigResult{
Success: false,
Error: "No config keys provided",
})
return c.JSON(http.StatusBadRequest, client.SetOrUnsetConfigResult{})
}

// successProps slice contains the properties that were successfully set
Expand All @@ -180,7 +176,6 @@ func (h *Handler) SetConfig(c *context) error {
return multiError
}
return c.JSON(http.StatusOK, client.SetOrUnsetConfigResult{
Success: true,
Properties: successProps,
})
}
Expand All @@ -192,10 +187,7 @@ func (h *Handler) UnsetConfig(c *context) error {
}

if len(req.Properties) == 0 {
return c.JSON(http.StatusBadRequest, client.SetOrUnsetConfigResult{
Success: false,
Error: "No config keys provided",
})
return c.JSON(http.StatusBadRequest, client.SetOrUnsetConfigResult{})
}

// successProps slice contains the properties that were successfully unset
Expand All @@ -212,7 +204,6 @@ func (h *Handler) UnsetConfig(c *context) error {
return multiError
}
return c.JSON(http.StatusOK, client.SetOrUnsetConfigResult{
Success: true,
Properties: successProps,
})
}
Expand All @@ -232,7 +223,6 @@ func (h *Handler) GetConfig(c *context) error {
configs[k] = v.Value
}
return c.JSON(http.StatusOK, client.GetConfigResult{
Success: true,
Configs: configs,
})
}
Expand All @@ -250,7 +240,6 @@ func (h *Handler) GetConfig(c *context) error {
return c.String(http.StatusInternalServerError, "Unable to get configs")
}
return c.JSON(http.StatusOK, client.GetConfigResult{
Success: true,
Configs: configs,
})
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/crc/api/types.go

This file was deleted.

0 comments on commit 538de9e

Please sign in to comment.