Browse Source

Added a test for the empty unit, moved bad unit test into a separate test function

Fredric Silberberg 5 years ago
parent
commit
72c638432f
2 changed files with 13 additions and 1 deletions
  1. 1
    1
      free/main.go
  2. 12
    0
      free/main_test.go

+ 1
- 1
free/main.go View File

@@ -23,7 +23,7 @@ func ConvertUnit(stringUnit string) (jsh.Unit, error) {
23 23
 		return jsh.GB, nil
24 24
 	case "tB":
25 25
 		return jsh.TB, nil
26
-	case "":
26
+	case "": // On some systems (Arch, for example) bytes are just the empty string
27 27
 		return jsh.B, nil
28 28
 	default:
29 29
 		return 0, errors.New(fmt.Sprintf("Unknown unit: %s\n", stringUnit))

+ 12
- 0
free/main_test.go View File

@@ -24,11 +24,23 @@ func TestConvertUnit(t *testing.T) {
24 24
 	testUnitError(jsh.GB, t)
25 25
 	testUnitError(jsh.TB, t)
26 26
 
27
+	// Test the empty unit, because this exists on some systems
28
+	actual, error := ConvertUnit("")
29
+	if error != nil {
30
+		t.Error(error)
31
+	}
32
+	if actual != jsh.B {
33
+		t.Errorf("Conversion error: expected %s, received %s", jsh.B.ToString(), actual.ToString())
34
+	}
35
+}
36
+
37
+func TestConvertBadUnit(t *testing.T) {
27 38
 	// Testing a bad unit conversion
28 39
 	actual, error := ConvertUnit("pB")
29 40
 	if error == nil {
30 41
 		t.Error("Expected an error for unit pB, received value of ", actual)
31 42
 	}
43
+
32 44
 }
33 45
 
34 46
 func TestParseGoodLine(t *testing.T) {

Loading…
Cancel
Save