github.com/tsuna/docker@v1.7.0-rc3/pkg/jsonmessage/jsonmessage_test.go (about) 1 package jsonmessage 2 3 import ( 4 "testing" 5 ) 6 7 func TestError(t *testing.T) { 8 je := JSONError{404, "Not found"} 9 if je.Error() != "Not found" { 10 t.Fatalf("Expected 'Not found' got '%s'", je.Error()) 11 } 12 } 13 14 func TestProgress(t *testing.T) { 15 jp := JSONProgress{} 16 if jp.String() != "" { 17 t.Fatalf("Expected empty string, got '%s'", jp.String()) 18 } 19 20 expected := " 1 B" 21 jp2 := JSONProgress{Current: 1} 22 if jp2.String() != expected { 23 t.Fatalf("Expected %q, got %q", expected, jp2.String()) 24 } 25 26 expected = "[=========================> ] 50 B/100 B" 27 jp3 := JSONProgress{Current: 50, Total: 100} 28 if jp3.String() != expected { 29 t.Fatalf("Expected %q, got %q", expected, jp3.String()) 30 } 31 32 // this number can't be negetive gh#7136 33 expected = "[==================================================>] 50 B/40 B" 34 jp4 := JSONProgress{Current: 50, Total: 40} 35 if jp4.String() != expected { 36 t.Fatalf("Expected %q, got %q", expected, jp4.String()) 37 } 38 }