Skip to content

Commit 8b61adc

Browse files
committed
Merge pull request #3901 from Joshua-Anderson/deisctl-error-cleanup
ref(deisctl): fix error to string conversion in tests
2 parents 3d96f64 + e3e47ba commit 8b61adc

7 files changed

Lines changed: 12 additions & 12 deletions

File tree

deisctl/backend/fleet/fleet_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func logState(outchan chan string, errchan chan error, errOutput *string, mutex
116116
}
117117
if err != nil {
118118
mutex.Lock()
119-
*errOutput += fmt.Sprintf("%v\n", err)
119+
*errOutput += err.Error()
120120
mutex.Unlock()
121121
}
122122
}

deisctl/backend/fleet/scale_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func TestScaleError(t *testing.T) {
147147
close(errchan)
148148
close(outchan)
149149

150-
expected := "cannot scale below 0\n"
150+
expected := "cannot scale below 0"
151151

152152
logMutex.Lock()
153153
if errOutput != expected {

deisctl/backend/fleet/ssh_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestFindUnit(t *testing.T) {
6969

7070
_, err := c.findUnit("foo")
7171

72-
actualErr := fmt.Sprintf("%v", err)
72+
actualErr := err.Error()
7373

7474
if actualErr != expectedErr {
7575
t.Error(fmt.Errorf("Expected '%s', Got '%s'", expectedErr, actualErr))
@@ -79,7 +79,7 @@ func TestFindUnit(t *testing.T) {
7979

8080
_, err = c.findUnit("deis-router@2.service")
8181

82-
actualErr = fmt.Sprintf("%v", err)
82+
actualErr = err.Error()
8383

8484
if actualErr != expectedErr {
8585
t.Error(fmt.Errorf("Expected '%s', Got '%s'", expectedErr, actualErr))

deisctl/backend/fleet/status_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestStatus(t *testing.T) {
8181
c.runner = mockStatusCommandRunner{validUnits: []string{}}
8282
err = c.Status("foo")
8383

84-
actualErr := fmt.Sprintf("%v", err)
84+
actualErr := err.Error()
8585
expectedErr := "could not find unit: foo"
8686

8787
if actualErr != expectedErr {

deisctl/backend/fleet/unit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func TestReadTemplateError(t *testing.T) {
154154

155155
_, err = readTemplate("foo", []string{name})
156156
expected := "Could not find unit template for foo"
157-
errorf := fmt.Sprintf("%v", err)
157+
errorf := err.Error()
158158

159159
if errorf != expected {
160160
t.Error(fmt.Errorf("Expected %s, Got %s", expected, errorf))

deisctl/backend/fleet/utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func TestNextComponent(t *testing.T) {
6666

6767
func TestLastComponent(t *testing.T) {
6868
num, err := lastUnitNum([]string{})
69-
errorf := fmt.Sprintf("%v", err)
69+
errorf := err.Error()
7070
expectedErr := "Component not found"
7171
if errorf != expectedErr {
7272
t.Fatal(fmt.Errorf("Expected %d, Got %d", expectedErr, errorf))

deisctl/cmd/cmd_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func TestRefreshUnitsError(t *testing.T) {
133133
defer server.Close()
134134

135135
err = RefreshUnits(name, "foo", server.URL+"/%s/%s.service")
136-
result := fmt.Sprintf("%v", err)
136+
result := err.Error()
137137
expected := "404 Not Found"
138138

139139
if result != expected {
@@ -171,7 +171,7 @@ func TestScaling(t *testing.T) {
171171
func TestScalingNonScalableComponent(t *testing.T) {
172172
b := backendStub{}
173173
expected := "cannot scale controller component"
174-
err := fmt.Sprintf("%v", Scale([]string{"controller=2"}, &b))
174+
err := Scale([]string{"controller=2"}, &b).Error()
175175

176176
if err != expected {
177177
t.Error(fmt.Errorf("Expected '%v', Got '%v'", expected, err))
@@ -181,7 +181,7 @@ func TestScalingNonScalableComponent(t *testing.T) {
181181
func TestScalingInvalidFormat(t *testing.T) {
182182
b := backendStub{}
183183
expected := "Could not parse: controller2"
184-
err := fmt.Sprintf("%v", Scale([]string{"controller2"}, &b))
184+
err := Scale([]string{"controller2"}, &b).Error()
185185

186186
if err != expected {
187187
t.Error(fmt.Errorf("Expected '%v', Got '%v'", expected, err))
@@ -300,7 +300,7 @@ func TestStatusError(t *testing.T) {
300300
b := backendStub{}
301301

302302
expected := "Test Error"
303-
err := fmt.Sprintf("%v", Status([]string{"blah"}, &b))
303+
err := Status([]string{"blah"}, &b).Error()
304304

305305
if err != expected {
306306
t.Error(fmt.Errorf("Expected '%v', Got '%v'", expected, err))
@@ -319,7 +319,7 @@ func TestJournalError(t *testing.T) {
319319
b := backendStub{}
320320

321321
expected := "Test Error"
322-
err := fmt.Sprintf("%v", Journal([]string{"blah"}, &b))
322+
err := Journal([]string{"blah"}, &b).Error()
323323

324324
if err != expected {
325325
t.Error(fmt.Errorf("Expected '%v', Got '%v'", expected, err))

0 commit comments

Comments
 (0)