Skip to content

Commit

Permalink
Test Severity const match OTel spec
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Feb 16, 2024
1 parent 8739674 commit a47f4b4
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 1 deletion.
11 changes: 10 additions & 1 deletion log/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ module go.opentelemetry.io/otel/log

go 1.20

require go.opentelemetry.io/otel v1.23.1
require (
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/otel v1.23.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace go.opentelemetry.io/otel/metric => ../metric

Expand Down
6 changes: 6 additions & 0 deletions log/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
220 changes: 220 additions & 0 deletions log/severity_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package log_test

import (
"testing"

"github.com/stretchr/testify/assert"

"go.opentelemetry.io/otel/log"
)

func TestSeverity(t *testing.T) {
// Test the Severity constants match the OTel values and short names.
testCases := []struct {
name string
severity log.Severity
value int
str string
}{
{
name: "SeverityTrace",
severity: log.SeverityTrace,
value: 1,
str: "TRACE",
},
{
name: "SeverityTrace1",
severity: log.SeverityTrace1,
value: 1,
str: "TRACE",
},
{
name: "SeverityTrace2",
severity: log.SeverityTrace2,
value: 2,
str: "TRACE2",
},
{
name: "SeverityTrace3",
severity: log.SeverityTrace3,
value: 3,
str: "TRACE3",
},
{
name: "SeverityTrace4",
severity: log.SeverityTrace4,
value: 4,
str: "TRACE4",
},
{
name: "SeverityDebug",
severity: log.SeverityDebug,
value: 5,
str: "DEBUG",
},
{
name: "SeverityDebug1",
severity: log.SeverityDebug1,
value: 5,
str: "DEBUG",
},
{
name: "SeverityDebug2",
severity: log.SeverityDebug2,
value: 6,
str: "DEBUG2",
},
{
name: "SeverityDebug3",
severity: log.SeverityDebug3,
value: 7,
str: "DEBUG3",
},
{
name: "SeverityDebug4",
severity: log.SeverityDebug4,
value: 8,
str: "DEBUG4",
},
{
name: "SeverityInfo",
severity: log.SeverityInfo,
value: 9,
str: "INFO",
},
{
name: "SeverityInfo1",
severity: log.SeverityInfo1,
value: 9,
str: "INFO",
},
{
name: "SeverityInfo2",
severity: log.SeverityInfo2,
value: 10,
str: "INFO2",
},
{
name: "SeverityInfo3",
severity: log.SeverityInfo3,
value: 11,
str: "INFO3",
},
{
name: "SeverityInfo4",
severity: log.SeverityInfo4,
value: 12,
str: "INFO4",
},
{
name: "SeverityWarn",
severity: log.SeverityWarn,
value: 13,
str: "WARN",
},
{
name: "SeverityWarn1",
severity: log.SeverityWarn1,
value: 13,
str: "WARN",
},
{
name: "SeverityWarn2",
severity: log.SeverityWarn2,
value: 14,
str: "WARN2",
},
{
name: "SeverityWarn3",
severity: log.SeverityWarn3,
value: 15,
str: "WARN3",
},
{
name: "SeverityWarn4",
severity: log.SeverityWarn4,
value: 16,
str: "WARN4",
},
{
name: "SeverityError",
severity: log.SeverityError,
value: 17,
str: "ERROR",
},
{
name: "SeverityError1",
severity: log.SeverityError1,
value: 17,
str: "ERROR",
},
{
name: "SeverityError2",
severity: log.SeverityError2,
value: 18,
str: "ERROR2",
},
{
name: "SeverityError3",
severity: log.SeverityError3,
value: 19,
str: "ERROR3",
},
{
name: "SeverityError4",
severity: log.SeverityError4,
value: 20,
str: "ERROR4",
},
{
name: "SeverityFatal",
severity: log.SeverityFatal,
value: 21,
str: "FATAL",
},
{
name: "SeverityFatal1",
severity: log.SeverityFatal1,
value: 21,
str: "FATAL",
},
{
name: "SeverityFatal2",
severity: log.SeverityFatal2,
value: 22,
str: "FATAL2",
},
{
name: "SeverityFatal3",
severity: log.SeverityFatal3,
value: 23,
str: "FATAL3",
},
{
name: "SeverityFatal4",
severity: log.SeverityFatal4,
value: 24,
str: "FATAL4",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.value, int(tc.severity), "value does not match OTel")
assert.Equal(t, tc.str, tc.severity.String(), "string does not match OTel")
})
}
}

0 comments on commit a47f4b4

Please sign in to comment.