| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package stdoutlog // import "go.opentelemetry.io/otel/exporters/stdout/stdoutlog" |
| 5 |
|
| 6 |
import ( |
| 7 |
"os" |
| 8 |
"testing" |
| 9 |
|
| 10 |
"github.com/stretchr/testify/assert" |
| 11 |
) |
| 12 |
|
| 13 |
func TestNewConfig(t *testing.T) { |
| 14 |
testCases := []struct { |
| 15 |
name string |
| 16 |
options []Option |
| 17 |
expected config |
| 18 |
}{ |
| 19 |
{ |
| 20 |
name: "default", |
| 21 |
expected: config{ |
| 22 |
Writer: os.Stdout, |
| 23 |
PrettyPrint: false, |
| 24 |
Timestamps: true, |
| 25 |
}, |
| 26 |
}, |
| 27 |
{ |
| 28 |
name: "WithWriter", |
| 29 |
options: []Option{WithWriter(os.Stderr)}, |
| 30 |
expected: config{ |
| 31 |
Writer: os.Stderr, |
| 32 |
PrettyPrint: false, |
| 33 |
Timestamps: true, |
| 34 |
}, |
| 35 |
}, |
| 36 |
{ |
| 37 |
name: "WithPrettyPrint", |
| 38 |
options: []Option{WithPrettyPrint()}, |
| 39 |
expected: config{ |
| 40 |
Writer: os.Stdout, |
| 41 |
PrettyPrint: true, |
| 42 |
Timestamps: true, |
| 43 |
}, |
| 44 |
}, |
| 45 |
{ |
| 46 |
name: "WithoutTimestamps", |
| 47 |
options: []Option{WithoutTimestamps()}, |
| 48 |
expected: config{ |
| 49 |
Writer: os.Stdout, |
| 50 |
PrettyPrint: false, |
| 51 |
Timestamps: false, |
| 52 |
}, |
| 53 |
}, |
| 54 |
} |
| 55 |
|
| 56 |
for _, tc := range testCases { |
| 57 |
t.Run(tc.name, func(t *testing.T) { |
| 58 |
cfg := newConfig(tc.options) |
| 59 |
assert.Equal(t, tc.expected, cfg) |
| 60 |
}) |
| 61 |
} |
| 62 |
} |