Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func main() {
conf.Cfg.PgHost,
conf.AppUserName,
conf.Cfg.AppUserPassword,
conf.DbName,
conf.Cfg.DbName,
)
dbClient := pgsql.NewClient(context.Background(), dsn, conf.GormConfig)
// TODO: wrap this and call it securely
Expand Down
4 changes: 2 additions & 2 deletions pkg/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (

const (
AppUserName = "sourcescore"
DbName = "sourcescore"
)

type conf struct {
AppUserPassword string `env:"APP_USER_PASSWORD" yaml:"APP_USER_PASSWORD" env-required:"true"`
DbName string `env:"DB_NAME" yaml:"DB_NAME" env-default:"sourcescore"`
PgHost string `env:"PG_HOST" yaml:"PG_HOST" env-required:"true"`
Port string `env:"PORT" yaml:"PORT"`
Port string `env:"PORT" yaml:"PORT" env-default:"8080"`
SuperUserPassword string `env:"SUPER_USER_PASSWORD" yaml:"SUPER_USER_PASSWORD" env-required:"true"`
}

Expand Down
29 changes: 29 additions & 0 deletions pkg/conf/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
SamplePwd = "sample-pwd"
SampleHost = "sample-host"
SampleSUPwd = "super-pwd"
SampleDbName = "test-db"
)

var _ = Describe("Conf Tests", func() {
Expand Down Expand Up @@ -44,4 +45,32 @@ var _ = Describe("Conf Tests", func() {
Expect(conf.Cfg.SuperUserPassword).To(BeEquivalentTo("user-pwd"))
})
})

When("DbName field is read", func() {
It("should use default value when DB_NAME environment variable is not set", func() {
os.Unsetenv("DOTENV_PATH")
os.Unsetenv("DB_NAME")
os.Setenv("APP_USER_PASSWORD", SamplePwd)
os.Setenv("PG_HOST", SampleHost)
os.Setenv("PORT", SamplePort)
os.Setenv("SUPER_USER_PASSWORD", SampleSUPwd)

conf.LoadConfig()

Expect(conf.Cfg.DbName).To(BeEquivalentTo("sourcescore"))
})

It("should be overwritten when DB_NAME environment variable is set", func() {
os.Unsetenv("DOTENV_PATH")
os.Setenv("DB_NAME", SampleDbName)
os.Setenv("APP_USER_PASSWORD", SamplePwd)
os.Setenv("PG_HOST", SampleHost)
os.Setenv("PORT", SamplePort)
os.Setenv("SUPER_USER_PASSWORD", SampleSUPwd)

conf.LoadConfig()

Expect(conf.Cfg.DbName).To(BeEquivalentTo(SampleDbName))
})
})
})
Loading