Exemple #1
0
func (s *preallocSuite) TestFsAvailSpaceErrors(c *gc.C) {
	tests := []struct {
		desc   string
		output string
		err    string
	}{{
		desc: "result is non-numeric",
		output: `Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/vda1        8124856 1365292       abc  18% /`,
		err: `strconv.ParseInt: parsing "abc": invalid syntax`,
	}, {
		desc:   "not enough lines",
		output: "abc",
		err:    `could not determine available space on ""`,
	}, {
		desc:   "not enough fields on second line",
		output: "abc\ndef",
		err:    `could not determine available space on ""`,
	}}
	for i, test := range tests {
		c.Logf("test %d: %s", i, test.desc)
		testing.PatchExecutable(c, s, "df", "#!/bin/sh\ncat<<EOF\n"+test.output+"\nEOF")
		_, err := mongo.FsAvailSpace("")
		c.Check(err, gc.ErrorMatches, test.err)
	}
}
Exemple #2
0
func (s *preallocSuite) TestFsAvailSpace(c *gc.C) {
	output := `Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/vda1        8124856 1365292     12345  18% /`
	testing.PatchExecutable(c, s, "df", "#!/bin/sh\ncat<<EOF\n"+output+"\nEOF")

	mb, err := mongo.FsAvailSpace("")
	c.Assert(err, gc.IsNil)
	c.Assert(mb, gc.Equals, float64(12345)/1024)
}