| 200 | } |
| 201 | |
| 202 | func TestConfig_Parse_ValidFile(t *testing.T) { |
| 203 | tmpDir := t.TempDir() |
| 204 | confPath := filepath.Join(tmpDir, "commitlint.yaml") |
| 205 | |
| 206 | confContent := `min-version: v0.9.0 |
| 207 | formatter: default |
| 208 | rules: |
| 209 | - header-min-length |
| 210 | - header-max-length |
| 211 | - type-enum |
| 212 | severity: |
| 213 | default: error |
| 214 | settings: |
| 215 | header-min-length: |
| 216 | argument: 10 |
| 217 | header-max-length: |
| 218 | argument: 50 |
| 219 | type-enum: |
| 220 | argument: |
| 221 | - feat |
| 222 | - fix |
| 223 | ` |
| 224 | err := os.WriteFile(confPath, []byte(confContent), 0o644) |
| 225 | if err != nil { |
| 226 | t.Fatalf("failed to write config file: %v", err) |
| 227 | } |
| 228 | |
| 229 | conf, err := config.Parse(confPath) |
| 230 | if err != nil { |
| 231 | t.Fatalf("unexpected error: %v", err) |
| 232 | } |
| 233 | |
| 234 | if conf.Formatter != "default" { |
| 235 | t.Errorf("expected formatter 'default', got %q", conf.Formatter) |
| 236 | } |
| 237 | if len(conf.Rules) != 3 { |
| 238 | t.Errorf("expected 3 rules, got %d", len(conf.Rules)) |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | func TestConfig_Parse_OldVersionKey(t *testing.T) { |
| 243 | tmpDir := t.TempDir() |