mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-17 15:36:48 +00:00
49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
|
|
package alertmanager
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"github.com/stretchr/testify/assert"
|
||
|
|
"github.com/stretchr/testify/require"
|
||
|
|
"go.signoz.io/signoz/pkg/config"
|
||
|
|
"go.signoz.io/signoz/pkg/config/envprovider"
|
||
|
|
"go.signoz.io/signoz/pkg/factory"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestNewWithEnvProvider(t *testing.T) {
|
||
|
|
t.Setenv("SIGNOZ_ALERTMANAGER_PROVIDER", "legacy")
|
||
|
|
t.Setenv("SIGNOZ_ALERTMANAGER_LEGACY_API__URL", "http://localhost:9093/api")
|
||
|
|
|
||
|
|
conf, err := config.New(
|
||
|
|
context.Background(),
|
||
|
|
config.ResolverConfig{
|
||
|
|
Uris: []string{"env:"},
|
||
|
|
ProviderFactories: []config.ProviderFactory{
|
||
|
|
envprovider.NewFactory(),
|
||
|
|
},
|
||
|
|
},
|
||
|
|
[]factory.ConfigFactory{
|
||
|
|
NewConfigFactory(),
|
||
|
|
},
|
||
|
|
)
|
||
|
|
require.NoError(t, err)
|
||
|
|
|
||
|
|
actual := &Config{}
|
||
|
|
err = conf.Unmarshal("alertmanager", actual)
|
||
|
|
require.NoError(t, err)
|
||
|
|
|
||
|
|
def := NewConfigFactory().New().(Config)
|
||
|
|
|
||
|
|
expected := &Config{
|
||
|
|
Provider: "legacy",
|
||
|
|
Legacy: Legacy{
|
||
|
|
ApiURL: "http://localhost:9093/api",
|
||
|
|
},
|
||
|
|
Signoz: def.Signoz,
|
||
|
|
}
|
||
|
|
|
||
|
|
assert.Equal(t, expected, actual)
|
||
|
|
assert.NoError(t, actual.Validate())
|
||
|
|
}
|