MCPcopy Index your code
hub / github.com/cortexproject/cortex / TestConfigValidation

Function TestConfigValidation

pkg/cortex/cortex_test.go:146–252  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

144}
145
146func TestConfigValidation(t *testing.T) {
147 for _, tc := range []struct {
148 name string
149 getTestConfig func() *Config
150 expectedError error
151 }{
152 {
153 name: "should pass validation if the http prefix is empty",
154 getTestConfig: func() *Config {
155 return newDefaultConfig()
156 },
157 expectedError: nil,
158 },
159 {
160 name: "should pass validation if the http prefix starts with /",
161 getTestConfig: func() *Config {
162 configuration := newDefaultConfig()
163 configuration.HTTPPrefix = "/test"
164 return configuration
165 },
166 expectedError: nil,
167 },
168 {
169 name: "should fail validation for invalid prefix",
170 getTestConfig: func() *Config {
171 configuration := newDefaultConfig()
172 configuration.HTTPPrefix = "test"
173 return configuration
174 },
175 expectedError: errInvalidHTTPPrefix,
176 },
177 {
178 name: "should fail validation for invalid resource to monitor",
179 getTestConfig: func() *Config {
180 configuration := newDefaultConfig()
181 configuration.ResourceMonitor = configs.ResourceMonitor{
182 Resources: []string{"wrong"},
183 }
184 return configuration
185 },
186 expectedError: fmt.Errorf("unsupported resource type to monitor: %s", "wrong"),
187 },
188 {
189 name: "should fail validation for invalid resource to monitor - 2",
190 getTestConfig: func() *Config {
191 configuration := newDefaultConfig()
192 configuration.ResourceMonitor = configs.ResourceMonitor{
193 Interval: -1,
194 }
195 return configuration
196 },
197 expectedError: fmt.Errorf("resource monitor interval must be greater than zero"),
198 },
199 {
200 name: "should fail validation for invalid resource to monitor - 3",
201 getTestConfig: func() *Config {
202 configuration := newDefaultConfig()
203 configuration.ResourceMonitor = configs.ResourceMonitor{

Callers

nothing calls this directly

Calls 4

newDefaultConfigFunction · 0.85
RunMethod · 0.65
ValidateMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected