Commit 5358a620 authored by Joan Piles's avatar Joan Piles

Fixed testing for space checks

parent 4e26c301
......@@ -3,16 +3,19 @@
package main
import (
"log"
"syscall"
"testing"
)
const testDir = "/home"
func gatherTestData(baseDir s) (data syscall.Statfs_t) {
func gatherTestData(baseDir string) (data syscall.Statfs_t) {
err := syscall.Statfs(testDir, &data)
if err != nil {
log.Println("could not check free space:", err)
}
return
}
......@@ -20,47 +23,48 @@ func TestCheckFreeSapce(t *testing.T) {
// First, gather the data
data := gatherTestData("/")
var float64 actualFreePerc = float64(data.Bfree) / float64(data.Bytes)
var int actualFreeGiB = int(freeBytes / GiB)
var actualFreePerc float64 = 100 * float64(data.Bfree) / float64(data.Blocks)
var actualFreeGiB int = int(uint64(data.Bsize) * data.Bfree / GiB)
// Now, let's make a quick run of the test
result := checkFreeSpace(testDir, 0, 0)
var result bool
result = checkFreeSpace(testDir, 0, 0)
if !result {
t.Errorf("Short run failure")
}
// Successful absolute free space
result := checkFreeSpace(testDir, 0, actualFreeGiB/2)
if result {
result = checkFreeSpace(testDir, 0, actualFreeGiB/2)
if !result {
t.Errorf("Error in successful absolute free space test")
}
// Successful relative free space
result := checkFreeSpace(testDir, actualFreePerc/2, 0)
if result {
t.Errorf("Error in successful absolute free space test")
result = checkFreeSpace(testDir, actualFreePerc/2, 0)
if !result {
t.Errorf("Error in successful relative free space test")
}
// Successful combined free space
result := checkFreeSpace(testDir, actualFreePerc/2, actualFreeGiB/2)
if result {
result = checkFreeSpace(testDir, actualFreePerc/2, actualFreeGiB/2)
if !result {
t.Errorf("Error in successful combined free space test")
}
// Failed absolute free space
result := checkFreeSpace(testDir, 0, actualFreeGiB*2)
result = checkFreeSpace(testDir, 0, actualFreeGiB*2)
if result {
t.Errorf("Error in failed absolute free space test")
}
// Failed relative free space
result := checkFreeSpace(testDir, actualFreePerc*2, 0)
result = checkFreeSpace(testDir, actualFreePerc*2, 0)
if result {
t.Errorf("Error in failed absolute free space test")
}
// Failed combined free space
result := checkFreeSpace(testDir, actualFreePerc*2, actualFreeGiB*2)
result = checkFreeSpace(testDir, actualFreePerc*2, actualFreeGiB*2)
if result {
t.Errorf("Error in Failed combined free space test")
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment