|
6 | 6 | "path/filepath" |
7 | 7 | "testing" |
8 | 8 |
|
9 | | - "github.com/stretchr/testify/require" |
10 | | - "go.opentelemetry.io/collector/component/componenttest" |
11 | | - |
12 | 9 | "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/entry" |
13 | 10 | "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/operatortest" |
14 | 11 | ) |
@@ -87,65 +84,51 @@ func TestUnmarshal(t *testing.T) { |
87 | 84 | }.Run(t) |
88 | 85 | } |
89 | 86 |
|
90 | | -type invalidConfigCase struct { |
91 | | - name string |
92 | | - cfg *Config |
93 | | - expectErr string |
94 | | -} |
95 | | - |
96 | | -func TestInvalidConfig(t *testing.T) { |
97 | | - cases := []invalidConfigCase{ |
98 | | - { |
99 | | - name: "neither_regex_nor_regexname", |
100 | | - cfg: func() *Config { |
101 | | - cfg := NewConfig() |
102 | | - cfg.Field = entry.NewBodyField() |
103 | | - cfg.RegexName = "" |
104 | | - cfg.Regex = "" |
105 | | - return cfg |
106 | | - }(), |
107 | | - expectErr: "either regex or regex_name must be set", |
108 | | - }, |
109 | | - { |
110 | | - name: "both_regex_and_regexname", |
111 | | - cfg: func() *Config { |
112 | | - cfg := NewConfig() |
113 | | - cfg.Field = entry.NewBodyField() |
114 | | - cfg.RegexName = "ansi_control_sequences" |
115 | | - cfg.Regex = ".*" |
116 | | - return cfg |
117 | | - }(), |
118 | | - expectErr: "either regex or regex_name must be set", |
119 | | - }, |
120 | | - { |
121 | | - name: "unknown_regex_name", |
122 | | - cfg: func() *Config { |
123 | | - cfg := NewConfig() |
124 | | - cfg.Field = entry.NewBodyField() |
125 | | - cfg.RegexName = "i_do_not_exist" |
126 | | - return cfg |
127 | | - }(), |
128 | | - expectErr: "regex_name i_do_not_exist is unknown", |
129 | | - }, |
130 | | - { |
131 | | - name: "invalid_regex", |
132 | | - cfg: func() *Config { |
133 | | - cfg := NewConfig() |
134 | | - cfg.Field = entry.NewBodyField() |
135 | | - cfg.Regex = ")" |
136 | | - return cfg |
137 | | - }(), |
138 | | - expectErr: "error parsing regexp: unexpected ): `)`", |
| 87 | +func TestBuild(t *testing.T) { |
| 88 | + operatortest.ConfigBuilderTests{ |
| 89 | + Tests: []operatortest.ConfigBuilderTest{ |
| 90 | + { |
| 91 | + Name: "neither_regex_nor_regexname", |
| 92 | + Cfg: func() *Config { |
| 93 | + cfg := NewConfig() |
| 94 | + cfg.Field = entry.NewBodyField() |
| 95 | + cfg.RegexName = "" |
| 96 | + cfg.Regex = "" |
| 97 | + return cfg |
| 98 | + }(), |
| 99 | + BuildError: "either regex or regex_name must be set", |
| 100 | + }, |
| 101 | + { |
| 102 | + Name: "both_regex_and_regexname", |
| 103 | + Cfg: func() *Config { |
| 104 | + cfg := NewConfig() |
| 105 | + cfg.Field = entry.NewBodyField() |
| 106 | + cfg.RegexName = "ansi_control_sequences" |
| 107 | + cfg.Regex = ".*" |
| 108 | + return cfg |
| 109 | + }(), |
| 110 | + BuildError: "either regex or regex_name must be set", |
| 111 | + }, |
| 112 | + { |
| 113 | + Name: "unknown_regex_name", |
| 114 | + Cfg: func() *Config { |
| 115 | + cfg := NewConfig() |
| 116 | + cfg.Field = entry.NewBodyField() |
| 117 | + cfg.RegexName = "i_do_not_exist" |
| 118 | + return cfg |
| 119 | + }(), |
| 120 | + BuildError: "regex_name i_do_not_exist is unknown", |
| 121 | + }, |
| 122 | + { |
| 123 | + Name: "invalid_regex", |
| 124 | + Cfg: func() *Config { |
| 125 | + cfg := NewConfig() |
| 126 | + cfg.Field = entry.NewBodyField() |
| 127 | + cfg.Regex = ")" |
| 128 | + return cfg |
| 129 | + }(), |
| 130 | + BuildError: "error parsing regexp: unexpected ): `)`", |
| 131 | + }, |
139 | 132 | }, |
140 | | - } |
141 | | - for _, tc := range cases { |
142 | | - t.Run("InvalidConfig/"+tc.name, func(t *testing.T) { |
143 | | - cfg := tc.cfg |
144 | | - cfg.OutputIDs = []string{"fake"} |
145 | | - cfg.OnError = "send" |
146 | | - set := componenttest.NewNopTelemetrySettings() |
147 | | - _, err := cfg.Build(set) |
148 | | - require.Equal(t, tc.expectErr, err.Error()) |
149 | | - }) |
150 | | - } |
| 133 | + }.Run(t) |
151 | 134 | } |
0 commit comments