Skip to content

Commit

Permalink
Merge pull request #23 from cyverse/irods_env_file
Browse files Browse the repository at this point in the history
Implement icommands session and refactor
  • Loading branch information
iychoi authored May 13, 2022
2 parents c609281 + 4538c50 commit a6b2135
Show file tree
Hide file tree
Showing 3 changed files with 347 additions and 172 deletions.
74 changes: 65 additions & 9 deletions test/testcases/irods_environment_test.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,86 @@
package testcases

import (
"os"
"path/filepath"
"testing"

"github.com/cyverse/go-irodsclient/test/server"
"github.com/cyverse/go-irodsclient/utils/icommands"
"github.com/stretchr/testify/assert"
)

func TestIRODSEnvironment(t *testing.T) {
//t.Run("test LoadCurrentUserEnv", testLoadCurrentUserEnv)
//t.Run("test SaveEnv", testSaveEnv)
t.Run("test SaveAndLoadEnv", testSaveAndLoadEnv)
t.Run("test SaveAndLoadEnvSession", testSaveAndLoadEnvSession)
}

/*
func testLoadCurrentUserEnv(t *testing.T) {
account, err := icommands.CreateAccountFromCurrentUserAndHome()
func testSaveAndLoadEnv(t *testing.T) {
account, err := server.GetLocalAccount()
assert.NoError(t, err)

homeDir, err := os.UserHomeDir()
assert.NoError(t, err)

newEnvDir := filepath.Join(homeDir, ".irods2")
envMgr, err := icommands.CreateIcommandsEnvironmentManagerFromIRODSAccount(newEnvDir, 0, account)
assert.NoError(t, err)

err = envMgr.Save()
assert.NoError(t, err)

envMgr2, err := icommands.CreateIcommandsEnvironmentManager(newEnvDir, 0)
assert.NoError(t, err)

envMgr2.Load()

env2 := envMgr2.GetEnvironment()
assert.Equal(t, account.Host, env2.Host)
assert.Equal(t, account.Port, env2.Port)
assert.Equal(t, account.ClientZone, env2.Zone)
assert.Equal(t, account.ClientUser, env2.Username)
assert.Equal(t, account.Password, envMgr2.GetPassword())

err = os.RemoveAll(newEnvDir)
assert.NoError(t, err)
assert.Equal(t, "iychoi", account.ClientUser)
}

func testSaveEnv(t *testing.T) {
func testSaveAndLoadEnvSession(t *testing.T) {
account, err := server.GetLocalAccount()
assert.NoError(t, err)

homeDir, err := os.UserHomeDir()
assert.NoError(t, err)

newEnvDir := filepath.Join(homeDir, ".irods2")
err = icommands.SaveAccountToDir(newEnvDir, 0, account)
envMgr, err := icommands.CreateIcommandsEnvironmentManagerFromIRODSAccount(newEnvDir, 0, account)
assert.NoError(t, err)

testWorkingDir := "/test/working/dir"

envMgr.GetSession().CurrentWorkingDir = testWorkingDir

err = envMgr.Save()
assert.NoError(t, err)
err = envMgr.SaveSession()
assert.NoError(t, err)

envMgr2, err := icommands.CreateIcommandsEnvironmentManager(newEnvDir, 0)
assert.NoError(t, err)

envMgr2.Load()

env2 := envMgr2.GetEnvironment()
assert.Equal(t, account.Host, env2.Host)
assert.Equal(t, account.Port, env2.Port)
assert.Equal(t, account.ClientZone, env2.Zone)
assert.Equal(t, account.ClientUser, env2.Username)
assert.Equal(t, account.Password, envMgr2.GetPassword())

sess2 := envMgr2.GetSession()
t.Logf("%v", sess2)
assert.Equal(t, testWorkingDir, sess2.CurrentWorkingDir)

err = os.RemoveAll(newEnvDir)
assert.NoError(t, err)
}
*/
Loading

0 comments on commit a6b2135

Please sign in to comment.