Skip to content
Snippets Groups Projects
Commit 900e69e9 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6747 remove envconfig

parent be59c912
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
package config package config
import ( import (
"github.com/kelseyhightower/envconfig"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"log" "log"
"os" "os"
...@@ -48,7 +47,7 @@ type Config struct { ...@@ -48,7 +47,7 @@ type Config struct {
Grpc struct { Grpc struct {
Server struct { Server struct {
Mock bool `yaml:"mock"` Mock bool `yaml:"mock"`
Port int `yaml:"port" envconfig:"GRPC_SERVER_PORT"` Port int `yaml:"port"`
} `yaml:"server"` } `yaml:"server"`
Router struct { Router struct {
Port int `yaml:"port"` Port int `yaml:"port"`
...@@ -85,10 +84,5 @@ func LoadConfig(configFilePath ...string) Config { ...@@ -85,10 +84,5 @@ func LoadConfig(configFilePath ...string) Config {
log.Fatalf("FATAL: error unmarshalling YAML file: %v", err) log.Fatalf("FATAL: error unmarshalling YAML file: %v", err)
} }
err = envconfig.Process("", &config)
if err != nil {
log.Fatalf("FATAL: error reading env: %v", err)
}
return config return config
} }
...@@ -26,9 +26,7 @@ ...@@ -26,9 +26,7 @@
package config package config
import ( import (
"os"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
...@@ -46,57 +44,4 @@ func TestLoadConfig(t *testing.T) { ...@@ -46,57 +44,4 @@ func TestLoadConfig(t *testing.T) {
assert.Equal(t, expectedConfig, config) assert.Equal(t, expectedConfig, config)
}) })
t.Run("should load config from env", func(t *testing.T) {
envVars := map[string]string{
"HTTP_SERVER_PORT": "9090",
"GRPC_SERVER_PORT": "1234",
"GRPC_ROUTER_PORT": "5678",
"LOGGING_LEVEL": "ERROR",
}
for key, value := range envVars {
assert.NoError(t, os.Setenv(key, value), "Setenv "+key+" should not return an error")
}
config := LoadConfig("testdata/empty_test_config.yml")
for key := range envVars {
assert.NoError(t, os.Unsetenv(key), "Unsetenv "+key+" should not return an error")
}
expectedConfig := Config{}
expectedConfig.Grpc.Server.Mock = false
expectedConfig.Http.Server.Port = 9090
expectedConfig.Grpc.Server.Port = 1234
expectedConfig.Grpc.Router.Port = 5678
expectedConfig.Logging.Level = "ERROR"
assert.Equal(t, expectedConfig, config)
})
t.Run("should overwrite config with env", func(t *testing.T) {
envVars := map[string]string{
"HTTP_SERVER_PORT": "9090",
"GRPC_SERVER_PORT": "1234",
}
for key, value := range envVars {
assert.NoError(t, os.Setenv(key, value), "Setenv "+key+" should not return an error")
}
config := LoadConfig()
for key := range envVars {
assert.NoError(t, os.Unsetenv(key), "Unsetenv "+key+" should not return an error")
}
expectedConfig := Config{}
expectedConfig.Grpc.Server.Mock = false
expectedConfig.Http.Server.Port = 9090
expectedConfig.Grpc.Server.Port = 1234
expectedConfig.Grpc.Router.Port = 50051
expectedConfig.Logging.Level = "DEBUG"
assert.Equal(t, expectedConfig, config)
})
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment