Skip to content

Commit

Permalink
Set a default value for ATHENS_MONGO_CONNECTION_STRING env var (gomod…
Browse files Browse the repository at this point in the history
…s#580)

* Set a default value for ATHENS_MONGO_CONNECTION_STRING env var

- ATHENS_MONGO_CONNECTION_STRING will default to mongodb://127.0.0.1:27017 if not set

* Fix Get function call

* Update user of env.MongoConnectionString
  • Loading branch information
artmello authored and marpio committed Aug 28, 2018
1 parent 69a5340 commit e5ce3f7
Show file tree
Hide file tree
Showing 11 changed files with 10 additions and 44 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ env:
- GO_ENV=test
- MINIO_ACCESS_KEY=minio
- MINIO_SECRET_KEY=minio123
- ATHENS_MONGO_CONNECTION_STRING=mongodb://127.0.0.1:27017
- CODE_COV=1
- ATHENS_DIR=${GOPATH}/src/github.com/gomods/athens
- REGISTRY=gomods/
Expand Down
1 change: 0 additions & 1 deletion cmd/olympus/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
ATHENS_MONGO_CONNECTION_STRING=mongodb://127.0.0.1:27017
PORT=:3001
5 changes: 1 addition & 4 deletions cmd/olympus/actions/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ func Test_ActionSuite(t *testing.T) {
if err != nil {
t.Fatalf("error creating storage (%s)", err)
}
mURI, err := env.MongoConnectionString()
if err != nil {
t.Fatalf("error getting mongo uri (%s)", err)
}
mURI := env.MongoConnectionString()
certPath := env.MongoCertPath()
eLog, err := mongo.NewLog(mURI, certPath)
if err != nil {
Expand Down
10 changes: 2 additions & 8 deletions cmd/olympus/actions/eventlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,15 @@ import (

// GetEventLog returns implementation of eventlog.EventLog
func GetEventLog() (eventlog.Eventlog, error) {
connectionString, err := env.MongoConnectionString()
if err != nil {
return nil, err
}
connectionString := env.MongoConnectionString()
certPath := env.MongoCertPath()
l, err := mongo.NewLog(connectionString, certPath)
return l, err
}

// NewCacheMissesLog returns impl. of eventlog.Appender
func NewCacheMissesLog() (eventlog.Appender, error) {
connectionString, err := env.MongoConnectionString()
if err != nil {
return nil, err
}
connectionString := env.MongoConnectionString()
certPath := env.MongoCertPath()
l, err := mongo.NewLogWithCollection(connectionString, certPath, "cachemisseslog")
return l, err
Expand Down
5 changes: 1 addition & 4 deletions cmd/olympus/actions/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ func GetStorage() (storage.Backend, error) {
}
return s, nil
case "mongo":
connectionString, err := env.MongoConnectionString()
if err != nil {
return nil, err
}
connectionString := env.MongoConnectionString()
certPath := env.MongoCertPath()
return mongo.NewStorageWithCert(connectionString, certPath)
default:
Expand Down
1 change: 0 additions & 1 deletion cmd/proxy/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
ATHENS_MONGO_CONNECTION_STRING=mongodb://127.0.0.1:27017
ATHENS_STORAGE_TYPE=mongo
GO_ENV=test
6 changes: 1 addition & 5 deletions cmd/proxy/actions/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ func GetStorage() (storage.Backend, error) {
case "memory":
return mem.NewStorage()
case "mongo":
connectionString, err := env.MongoConnectionString()
if err != nil {
return nil, err
}

connectionString := env.MongoConnectionString()
certPath := env.MongoCertPath()
return mongo.NewStorageWithCert(connectionString, certPath)
case "disk":
Expand Down
9 changes: 2 additions & 7 deletions pkg/config/env/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ import (
)

// MongoConnectionString returns Athens Mongo Storage connection string defined by ATHENS_MONGO_CONNECTION_STRING
func MongoConnectionString() (string, error) {
env, err := envy.MustGet("ATHENS_MONGO_CONNECTION_STRING")
if err != nil {
return "", fmt.Errorf("missing mongo connection string: %s", err)
}

return env, nil
func MongoConnectionString() string {
return envy.Get("ATHENS_MONGO_CONNECTION_STRING", "mongodb://127.0.0.1:27017")
}

// MongoCertPath returns Athens Mongo Storage cert path string defined by ATHENS_MONGO_CERT_PATH
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/mongo/mongo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "github.com/gomods/athens/pkg/config/env"

func (m *MongoTests) TestNewMongoStorage() {
r := m.Require()
muri, err := env.MongoConnectionString()
muri := env.MongoConnectionString()
certPath := env.MongoCertPath()
getterSaver, err := NewStorageWithCert(muri, certPath)

Expand Down
10 changes: 2 additions & 8 deletions pkg/storage/mongo/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ func NewTestSuite(model *suite.Model) (storage.TestSuite, error) {
}

func newTestStore() (*ModuleStore, error) {
muri, err := env.MongoConnectionString()
if err != nil {
return nil, err
}
muri := env.MongoConnectionString()
certPath := env.MongoCertPath()
mongoStore, err := NewStorageWithCert(muri, certPath)
if err != nil {
Expand All @@ -53,10 +50,7 @@ func (ts *TestSuite) StorageHumanReadableName() string {

// Cleanup tears down test
func (ts *TestSuite) Cleanup() error {
muri, err := env.MongoConnectionString()
if err != nil {
return err
}
muri := env.MongoConnectionString()
timeout := env.MongoConnectionTimeoutSecWithDefault(1)
s, err := mgo.DialWithTimeout(muri, timeout)
defer s.Close()
Expand Down
4 changes: 0 additions & 4 deletions scripts/test_unit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

# test_unit.sh

if [ -z ${ATHENS_MONGO_CONNECTION_STRING} ]; then
export ATHENS_MONGO_CONNECTION_STRING="mongodb://127.0.0.1:27017"
fi

if [ -z ${GO_ENV} ]; then
export GO_ENV="test"
fi
Expand Down

0 comments on commit e5ce3f7

Please sign in to comment.