Skip to content

Commit

Permalink
Added unit tests in internal/tracegen
Browse files Browse the repository at this point in the history
- part of jaegertracing#5068

- This commit adds tests for the `Run` function defined in the
  `internal/tracegen` package.

- make test

- [x] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [x] I have signed all commits
- [x] I have added unit tests for the new functionality
- [x] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`

---------

Signed-off-by: VaibhavMalik4187 <[email protected]>
  • Loading branch information
VaibhavMalik4187 committed Jan 19, 2024
1 parent 88efe47 commit 764b0a5
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions internal/tracegen/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright (c) 2018 The Jaeger 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 tracegen

import (
"errors"
"testing"
"time"

"github.com/stretchr/testify/assert"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"
)

func Test_Run(t *testing.T) {
logger := zap.NewNop()
tp := sdktrace.NewTracerProvider()
// tracers := []trace.Tracer{tp.Tracer(cfg.Service)}

tests := []struct {
name string
config *Config
expectedErr error
}{
{
name: "Empty config",
config: &Config{},
expectedErr: errors.New("either `traces` or `duration` must be greater than 0"),
},
{
name: "Non-empty config",
config: &Config{
Workers: 2,
Traces: 10,
ChildSpans: 5,
Attributes: 20,
AttrKeys: 50,
AttrValues: 100,
Duration: time.Second,
Service: "custom",
},
expectedErr: nil,
},
{
name: "Traces and duration set to 0",
config: &Config{
Traces: 0,
Duration: 0,
},
expectedErr: errors.New("either `traces` or `duration` must be greater than 0"),
},
{
name: "Negative traces, positive duration",
config: &Config{
Traces: -7,
Duration: 7,
},
expectedErr: nil,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tracers := []trace.Tracer{tp.Tracer("Test-Tracer")}
err := Run(tt.config, tracers, logger)
assert.Equal(t, tt.expectedErr, err)
})
}
}

0 comments on commit 764b0a5

Please sign in to comment.