Added a test for the empty unit, moved bad unit test into a separate test function
This commit is contained in:
parent
a144a70a61
commit
72c638432f
@ -23,7 +23,7 @@ func ConvertUnit(stringUnit string) (jsh.Unit, error) {
|
|||||||
return jsh.GB, nil
|
return jsh.GB, nil
|
||||||
case "tB":
|
case "tB":
|
||||||
return jsh.TB, nil
|
return jsh.TB, nil
|
||||||
case "":
|
case "": // On some systems (Arch, for example) bytes are just the empty string
|
||||||
return jsh.B, nil
|
return jsh.B, nil
|
||||||
default:
|
default:
|
||||||
return 0, errors.New(fmt.Sprintf("Unknown unit: %s\n", stringUnit))
|
return 0, errors.New(fmt.Sprintf("Unknown unit: %s\n", stringUnit))
|
||||||
|
@ -24,11 +24,23 @@ func TestConvertUnit(t *testing.T) {
|
|||||||
testUnitError(jsh.GB, t)
|
testUnitError(jsh.GB, t)
|
||||||
testUnitError(jsh.TB, t)
|
testUnitError(jsh.TB, t)
|
||||||
|
|
||||||
|
// Test the empty unit, because this exists on some systems
|
||||||
|
actual, error := ConvertUnit("")
|
||||||
|
if error != nil {
|
||||||
|
t.Error(error)
|
||||||
|
}
|
||||||
|
if actual != jsh.B {
|
||||||
|
t.Errorf("Conversion error: expected %s, received %s", jsh.B.ToString(), actual.ToString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConvertBadUnit(t *testing.T) {
|
||||||
// Testing a bad unit conversion
|
// Testing a bad unit conversion
|
||||||
actual, error := ConvertUnit("pB")
|
actual, error := ConvertUnit("pB")
|
||||||
if error == nil {
|
if error == nil {
|
||||||
t.Error("Expected an error for unit pB, received value of ", actual)
|
t.Error("Expected an error for unit pB, received value of ", actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseGoodLine(t *testing.T) {
|
func TestParseGoodLine(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user