Skip to content

Commit

Permalink
Merge pull request #36 from kjsanger/devel
Browse files Browse the repository at this point in the history
Add tests for iRODS environment configuration
  • Loading branch information
kjsanger authored May 3, 2024
2 parents 016682e + faa6057 commit b06707c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/sqyrrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func CLI() {
"key-file", "",
"Path to the SSL private key file")
startCmd.Flags().StringVar(&cliFlagsSelected.envFilePath,
"irods-env", server.IRODSEnvFilePath(),
"irods-env", server.LookupIRODSEnvFilePath(),
"Path to the iRODS environment file")
startCmd.Flags().DurationVar(&cliFlagsSelected.indexInterval,
"index-interval", server.DefaultIndexInterval,
Expand Down
6 changes: 3 additions & 3 deletions server/irods.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ const (
CategoryAttr = Namespace + NamespaceSeparator + "category"
)

// IRODSEnvFilePath returns the path to the iRODS environment file. If the path
// is not set in the environment, the default path is returned.
func IRODSEnvFilePath() string {
// LookupIRODSEnvFilePath returns the path to the iRODS environment file set in the
// environment. If not set, the default path is returned.
func LookupIRODSEnvFilePath() string {
path := os.Getenv(IRODSEnvFileEnvVar)
if path == "" {
path = IRODSEnvFileDefault
Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func NewSqyrrlServer(logger zerolog.Logger, config Config) (server *SqyrrlServer

var manager *icommands.ICommandsEnvironmentManager
if config.EnvFilePath == "" {
config.EnvFilePath = IRODSEnvFilePath()
config.EnvFilePath = LookupIRODSEnvFilePath()
}

logger.Debug().
Expand Down
45 changes: 41 additions & 4 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net"
"net/http"
"net/url"
"os"
"path/filepath"
"sync"

Expand Down Expand Up @@ -33,9 +34,9 @@ var _ = Describe("Server startup and shutdown", func() {
}
})

When("a server instance is created", func() {
When("a server is created", func() {
It("can be started and stopped", func() {
server, err := server.NewSqyrrlServer(suiteLogger, config)
srv, err := server.NewSqyrrlServer(suiteLogger, config)
Expect(err).NotTo(HaveOccurred())

var startStopErr error
Expand All @@ -44,7 +45,7 @@ var _ = Describe("Server startup and shutdown", func() {
wgStop.Add(1)
go func() {
defer wgStop.Done()
startStopErr = server.Start()
startStopErr = srv.Start()
}()

insecureTransport := http.DefaultTransport.(*http.Transport).Clone()
Expand All @@ -63,10 +64,46 @@ var _ = Describe("Server startup and shutdown", func() {
Eventually(homePage, "5s").Should(BeTrue())
Expect(startStopErr).NotTo(HaveOccurred())

server.Stop()
srv.Stop()
wgStop.Wait()

Expect(startStopErr).NotTo(HaveOccurred())
})
})

When("no iRODS environment file is provided on the command line", func() {
When("no IRODS_ENVIRONMENT_FILE environment variable is set", func() {
It("uses the default iRODS environment file path", func() {
config.EnvFilePath = ""
srv, err := server.NewSqyrrlServer(suiteLogger, config)
Expect(err).NotTo(HaveOccurred())

Expect(srv.IRODSEnvFilePath()).To(Equal(server.LookupIRODSEnvFilePath()))
})
})

When("an IRODS_ENVIRONMENT_FILE environment variable is set", func() {
It("uses the IRODS_ENVIRONMENT_FILE environment variable", func() {
envFilePath := config.EnvFilePath
config.EnvFilePath = ""

serr := os.Setenv("IRODS_ENVIRONMENT_FILE", envFilePath)
Expect(serr).NotTo(HaveOccurred())

srv, err := server.NewSqyrrlServer(suiteLogger, config)
Expect(err).NotTo(HaveOccurred())

Expect(srv.IRODSEnvFilePath()).To(Equal(envFilePath))
})
})
})

When("the configured iRODS environment file is not found", func() {
It("returns an error", func() {
config.EnvFilePath = "nonexistent.json"
srv, err := server.NewSqyrrlServer(suiteLogger, config)
Expect(err).To(HaveOccurred())
Expect(srv).To(BeNil())
})
})
})

0 comments on commit b06707c

Please sign in to comment.