From 3c77f8b3c80d84a8c5875e1a4ac909c96ee46563 Mon Sep 17 00:00:00 2001 From: Illyoung Choi Date: Wed, 25 May 2022 14:54:14 -0700 Subject: [PATCH] Use separate subdirectory for each test group --- test/testcases/fs_api_test.go | 46 ++++++++++++++++++++------------- test/testcases/fs_cache_test.go | 9 ++++++- test/testcases/fs_io_test.go | 9 ++++++- test/testcases/fs_test.go | 24 ++++++++++++----- test/testcases/main.go | 27 +++++++++++++++++-- test/testcases/session_test.go | 14 +++++++--- 6 files changed, 96 insertions(+), 33 deletions(-) diff --git a/test/testcases/fs_api_test.go b/test/testcases/fs_api_test.go index cf721ea..3db6f6d 100644 --- a/test/testcases/fs_api_test.go +++ b/test/testcases/fs_api_test.go @@ -3,7 +3,6 @@ package testcases import ( "crypto/sha1" "encoding/hex" - "fmt" "io" "os" "path" @@ -14,14 +13,21 @@ import ( "github.com/cyverse/go-irodsclient/irods/fs" "github.com/cyverse/go-irodsclient/irods/session" "github.com/cyverse/go-irodsclient/irods/types" + "github.com/rs/xid" "github.com/stretchr/testify/assert" ) +var ( + fsAPITestID = xid.New().String() +) + func TestFSAPI(t *testing.T) { setup() defer shutdown() - t.Run("test PrepareSamples", testPrepareSamples) + makeHomeDir(t, fsAPITestID) + + t.Run("test PrepareSamples", testPrepareSamplesForFSAPI) t.Run("test GetIRODSCollection", testGetIRODSCollection) t.Run("test ListIRODSCollections", testListIRODSCollections) t.Run("test ListIRODSCollectionMeta", testListIRODSCollectionMeta) @@ -43,6 +49,10 @@ func TestFSAPI(t *testing.T) { t.Run("test ParallelUploadAndDownloadDataObject", testParallelUploadAndDownloadDataObject) } +func testPrepareSamplesForFSAPI(t *testing.T) { + prepareSamples(t, fsAPITestID) +} + func testGetIRODSCollection(t *testing.T) { account := GetTestAccount() @@ -53,7 +63,7 @@ func testGetIRODSCollection(t *testing.T) { assert.NoError(t, err) defer conn.Disconnect() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsAPITestID) collection, err := fs.GetCollection(conn, homedir) assert.NoError(t, err) @@ -72,7 +82,7 @@ func testListIRODSCollections(t *testing.T) { assert.NoError(t, err) defer conn.Disconnect() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsAPITestID) collections, err := fs.ListSubCollections(conn, homedir) assert.NoError(t, err) @@ -98,7 +108,7 @@ func testListIRODSCollectionMeta(t *testing.T) { assert.NoError(t, err) defer conn.Disconnect() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsAPITestID) metas, err := fs.ListCollectionMeta(conn, homedir) assert.NoError(t, err) @@ -118,7 +128,7 @@ func testListIRODSCollectionAccess(t *testing.T) { assert.NoError(t, err) defer conn.Disconnect() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsAPITestID) accesses, err := fs.ListCollectionAccess(conn, homedir) assert.NoError(t, err) @@ -139,7 +149,7 @@ func testListIRODSDataObjects(t *testing.T) { assert.NoError(t, err) defer conn.Disconnect() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsAPITestID) collection, err := fs.GetCollection(conn, homedir) assert.NoError(t, err) @@ -173,7 +183,7 @@ func testListIRODSDataObjectsMasterReplica(t *testing.T) { assert.NoError(t, err) defer conn.Disconnect() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsAPITestID) collection, err := fs.GetCollection(conn, homedir) assert.NoError(t, err) @@ -209,7 +219,7 @@ func testGetIRODSDataObject(t *testing.T) { assert.NoError(t, err) defer conn.Disconnect() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsAPITestID) collection, err := fs.GetCollection(conn, homedir) assert.NoError(t, err) @@ -243,7 +253,7 @@ func testGetIRODSDataObjectMasterReplica(t *testing.T) { assert.NoError(t, err) defer conn.Disconnect() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsAPITestID) collection, err := fs.GetCollection(conn, homedir) assert.NoError(t, err) @@ -278,7 +288,7 @@ func testListIRODSDataObjectMeta(t *testing.T) { assert.NoError(t, err) defer conn.Disconnect() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsAPITestID) collection, err := fs.GetCollection(conn, homedir) assert.NoError(t, err) @@ -308,7 +318,7 @@ func testListIRODSDataObjectAccess(t *testing.T) { assert.NoError(t, err) defer conn.Disconnect() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsAPITestID) collection, err := fs.GetCollection(conn, homedir) assert.NoError(t, err) @@ -339,7 +349,7 @@ func testCreateDeleteIRODSCollection(t *testing.T) { assert.NoError(t, err) defer conn.Disconnect() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsAPITestID) // create newCollectionPath := homedir + "/test123" @@ -379,7 +389,7 @@ func testCreateMoveDeleteIRODSCollection(t *testing.T) { assert.NoError(t, err) defer conn.Disconnect() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsAPITestID) // create newCollectionPath := homedir + "/test123" @@ -430,7 +440,7 @@ func testCreateDeleteIRODSDataObject(t *testing.T) { assert.NoError(t, err) defer conn.Disconnect() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsAPITestID) // create newDataObjectFilename := "testobj123" @@ -474,7 +484,7 @@ func testReadWriteIRODSDataObject(t *testing.T) { assert.NoError(t, err) defer conn.Disconnect() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsAPITestID) // create newDataObjectFilename := "testobjwrite123" @@ -526,7 +536,7 @@ func testTruncateIRODSDataObject(t *testing.T) { assert.NoError(t, err) defer conn.Disconnect() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsAPITestID) // create newDataObjectFilename := "testobjtruncate123" @@ -673,7 +683,7 @@ func testParallelUploadAndDownloadDataObject(t *testing.T) { return } - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsAPITestID) // gen very large file testval := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" // 62 diff --git a/test/testcases/fs_cache_test.go b/test/testcases/fs_cache_test.go index 13d8202..4a56134 100644 --- a/test/testcases/fs_cache_test.go +++ b/test/testcases/fs_cache_test.go @@ -5,13 +5,20 @@ import ( "testing" "github.com/cyverse/go-irodsclient/fs" + "github.com/rs/xid" "github.com/stretchr/testify/assert" ) +var ( + fsCacheTestID = xid.New().String() +) + func TestFSCache(t *testing.T) { setup() defer shutdown() + makeHomeDir(t, fsCacheTestID) + t.Run("test MakeDir", testMakeDir) } @@ -26,7 +33,7 @@ func testMakeDir(t *testing.T) { assert.NoError(t, err) defer fs.Release() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsCacheTestID) for i := 0; i < 10; i++ { newdir := fmt.Sprintf("%s/test_dir_%d", homedir, i) diff --git a/test/testcases/fs_io_test.go b/test/testcases/fs_io_test.go index 1533576..6ba6505 100644 --- a/test/testcases/fs_io_test.go +++ b/test/testcases/fs_io_test.go @@ -9,13 +9,20 @@ import ( "time" "github.com/cyverse/go-irodsclient/fs" + "github.com/rs/xid" "github.com/stretchr/testify/assert" ) +var ( + fsIOTestID = xid.New().String() +) + func TestFSIO(t *testing.T) { setup() defer shutdown() + makeHomeDir(t, fsIOTestID) + t.Run("test UpDownMBFiles", testUpDownMBFiles) } @@ -30,7 +37,7 @@ func testUpDownMBFiles(t *testing.T) { assert.NoError(t, err) defer fs.Release() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsIOTestID) fileSize := int64(100 * 1024 * 1024) // 100MB localPath, err := createLocalTestFile("test_file_", fileSize) diff --git a/test/testcases/fs_test.go b/test/testcases/fs_test.go index dd8a626..6707ffc 100644 --- a/test/testcases/fs_test.go +++ b/test/testcases/fs_test.go @@ -10,15 +10,21 @@ import ( "time" "github.com/cyverse/go-irodsclient/fs" + "github.com/rs/xid" "github.com/stretchr/testify/assert" ) +var ( + fsTestID = xid.New().String() +) + func TestFS(t *testing.T) { setup() defer shutdown() - t.Run("test PrepareSamples", testPrepareSamples) + makeHomeDir(t, fsTestID) + t.Run("test PrepareSamples", testPrepareSamplesForFS) t.Run("test ListEntries", testListEntries) t.Run("test ListEntriesByMeta", testListEntriesByMeta) t.Run("test ListACLs", testListACLs) @@ -29,6 +35,10 @@ func TestFS(t *testing.T) { t.Run("test RemoveClose", testRemoveClose) } +func testPrepareSamplesForFS(t *testing.T) { + prepareSamples(t, fsTestID) +} + func testListEntries(t *testing.T) { account := GetTestAccount() @@ -40,7 +50,7 @@ func testListEntries(t *testing.T) { assert.NoError(t, err) defer filesystem.Release() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsTestID) collections, err := filesystem.List(homedir) assert.NoError(t, err) @@ -120,7 +130,7 @@ func testReadWrite(t *testing.T) { assert.NoError(t, err) defer filesystem.Release() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsTestID) newDataObjectFilename := "testobj123" newDataObjectPath := homedir + "/" + newDataObjectFilename @@ -170,7 +180,7 @@ func testCreateStat(t *testing.T) { assert.NoError(t, err) defer filesystem.Release() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsTestID) newDataObjectFilename := "testobj_create1234" newDataObjectPath := homedir + "/" + newDataObjectFilename @@ -228,7 +238,7 @@ func testWriteRename(t *testing.T) { assert.NoError(t, err) defer filesystem.Release() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsTestID) newDataObjectFilename := "testobj1234" newDataObjectPath := homedir + "/" + newDataObjectFilename @@ -290,7 +300,7 @@ func testWriteRenameDir(t *testing.T) { assert.NoError(t, err) defer filesystem.Release() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsTestID) newdir := fmt.Sprintf("%s/testdir", homedir) err = filesystem.MakeDir(newdir, true) @@ -361,7 +371,7 @@ func testRemoveClose(t *testing.T) { assert.NoError(t, err) defer filesystem.Release() - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsTestID) newDataObjectFilename := "testobj1234" newDataObjectPath := homedir + "/" + newDataObjectFilename diff --git a/test/testcases/main.go b/test/testcases/main.go index 17a1dbc..50270f8 100644 --- a/test/testcases/main.go +++ b/test/testcases/main.go @@ -120,9 +120,32 @@ func createLocalTestFile(name string, size int64) (string, error) { return tempPath, nil } -func testPrepareSamples(t *testing.T) { +func getHomeDir(testID string) string { account := GetTestAccount() + return fmt.Sprintf("/%s/home/%s/%s", account.ClientZone, account.ClientUser, testID) +} + +func makeHomeDir(t *testing.T, testID string) { + account := GetTestAccount() + account.ClientServerNegotiation = false + + sessionConfig := session.NewIRODSSessionConfigWithDefault("go-irodsclient-test") + + sess, err := session.NewIRODSSession(account, sessionConfig) + assert.NoError(t, err) + defer sess.Release() + + // first + conn, err := sess.AcquireConnection() + assert.NoError(t, err) + homedir := getHomeDir(testID) + err = fs.CreateCollection(conn, homedir, true) + assert.NoError(t, err) +} + +func prepareSamples(t *testing.T, testID string) { + account := GetTestAccount() account.ClientServerNegotiation = false sessionConfig := session.NewIRODSSessionConfigWithDefault("go-irodsclient-test") @@ -135,7 +158,7 @@ func testPrepareSamples(t *testing.T) { conn, err := sess.AcquireConnection() assert.NoError(t, err) - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(testID) collection, err := fs.GetCollection(conn, homedir) assert.NoError(t, err) diff --git a/test/testcases/session_test.go b/test/testcases/session_test.go index 013f3d8..220153a 100644 --- a/test/testcases/session_test.go +++ b/test/testcases/session_test.go @@ -1,20 +1,26 @@ package testcases import ( - "fmt" "testing" "github.com/cyverse/go-irodsclient/irods/connection" "github.com/cyverse/go-irodsclient/irods/fs" "github.com/cyverse/go-irodsclient/irods/session" "github.com/cyverse/go-irodsclient/irods/types" + "github.com/rs/xid" "github.com/stretchr/testify/assert" ) +var ( + fsSessionTestID = xid.New().String() +) + func TestSession(t *testing.T) { setup() defer shutdown() + makeHomeDir(t, fsSessionTestID) + t.Run("test Session", testSession) t.Run("test many Connections", testManyConnections) } @@ -35,7 +41,7 @@ func testSession(t *testing.T) { conn, err := sess.AcquireConnection() assert.NoError(t, err) - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) + homedir := getHomeDir(fsSessionTestID) collection, err := fs.GetCollection(conn, homedir) if err != nil { @@ -62,14 +68,14 @@ func testManyConnections(t *testing.T) { assert.NoError(t, err) defer sess.Release() + homedir := getHomeDir(fsSessionTestID) + connections := []*connection.IRODSConnection{} for i := 0; i < 30; i++ { conn, err := sess.AcquireConnection() assert.NoError(t, err) - homedir := fmt.Sprintf("/%s/home/%s", account.ClientZone, account.ClientUser) - collection, err := fs.GetCollection(conn, homedir) assert.NoError(t, err)