Add status string for unknown status codes
This commit is contained in:
parent
0d36957938
commit
c6fe263756
@ -1,5 +1,7 @@
|
|||||||
package ftp
|
package ftp
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
// FTP status codes, defined in RFC 959
|
// FTP status codes, defined in RFC 959
|
||||||
const (
|
const (
|
||||||
StatusInitiating = 100
|
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.
|
// StatusText returns a text for the FTP status code. It returns the empty string if the code is unknown.
|
||||||
func StatusText(code int) string {
|
func StatusText(code int) string {
|
||||||
return statusText[code]
|
str, ok := statusText[code]
|
||||||
|
if !ok {
|
||||||
|
str = fmt.Sprintf("Unknown status code: %d", code)
|
||||||
|
}
|
||||||
|
return str
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,12 @@
|
|||||||
package ftp
|
package ftp
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
func TestValidStatusText(t *testing.T) {
|
"github.com/stretchr/testify/assert"
|
||||||
txt := StatusText(StatusInvalidCredentials)
|
)
|
||||||
if txt == "" {
|
|
||||||
t.Fatal("exptected status text, got empty string")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestInvalidStatusText(t *testing.T) {
|
func TestStatusText(t *testing.T) {
|
||||||
txt := StatusText(0)
|
assert.Equal(t, "Unknown status code: 0", StatusText(0))
|
||||||
if txt != "" {
|
assert.Equal(t, "Invalid username or password.", StatusText(StatusInvalidCredentials))
|
||||||
t.Fatalf("got status text %q, expected empty string", txt)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user