github.com/safedep/dry@v0.0.0-20241016050132-a15651f0548b/config/config_test.go (about) 1 package config 2 3 import ( 4 "testing" 5 6 "github.com/safedep/dry/log" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestDefaultConfigFromEnvironment(t *testing.T) { 11 log.Init("config-test", "test") 12 13 t.Run("APP_SERVICE_NAME", func(t *testing.T) { 14 t.Setenv("APP_SERVICE_NAME", "test-service") 15 16 value, err := AppServiceName.Value() 17 assert.NoError(t, err) 18 19 assert.Equal(t, "test-service", value) 20 }) 21 } 22 23 func TestConfigString(t *testing.T) { 24 t.Run("ValueSet", func(t *testing.T) { 25 t.Setenv("test", "Value") 26 27 c := Config[string]{Name: "test"} 28 v, err := c.Value() 29 assert.NoError(t, err) 30 assert.Equal(t, "Value", v) 31 }) 32 33 } 34 35 func TestConfigInt(t *testing.T) { 36 t.Skip("Skipping test as it is failing") 37 38 t.Run("ValueSet", func(t *testing.T) { 39 t.Setenv("test", "123") 40 41 c := Config[int]{Name: "test"} 42 v, err := c.Value() 43 assert.NoError(t, err) 44 assert.Equal(t, 123, v) 45 }) 46 47 } 48 49 func TestConfigFloat(t *testing.T) { 50 t.Skip("Skipping test as it is failing") 51 52 t.Run("ValueSet", func(t *testing.T) { 53 t.Setenv("test", "123.45") 54 55 c := Config[float64]{Name: "test"} 56 v, err := c.Value() 57 assert.NoError(t, err) 58 assert.Equal(t, 123.45, v) 59 }) 60 61 }