Files
o11y/pkg/sqlstore/config_test.go
zeekayandGitHub b838309bd6 test(config): complete O11Y_ env-prefix debrand across all env-provider tests (#12)
281d622 renamed the env provider prefix SIGNOZ_ -> O11Y_ and updated only
provider_test.go, leaving every downstream env-provider consumer test still
setting the old SIGNOZ_ prefix. Those envs are now ignored by the O11Y_ provider,
so 7 packages failed `go test ./...` (CI red on main): pprof, web, sqlstore,
alertmanager, instrumentation, apiserver, cmd.

Rename the leading env prefix to O11Y_ in these tests (and align alertmanager's
`const prefix` + clearEnv helper). Scope is strictly the env-config prefix:
ClickHouse wire identifiers (constants.SIGNOZ_*_TABLENAME/_DBNAME) and query
reserved vars (SIGNOZ_START_TIME/#SIGNOZ_VALUE) are the datastore schema/query
contract and are deliberately untouched, matching 281d622's "store stays
ClickHouse wire-protocol".

go build ./... green; go test -count=1 -skip '^TestEmailRejected$' ./... = 125
packages OK, 0 failures.
2026-07-02 17:42:56 -07:00

59 lines
1.4 KiB
Go

package sqlstore
import (
"context"
"testing"
"time"
"github.com/hanzoai/o11y/pkg/config"
"github.com/hanzoai/o11y/pkg/config/envprovider"
"github.com/hanzoai/o11y/pkg/factory"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewWithEnvProvider(t *testing.T) {
t.Setenv("O11Y_SQLSTORE_PROVIDER", "sqlite")
t.Setenv("O11Y_SQLSTORE_SQLITE_PATH", "/tmp/test.db")
t.Setenv("O11Y_SQLSTORE_SQLITE_MODE", "wal")
t.Setenv("O11Y_SQLSTORE_SQLITE_BUSY__TIMEOUT", "5s")
t.Setenv("O11Y_SQLSTORE_SQLITE_TRANSACTION__MODE", "immediate")
t.Setenv("O11Y_SQLSTORE_MAX__OPEN__CONNS", "50")
t.Setenv("O11Y_SQLSTORE_MAX__CONN__LIFETIME", "3h")
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("sqlstore", actual)
require.NoError(t, err)
expected := &Config{
Provider: "sqlite",
Connection: ConnectionConfig{
MaxOpenConns: 50,
MaxConnLifetime: time.Hour * 3,
},
Sqlite: SqliteConfig{
Path: "/tmp/test.db",
Mode: "wal",
BusyTimeout: 5 * time.Second,
TransactionMode: "immediate",
},
}
assert.Equal(t, expected, actual)
assert.NoError(t, actual.Validate())
}