-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathfactory_test.go
69 lines (59 loc) · 1.52 KB
/
factory_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package oauth2clientauthextension
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/extension/extensiontest"
)
func TestCreateDefaultConfig(t *testing.T) {
// prepare and test
expected := &Config{}
// test
cfg := createDefaultConfig()
// verify
assert.Equal(t, expected, cfg)
assert.NoError(t, componenttest.CheckConfigStruct(cfg))
}
func TestCreate(t *testing.T) {
cfg := createDefaultConfig().(*Config)
tests := []struct {
name string
settings *Config
shouldError bool
expectedErr error
}{
{
name: "valid_settings",
settings: &Config{
ClientID: "testclientid",
ClientSecret: "testsecret",
TokenURL: "https://example.com/v1/token",
Scopes: []string{"resource.read"},
},
shouldError: false,
},
}
for _, testcase := range tests {
t.Run(testcase.name, func(t *testing.T) {
cfg.ClientID = testcase.settings.ClientID
cfg.ClientSecret = testcase.settings.ClientSecret
cfg.TokenURL = testcase.settings.TokenURL
cfg.Scopes = testcase.settings.Scopes
ext, err := createExtension(context.Background(), extensiontest.NewNopSettings(), cfg)
if testcase.shouldError {
assert.Error(t, err)
assert.Nil(t, ext)
} else {
assert.NoError(t, err)
assert.NotNil(t, ext)
}
})
}
}
func TestNewFactory(t *testing.T) {
f := NewFactory()
assert.NotNil(t, f)
}