rados: reduce boilerplate in TestGetPoolByName using testify

Testfiy's assert and require libs have helpful functions for
checking values. Use them to reduce a bunch of boilerplate code in the
TestGetPoolByName function.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2019-12-20 15:01:57 -05:00 committed by Niels de Vos
parent b5a0045d70
commit 15dfd6fc09

View File

@ -300,18 +300,11 @@ func (suite *RadosTestSuite) TestGetPoolByName() {
// check that new pool name is unique // check that new pool name is unique
new_name := uuid.Must(uuid.NewV4()).String() new_name := uuid.Must(uuid.NewV4()).String()
for _, poolname := range pools { require.NotContains(
if new_name == poolname { suite.T(), pools, new_name, "Random pool name exists!")
suite.T().Error("Random pool name exists!")
return
}
}
pool, _ := suite.conn.GetPoolByName(new_name) pool, _ := suite.conn.GetPoolByName(new_name)
if pool != 0 { assert.Equal(suite.T(), int64(0), pool, "Pool does not exist, but was found!")
suite.T().Error("Pool does not exist, but was found!")
return
}
// create pool // create pool
err = suite.conn.MakePool(new_name) err = suite.conn.MakePool(new_name)
@ -320,24 +313,12 @@ func (suite *RadosTestSuite) TestGetPoolByName() {
// verify that the new pool name exists // verify that the new pool name exists
pools, err = suite.conn.ListPools() pools, err = suite.conn.ListPools()
assert.NoError(suite.T(), err) assert.NoError(suite.T(), err)
assert.Contains(
found := false suite.T(), pools, new_name, "Cannot find newly created pool")
for _, poolname := range pools {
if new_name == poolname {
found = true
}
}
if !found {
suite.T().Error("Cannot find newly created pool")
}
pool, err = suite.conn.GetPoolByName(new_name) pool, err = suite.conn.GetPoolByName(new_name)
assert.NoError(suite.T(), err) assert.NoError(suite.T(), err)
if pool == 0 { assert.NotEqual(suite.T(), int64(0), pool, "Pool not found!")
suite.T().Error("Pool not found!")
return
}
// delete the pool // delete the pool
err = suite.conn.DeletePool(new_name) err = suite.conn.DeletePool(new_name)
@ -346,23 +327,13 @@ func (suite *RadosTestSuite) TestGetPoolByName() {
// verify that it is gone // verify that it is gone
pools, err = suite.conn.ListPools() pools, err = suite.conn.ListPools()
assert.NoError(suite.T(), err) assert.NoError(suite.T(), err)
assert.NotContains(
found = false suite.T(), pools, new_name, "Deleted pool still exists")
for _, poolname := range pools {
if new_name == poolname {
found = true
}
}
if found {
suite.T().Error("Deleted pool still exists")
}
pool, err = suite.conn.GetPoolByName(new_name) pool, err = suite.conn.GetPoolByName(new_name)
if pool != 0 || err == nil { assert.Error(suite.T(), err)
suite.T().Error("Pool should have been deleted, but was found!") assert.Equal(
return suite.T(), int64(0), pool, "Pool should have been deleted, but was found!")
}
} }
func (suite *RadosTestSuite) TestGetPoolByID() { func (suite *RadosTestSuite) TestGetPoolByID() {