(t *testing.T)
| 144 | } |
| 145 | |
| 146 | func 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{ |
nothing calls this directly
no test coverage detected