diff --git a/core/sentry.go b/core/sentry.go index 763ef73..e346552 100644 --- a/core/sentry.go +++ b/core/sentry.go @@ -272,7 +272,7 @@ func (t *SentryTaggedStruct) GetProperty(v interface{}, property string) (name s } if val.Kind() != reflect.Struct { - err = fmt.Errorf("passed value must be struct, %s provided", val.String()) + err = fmt.Errorf("passed value must be struct, %s provided", val.Type().String()) return } diff --git a/core/sentry_test.go b/core/sentry_test.go index c263168..5f197e1 100644 --- a/core/sentry_test.go +++ b/core/sentry_test.go @@ -32,6 +32,7 @@ func (s *SentryTest) SetupTest() { require.Equal(s.T(), "", s.structTags.GetName()) require.Equal(s.T(), "Scalar", s.scalarTags.GetName()) s.structTags.Tags = map[string]string{} + s.sentry = NewSentry("dsn", "unknown_error", SentryTaggedTypes{}, nil, nil) } func (s *SentryTest) TestStruct_AddTag() { @@ -62,9 +63,9 @@ func (s *SentryTest) TestStruct_GetProperty_InvalidStruct() { } func (s *SentryTest) TestStruct_GetProperty_GotScalar() { - _, _, err := s.structTags.GetProperty("str", "Field") + _, _, err := s.structTags.GetProperty("", "Field") require.Error(s.T(), err) - assert.Equal(s.T(), "passed value must be struct, str provided", err.Error()) + assert.Equal(s.T(), "passed value must be struct, string provided", err.Error()) } func (s *SentryTest) TestStruct_GetProperty_InvalidType() { @@ -86,6 +87,88 @@ func (s *SentryTest) TestStruct_GetProperty_InvalidProperty() { assert.Equal(s.T(), "invalid property, got ", err.Error()) } +func (s *SentryTest) TestStruct_BuildTags_Fail() { + s.structTags.Tags = map[string]string{} + s.structTags.AddTag("test", "Field") + _, err := s.structTags.BuildTags(false) + assert.Error(s.T(), err) +} + +func (s *SentryTest) TestStruct_BuildTags() { + s.structTags.Tags = map[string]string{} + s.structTags.AddTag("test", "Field") + tags, err := s.structTags.BuildTags(SampleStruct{Field: "value"}) + + require.NoError(s.T(), err) + require.NotEmpty(s.T(), tags) + i, ok := tags["test"] + require.True(s.T(), ok) + assert.Equal(s.T(), "value", i) +} + +func (s *SentryTest) TestScalar_Get_Nil() { + _, err := s.scalarTags.Get(nil) + require.Error(s.T(), err) + assert.Equal(s.T(), "invalid value provided", err.Error()) +} + +func (s *SentryTest) TestScalar_Get_Struct() { + _, err := s.scalarTags.Get(struct{}{}) + require.Error(s.T(), err) + assert.Equal(s.T(), "passed value must not be struct", err.Error()) +} + +func (s *SentryTest) TestScalar_Get_InvalidType() { + _, err := s.scalarTags.Get(false) + require.Error(s.T(), err) + assert.Equal(s.T(), "passed value should be of type `string`, got `bool` instead", err.Error()) +} + +func (s *SentryTest) TestScalar_Get() { + val, err := s.scalarTags.Get("test") + require.NoError(s.T(), err) + assert.Equal(s.T(), "test", val) +} + +func (s *SentryTest) TestScalar_GetTags() { + assert.Empty(s.T(), s.scalarTags.GetTags()) +} + +func (s *SentryTest) TestScalar_BuildTags_Fail() { + _, err := s.scalarTags.BuildTags(false) + assert.Error(s.T(), err) +} + +func (s *SentryTest) TestScalar_BuildTags() { + tags, err := s.scalarTags.BuildTags("test") + + require.NoError(s.T(), err) + require.NotEmpty(s.T(), tags) + i, ok := tags[s.scalarTags.GetName()] + require.True(s.T(), ok) + assert.Equal(s.T(), "test", i) +} + +func (s *SentryTest) TestSentry_ErrorMiddleware() { + assert.NotNil(s.T(), s.sentry.ErrorMiddleware()) +} + +func (s *SentryTest) TestSentry_PanicLogger() { + assert.NotNil(s.T(), s.sentry.PanicLogger()) +} + +func (s *SentryTest) TestSentry_ErrorLogger() { + assert.NotNil(s.T(), s.sentry.ErrorLogger()) +} + +func (s *SentryTest) TestSentry_ErrorResponseHandler() { + assert.NotNil(s.T(), s.sentry.ErrorResponseHandler()) +} + +func (s *SentryTest) TestSentry_ErrorCaptureHandler() { + assert.NotNil(s.T(), s.sentry.ErrorCaptureHandler()) +} + func TestSentry_newRavenStackTrace_Fail(t *testing.T) { defer func() { assert.NotNil(t, recover()) diff --git a/go.sum b/go.sum index c150edd..c4b4ba9 100644 --- a/go.sum +++ b/go.sum @@ -183,8 +183,10 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= +github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=