2024-08-21 14:18:44 +05:30
|
|
|
package config
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"testing"
|
2025-01-04 01:28:54 +05:30
|
|
|
"time"
|
2024-08-21 14:18:44 +05:30
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
"go.opentelemetry.io/collector/confmap"
|
2025-01-04 01:28:54 +05:30
|
|
|
"go.signoz.io/signoz/pkg/cache"
|
2024-08-21 14:18:44 +05:30
|
|
|
"go.signoz.io/signoz/pkg/confmap/provider/signozenvprovider"
|
2024-08-22 20:56:15 +05:30
|
|
|
"go.signoz.io/signoz/pkg/web"
|
2024-08-21 14:18:44 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestNewWithSignozEnvProvider(t *testing.T) {
|
2025-01-04 01:28:54 +05:30
|
|
|
|
2024-08-22 20:56:15 +05:30
|
|
|
t.Setenv("SIGNOZ__WEB__PREFIX", "/web")
|
|
|
|
|
t.Setenv("SIGNOZ__WEB__DIRECTORY", "/build")
|
2025-01-04 01:28:54 +05:30
|
|
|
t.Setenv("SIGNOZ__CACHE__PROVIDER", "redis")
|
|
|
|
|
t.Setenv("SIGNOZ__CACHE__REDIS__HOST", "127.0.0.1")
|
2024-08-21 14:18:44 +05:30
|
|
|
|
|
|
|
|
config, err := New(context.Background(), ProviderSettings{
|
|
|
|
|
ResolverSettings: confmap.ResolverSettings{
|
|
|
|
|
URIs: []string{"signozenv:"},
|
|
|
|
|
ProviderFactories: []confmap.ProviderFactory{
|
|
|
|
|
signozenvprovider.NewFactory(),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
expected := &Config{
|
2024-08-22 20:56:15 +05:30
|
|
|
Web: web.Config{
|
|
|
|
|
Prefix: "/web",
|
|
|
|
|
Directory: "/build",
|
|
|
|
|
},
|
2025-01-04 01:28:54 +05:30
|
|
|
Cache: cache.Config{
|
|
|
|
|
Provider: "redis",
|
|
|
|
|
Memory: cache.Memory{
|
|
|
|
|
TTL: time.Duration(-1),
|
|
|
|
|
CleanupInterval: 1 * time.Minute,
|
|
|
|
|
},
|
|
|
|
|
Redis: cache.Redis{
|
|
|
|
|
Host: "127.0.0.1",
|
|
|
|
|
Port: 6379,
|
|
|
|
|
Password: "",
|
|
|
|
|
DB: 0,
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-08-21 14:18:44 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, expected, config)
|
|
|
|
|
}
|