|
| 1 | +package runner |
| 2 | + |
| 3 | +import ( |
| 4 | + "regexp" |
| 5 | + "strings" |
| 6 | + "testing" |
| 7 | +) |
| 8 | + |
| 9 | +func TestDryRun_NoChanges(t *testing.T) { |
| 10 | + prefix := regexp.MustCompile(`\s*[#;/]* selfup `) |
| 11 | + |
| 12 | + t.Run("Empty input", func(t *testing.T) { |
| 13 | + input := `` |
| 14 | + result, err := DryRun(strings.NewReader(input), prefix, "") |
| 15 | + if err != nil { |
| 16 | + t.Fatalf("unexpected error: %v", err) |
| 17 | + } |
| 18 | + if result.ChangedCount != 0 { |
| 19 | + t.Errorf("expected 0 changes for empty input, got %d", result.ChangedCount) |
| 20 | + } |
| 21 | + if result.Total != 0 { |
| 22 | + t.Errorf("expected 0 total definitions, got %d", result.Total) |
| 23 | + } |
| 24 | + }) |
| 25 | + |
| 26 | + t.Run("No selfup definitions", func(t *testing.T) { |
| 27 | + input := "line1\nline2" |
| 28 | + result, err := DryRun(strings.NewReader(input), prefix, "") |
| 29 | + if err != nil { |
| 30 | + t.Fatalf("unexpected error: %v", err) |
| 31 | + } |
| 32 | + if result.ChangedCount != 0 { |
| 33 | + t.Errorf("expected 0 changes, got %d", result.ChangedCount) |
| 34 | + } |
| 35 | + if result.Total != 0 { |
| 36 | + t.Errorf("expected 0 total definitions, got %d", result.Total) |
| 37 | + } |
| 38 | + }) |
| 39 | + |
| 40 | + t.Run("Selfup definition exists but no change needed", func(t *testing.T) { |
| 41 | + input := `tool: 1.0 # selfup { "extract": "[0-9.]+", "replacer": ["echo", "1.0"] }` |
| 42 | + result, err := DryRun(strings.NewReader(input), prefix, "") |
| 43 | + if err != nil { |
| 44 | + t.Fatalf("unexpected error: %v", err) |
| 45 | + } |
| 46 | + if result.ChangedCount != 0 { |
| 47 | + t.Errorf("expected 0 changes, got %d", result.ChangedCount) |
| 48 | + } |
| 49 | + if result.Total != 1 { |
| 50 | + t.Errorf("expected 1 total definition, got %d", result.Total) |
| 51 | + } |
| 52 | + }) |
| 53 | +} |
0 commit comments