rados: include rados_test.go in rados package

Keeping the _test.go code in the same package allows for the testing
of private functions. AFAIK it is more conventional as well.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2019-12-13 11:53:11 -05:00 committed by Niels de Vos
parent 750fe1830e
commit 8a2d18be87
1 changed files with 18 additions and 19 deletions

View File

@ -1,4 +1,4 @@
package rados_test package rados
import ( import (
"encoding/json" "encoding/json"
@ -12,7 +12,6 @@ import (
"testing" "testing"
"time" "time"
"github.com/ceph/go-ceph/rados"
"github.com/gofrs/uuid" "github.com/gofrs/uuid"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -21,14 +20,14 @@ import (
type RadosTestSuite struct { type RadosTestSuite struct {
suite.Suite suite.Suite
conn *rados.Conn conn *Conn
ioctx *rados.IOContext ioctx *IOContext
pool string pool string
count int count int
} }
func (suite *RadosTestSuite) SetupSuite() { func (suite *RadosTestSuite) SetupSuite() {
conn, err := rados.NewConn() conn, err := NewConn()
require.NoError(suite.T(), err) require.NoError(suite.T(), err)
defer conn.Shutdown() defer conn.Shutdown()
@ -50,7 +49,7 @@ func (suite *RadosTestSuite) SetupTest() {
suite.ioctx = nil suite.ioctx = nil
suite.count = 0 suite.count = 0
conn, err := rados.NewConn() conn, err := NewConn()
require.NoError(suite.T(), err) require.NoError(suite.T(), err)
suite.conn = conn suite.conn = conn
suite.conn.ReadDefaultConfigFile() suite.conn.ReadDefaultConfigFile()
@ -90,7 +89,7 @@ func (suite *RadosTestSuite) TearDownTest() {
} }
func (suite *RadosTestSuite) TearDownSuite() { func (suite *RadosTestSuite) TearDownSuite() {
conn, err := rados.NewConn() conn, err := NewConn()
require.NoError(suite.T(), err) require.NoError(suite.T(), err)
defer conn.Shutdown() defer conn.Shutdown()
@ -103,7 +102,7 @@ func (suite *RadosTestSuite) TearDownSuite() {
} }
func TestVersion(t *testing.T) { func TestVersion(t *testing.T) {
var major, minor, patch = rados.Version() var major, minor, patch = Version()
assert.False(t, major < 0 || major > 1000, "invalid major") assert.False(t, major < 0 || major > 1000, "invalid major")
assert.False(t, minor < 0 || minor > 1000, "invalid minor") assert.False(t, minor < 0 || minor > 1000, "invalid minor")
assert.False(t, patch < 0 || patch > 1000, "invalid patch") assert.False(t, patch < 0 || patch > 1000, "invalid patch")
@ -461,7 +460,7 @@ func (suite *RadosTestSuite) TestReadNotFound() {
var bytes []byte var bytes []byte
oid := suite.GenObjectName() oid := suite.GenObjectName()
_, err := suite.ioctx.Read(oid, bytes, 0) _, err := suite.ioctx.Read(oid, bytes, 0)
assert.Equal(suite.T(), err, rados.RadosErrorNotFound) assert.Equal(suite.T(), err, RadosErrorNotFound)
} }
func (suite *RadosTestSuite) TestDeleteNotFound() { func (suite *RadosTestSuite) TestDeleteNotFound() {
@ -469,7 +468,7 @@ func (suite *RadosTestSuite) TestDeleteNotFound() {
oid := suite.GenObjectName() oid := suite.GenObjectName()
err := suite.ioctx.Delete(oid) err := suite.ioctx.Delete(oid)
assert.Equal(suite.T(), err, rados.RadosErrorNotFound) assert.Equal(suite.T(), err, RadosErrorNotFound)
} }
func (suite *RadosTestSuite) TestStatNotFound() { func (suite *RadosTestSuite) TestStatNotFound() {
@ -477,7 +476,7 @@ func (suite *RadosTestSuite) TestStatNotFound() {
oid := suite.GenObjectName() oid := suite.GenObjectName()
_, err := suite.ioctx.Stat(oid) _, err := suite.ioctx.Stat(oid)
assert.Equal(suite.T(), err, rados.RadosErrorNotFound) assert.Equal(suite.T(), err, RadosErrorNotFound)
} }
func (suite *RadosTestSuite) TestObjectStat() { func (suite *RadosTestSuite) TestObjectStat() {
@ -710,7 +709,7 @@ func (suite *RadosTestSuite) TestObjectIteratorAcrossNamespaces() {
objectListNS2 := []string{} objectListNS2 := []string{}
// populate list of current objects // populate list of current objects
suite.ioctx.SetNamespace(rados.RadosAllNamespaces) suite.ioctx.SetNamespace(RadosAllNamespaces)
existingList := []string{} existingList := []string{}
iter, err := suite.ioctx.Iter() iter, err := suite.ioctx.Iter()
assert.NoError(suite.T(), err) assert.NoError(suite.T(), err)
@ -743,7 +742,7 @@ func (suite *RadosTestSuite) TestObjectIteratorAcrossNamespaces() {
} }
assert.True(suite.T(), len(createdList) == 20) assert.True(suite.T(), len(createdList) == 20)
suite.ioctx.SetNamespace(rados.RadosAllNamespaces) suite.ioctx.SetNamespace(RadosAllNamespaces)
iter, err = suite.ioctx.Iter() iter, err = suite.ioctx.Iter()
assert.NoError(suite.T(), err) assert.NoError(suite.T(), err)
rogueList := []string{} rogueList := []string{}
@ -777,12 +776,12 @@ func (suite *RadosTestSuite) TestObjectIteratorAcrossNamespaces() {
} }
func (suite *RadosTestSuite) TestNewConnWithUser() { func (suite *RadosTestSuite) TestNewConnWithUser() {
_, err := rados.NewConnWithUser("admin") _, err := NewConnWithUser("admin")
assert.Equal(suite.T(), err, nil) assert.Equal(suite.T(), err, nil)
} }
func (suite *RadosTestSuite) TestNewConnWithClusterAndUser() { func (suite *RadosTestSuite) TestNewConnWithClusterAndUser() {
_, err := rados.NewConnWithClusterAndUser("ceph", "client.admin") _, err := NewConnWithClusterAndUser("ceph", "client.admin")
assert.Equal(suite.T(), err, nil) assert.Equal(suite.T(), err, nil)
} }
@ -980,7 +979,7 @@ func (suite *RadosTestSuite) TestSetNamespace() {
// oid isn't seen in space1 ns // oid isn't seen in space1 ns
suite.ioctx.SetNamespace("space1") suite.ioctx.SetNamespace("space1")
stat, err = suite.ioctx.Stat(oid) stat, err = suite.ioctx.Stat(oid)
assert.Equal(suite.T(), err, rados.RadosErrorNotFound) assert.Equal(suite.T(), err, RadosErrorNotFound)
// create oid2 in space1 ns // create oid2 in space1 ns
oid2 := suite.GenObjectName() oid2 := suite.GenObjectName()
@ -990,7 +989,7 @@ func (suite *RadosTestSuite) TestSetNamespace() {
suite.ioctx.SetNamespace("") suite.ioctx.SetNamespace("")
stat, err = suite.ioctx.Stat(oid2) stat, err = suite.ioctx.Stat(oid2)
assert.Equal(suite.T(), err, rados.RadosErrorNotFound) assert.Equal(suite.T(), err, RadosErrorNotFound)
stat, err = suite.ioctx.Stat(oid) stat, err = suite.ioctx.Stat(oid)
assert.Equal(suite.T(), uint64(len(bytes_in)), stat.Size) assert.Equal(suite.T(), uint64(len(bytes_in)), stat.Size)
@ -1028,7 +1027,7 @@ func (suite *RadosTestSuite) TestListAcrossNamespaces() {
assert.EqualValues(suite.T(), 1, nsFoundObjects) assert.EqualValues(suite.T(), 1, nsFoundObjects)
// count objects in pool // count objects in pool
suite.ioctx.SetNamespace(rados.RadosAllNamespaces) suite.ioctx.SetNamespace(RadosAllNamespaces)
allFoundObjects := 0 allFoundObjects := 0
err = suite.ioctx.ListObjects(func(oid string) { err = suite.ioctx.ListObjects(func(oid string) {
allFoundObjects++ allFoundObjects++
@ -1131,7 +1130,7 @@ func (suite *RadosTestSuite) TestOmapOnNonexistentObjectError() {
suite.SetupConnection() suite.SetupConnection()
oid := suite.GenObjectName() oid := suite.GenObjectName()
_, err := suite.ioctx.GetAllOmapValues(oid, "", "", 100) _, err := suite.ioctx.GetAllOmapValues(oid, "", "", 100)
assert.Equal(suite.T(), err, rados.RadosErrorNotFound) assert.Equal(suite.T(), err, RadosErrorNotFound)
} }
func TestRadosTestSuite(t *testing.T) { func TestRadosTestSuite(t *testing.T) {