2013-11-28 19:28:31 -05:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestError(t *testing.T) {
|
|
|
|
je := JSONError{404, "Not found"}
|
|
|
|
if je.Error() != "Not found" {
|
|
|
|
t.Fatalf("Expected 'Not found' got '%s'", je.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProgress(t *testing.T) {
|
2013-12-02 14:53:04 -05:00
|
|
|
jp := JSONProgress{}
|
2013-11-28 19:28:31 -05:00
|
|
|
if jp.String() != "" {
|
|
|
|
t.Fatalf("Expected empty string, got '%s'", jp.String())
|
|
|
|
}
|
|
|
|
|
2014-07-28 14:43:28 -04:00
|
|
|
expected := " 1 B"
|
2013-12-02 14:53:04 -05:00
|
|
|
jp2 := JSONProgress{Current: 1}
|
2014-07-28 14:43:28 -04:00
|
|
|
if jp2.String() != expected {
|
|
|
|
t.Fatalf("Expected %q, got %q", expected, jp2.String())
|
2013-12-02 14:53:04 -05:00
|
|
|
}
|
|
|
|
|
2014-07-28 14:43:28 -04:00
|
|
|
expected = "[=========================> ] 50 B/100 B"
|
2013-12-02 14:53:04 -05:00
|
|
|
jp3 := JSONProgress{Current: 50, Total: 100}
|
2014-07-28 14:43:28 -04:00
|
|
|
if jp3.String() != expected {
|
|
|
|
t.Fatalf("Expected %q, got %q", expected, jp3.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
// this number can't be negetive gh#7136
|
|
|
|
expected = "[==============================================================>] 50 B/40 B"
|
|
|
|
jp4 := JSONProgress{Current: 50, Total: 40}
|
|
|
|
if jp4.String() != expected {
|
|
|
|
t.Fatalf("Expected %q, got %q", expected, jp4.String())
|
2013-11-28 19:28:31 -05:00
|
|
|
}
|
|
|
|
}
|