github.com/blend/go-sdk@v1.20220411.3/sentry/config_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package sentry 9 10 import ( 11 "context" 12 "testing" 13 14 "github.com/blend/go-sdk/assert" 15 "github.com/blend/go-sdk/env" 16 ) 17 18 func Test_Config_Resolve(t *testing.T) { 19 its := assert.New(t) 20 21 vars := env.Vars{ 22 "SENTRY_DSN": "test-dsn", 23 env.VarServiceEnv: env.ServiceEnvTest, 24 env.VarServiceName: "sentry-test", 25 } 26 27 cfg := new(Config) 28 err := cfg.Resolve(env.WithVars(context.Background(), vars)) 29 its.Nil(err) 30 its.Equal("test-dsn", cfg.DSN) 31 its.False(cfg.IsZero()) 32 its.Equal(env.ServiceEnvTest, cfg.Environment) 33 its.Equal("sentry-test", cfg.ServerName) 34 } 35 36 func Test_Config_Resolve_noDSN(t *testing.T) { 37 its := assert.New(t) 38 39 vars := env.Vars{ 40 env.VarServiceEnv: env.ServiceEnvTest, 41 env.VarServiceName: "sentry-test", 42 } 43 44 cfg := new(Config) 45 err := cfg.Resolve(env.WithVars(context.Background(), vars)) 46 its.Nil(err) 47 its.Empty(cfg.DSN) 48 its.True(cfg.IsZero()) 49 its.Equal(env.ServiceEnvTest, cfg.Environment) 50 its.Equal("sentry-test", cfg.ServerName) 51 } 52 53 func Test_Config_GetDSNHost(t *testing.T) { 54 its := assert.New(t) 55 56 cfg := &Config{ 57 DSN: "https://admin:nopasswd@example.com/buzz/fuzz?query=value", 58 } 59 its.Equal("https://example.com", cfg.GetDSNHost()) 60 }