github.com/cyverse/go-irodsclient@v0.13.2/test/server/server.go (about) 1 package server 2 3 import ( 4 "fmt" 5 "os/exec" 6 "path" 7 "runtime" 8 9 "github.com/cyverse/go-irodsclient/irods/types" 10 log "github.com/sirupsen/logrus" 11 "golang.org/x/xerrors" 12 ) 13 14 const ( 15 // must have the same information as in `docker-compose.yml` and `config.inc` 16 testServerContainer string = "irods_test-irods-1" 17 testServerHost string = "localhost" 18 testServerPort int = 1247 19 testServerAdminUser string = "rods" 20 testServerAdminPassword string = "test_rods_password" 21 testServerZone string = "cyverse" 22 ) 23 24 func StartServer() error { 25 logger := log.WithFields(log.Fields{ 26 "package": "server", 27 "function": "StartServer", 28 }) 29 30 logger.Info("Running iRODS test server") 31 _, callerPath, _, _ := runtime.Caller(0) 32 serverDir := path.Dir(callerPath) 33 scriptPath := fmt.Sprintf("%s/%s", serverDir, "start.sh") 34 35 logger.Debugf("Executing %s", scriptPath) 36 cmd := exec.Command(scriptPath) 37 cmd.Dir = serverDir 38 39 err := cmd.Start() 40 if err != nil { 41 startErr := xerrors.Errorf("failed to start iRODS test server: %w", err) 42 logger.Errorf("%+v", startErr) 43 return startErr 44 } 45 46 cmd.Wait() 47 48 return nil 49 } 50 51 func StopServer() error { 52 logger := log.WithFields(log.Fields{ 53 "package": "server", 54 "function": "StopServer", 55 }) 56 57 logger.Info("Stopping iRODS test server") 58 _, callerPath, _, _ := runtime.Caller(0) 59 serverDir := path.Dir(callerPath) 60 scriptPath := fmt.Sprintf("%s/%s", serverDir, "stop.sh") 61 62 logger.Debugf("Executing %s", scriptPath) 63 cmd := exec.Command(scriptPath) 64 cmd.Dir = serverDir 65 66 err := cmd.Start() 67 if err != nil { 68 stopErr := xerrors.Errorf("failed to stop iRODS test server: %w", err) 69 logger.Errorf("%+v", stopErr) 70 return stopErr 71 } 72 73 cmd.Wait() 74 // we don't check it's error because it always return exit code 1 75 76 logger.Info("Successfully stopped iRODS test server") 77 return nil 78 } 79 80 func GetLocalAccount() (*types.IRODSAccount, error) { 81 logger := log.WithFields(log.Fields{ 82 "package": "server", 83 "function": "GetLocalAccount", 84 }) 85 86 account, err := types.CreateIRODSAccount(testServerHost, testServerPort, testServerAdminUser, testServerZone, types.AuthSchemeNative, testServerAdminPassword, "") 87 if err != nil { 88 accountErr := xerrors.Errorf("failed to create irods account: %w", err) 89 logger.Errorf("%+v", accountErr) 90 return nil, accountErr 91 } 92 93 return account, nil 94 }