status-go/internal/sentry/params_test.go
Igor Sirotin 987a9e8707
feat_: add Sentry panic reporting (#6054)
* feat_: report panics to sentry

* test_: sentry options, params and utils

* feat_: toggle sentry with centralized metrics

* test_: sentry init, report and close

* refactor_: rename public api to generic

* docs_: sentry

* fix_: typo in internal/sentry/README.md

Co-authored-by: osmaczko <33099791+osmaczko@users.noreply.github.com>

* fix_: linter

---------

Co-authored-by: osmaczko <33099791+osmaczko@users.noreply.github.com>
2024-11-25 12:13:47 +00:00

49 lines
1.2 KiB
Go

package sentry
import (
"os"
"testing"
"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/require"
)
func setEnvVar(t *testing.T, varName, value string) {
err := os.Setenv(varName, value)
require.NoError(t, err)
t.Cleanup(func() {
err = os.Unsetenv(varName)
require.NoError(t, err)
})
}
func TestEnvironment(t *testing.T) {
t.Parallel()
t.Run("returns production environment when production is true", func(t *testing.T) {
varName := gofakeit.LetterN(10)
setEnvVar(t, varName, "development")
// Expect production although the env variable is set to development
result := environment(true, varName)
require.Equal(t, productionEnvironment, result)
})
t.Run("returns empty string when env is productionEnvironment", func(t *testing.T) {
varName := gofakeit.LetterN(10)
setEnvVar(t, varName, productionEnvironment)
result := environment(false, varName)
require.Equal(t, "", result)
})
t.Run("returns environment variable when production is false", func(t *testing.T) {
varName := gofakeit.LetterN(10)
expectedEnv := "development"
setEnvVar(t, varName, expectedEnv)
result := environment(false, varName)
require.Equal(t, expectedEnv, result)
})
}