diff --git a/status.go b/status.go index c8ea026..8d357b0 100644 --- a/status.go +++ b/status.go @@ -1,5 +1,7 @@ package ftp +import "fmt" + // FTP status codes, defined in RFC 959 const ( StatusInitiating = 100 @@ -109,5 +111,9 @@ var statusText = map[int]string{ // StatusText returns a text for the FTP status code. It returns the empty string if the code is unknown. func StatusText(code int) string { - return statusText[code] + str, ok := statusText[code] + if !ok { + str = fmt.Sprintf("Unknown status code: %d", code) + } + return str } diff --git a/status_test.go b/status_test.go index 1b04aa7..8dead00 100644 --- a/status_test.go +++ b/status_test.go @@ -1,17 +1,12 @@ package ftp -import "testing" +import ( + "testing" -func TestValidStatusText(t *testing.T) { - txt := StatusText(StatusInvalidCredentials) - if txt == "" { - t.Fatal("exptected status text, got empty string") - } -} + "github.com/stretchr/testify/assert" +) -func TestInvalidStatusText(t *testing.T) { - txt := StatusText(0) - if txt != "" { - t.Fatalf("got status text %q, expected empty string", txt) - } +func TestStatusText(t *testing.T) { + assert.Equal(t, "Unknown status code: 0", StatusText(0)) + assert.Equal(t, "Invalid username or password.", StatusText(StatusInvalidCredentials)) }