Skip to content

Commit

Permalink
Add test coverage for common command interface
Browse files Browse the repository at this point in the history
  • Loading branch information
nfx committed Mar 8, 2021
1 parent 5d0824f commit 3e34708
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions common/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,46 @@ func TestCommandMock(t *testing.T) {
assert.Equal(t, false, cr.Failed())
assert.Equal(t, "done", cr.Text())
}

func TestCommandResults_Error(t *testing.T) {
cr := CommandResults{}
assert.NoError(t, cr.Err())
cr.ResultType = "error"
assert.EqualError(t, cr.Err(), "")

cr.Summary = "<b>NotFoundException: Things are going wrong; nested exception is: with something</b>"
assert.Equal(t, "Things are going wrong with something", cr.Error())

cr.Summary = ""
cr.Cause = "ExecutionError: \nStatusCode=400\nStatusDescription=ABC\nSomething else"
assert.Equal(t, "\nStatusCode=400\nStatusDescription=ABC", cr.Error())

cr.Cause = "ErrorMessage=Error was here\n"
assert.Equal(t, "Error was here", cr.Error())

assert.False(t, cr.Scan())
}

func TestCommandResults_Scan(t *testing.T) {
cr := CommandResults{
ResultType: "table",
Data: []interface{}{
[]interface{}{"foo", 1, true},
[]interface{}{"bar", 2, false},
},
}
a := ""
b := 0
c := false
assert.True(t, cr.Scan(&a, &b, &c))
assert.Equal(t, "foo", a)
assert.Equal(t, 1, b)
assert.Equal(t, true, c)

assert.True(t, cr.Scan(&a, &b, &c))
assert.Equal(t, "bar", a)
assert.Equal(t, 2, b)
assert.Equal(t, false, c)

assert.False(t, cr.Scan(&a, &b, &c))
}

0 comments on commit 3e34708

Please sign in to comment.