minfreespace_test.go 894 B

1234567891011121314151617181920212223242526272829
  1. package util
  2. import "testing"
  3. func TestParseMinFreeSpace(t *testing.T) {
  4. tests := []struct {
  5. in string
  6. ok bool
  7. value *MinFreeSpace
  8. }{
  9. {in: "42", ok: true, value: &MinFreeSpace{Type: AsPercent, Percent: 42, Raw: "42"}},
  10. {in: "-1", ok: false, value: nil},
  11. {in: "101", ok: false, value: nil},
  12. {in: "100B", ok: false, value: nil},
  13. {in: "100Ki", ok: true, value: &MinFreeSpace{Type: AsBytes, Bytes: 100 * 1024, Raw: "100Ki"}},
  14. {in: "100GiB", ok: true, value: &MinFreeSpace{Type: AsBytes, Bytes: 100 * 1024 * 1024 * 1024, Raw: "100GiB"}},
  15. {in: "42M", ok: true, value: &MinFreeSpace{Type: AsBytes, Bytes: 42 * 1000 * 1000, Raw: "42M"}},
  16. }
  17. for _, p := range tests {
  18. got, err := ParseMinFreeSpace(p.in)
  19. if p.ok != (err == nil) {
  20. t.Errorf("failed to test %v", p.in)
  21. }
  22. if p.ok && err == nil && *got != *p.value {
  23. t.Errorf("failed to test %v", p.in)
  24. }
  25. }
  26. }