Skip to content

Commit c8b65a3

Browse files
committed
chore: Expanding lll coverage to report
1 parent ccceca5 commit c8b65a3

4 files changed

Lines changed: 52 additions & 16 deletions

File tree

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ linters:
121121
# trying to get this merged in.
122122
- linters:
123123
- lll
124-
path-except: '^(internal/awshelper/|internal/cas/|internal/cli/commands/(backend/(delete|migrate)|catalog/tui/command|dag/graph|exec|find|help|list|scaffold|stack)/|internal/cloner/|internal/configbridge/|internal/engine/|internal/errorconfig/|internal/errors/|internal/experiment/|internal/gcphelper/|internal/git/|internal/os/exec/|internal/prepare/|internal/queue/|internal/retry/|internal/runner/(common|graph|run/creds|runall|runcfg)/|internal/stacks/(generate|output)/|internal/telemetry/|internal/tf/cache/(controllers|middleware)/|internal/tflint/|internal/tips/|internal/vfs/|internal/worktrees/|pkg/log/(format/(options|placeholders)|writer)/|pkg/options/)'
124+
path-except: '^(internal/awshelper/|internal/cas/|internal/cli/commands/(backend/(delete|migrate)|catalog/tui/command|dag/graph|exec|find|help|list|scaffold|stack)/|internal/cloner/|internal/configbridge/|internal/engine/|internal/errorconfig/|internal/errors/|internal/experiment/|internal/gcphelper/|internal/git/|internal/os/exec/|internal/prepare/|internal/queue/|internal/report/|internal/retry/|internal/runner/(common|graph|run/creds|runall|runcfg)/|internal/stacks/(generate|output)/|internal/telemetry/|internal/tf/cache/(controllers|middleware)/|internal/tflint/|internal/tips/|internal/vfs/|internal/worktrees/|pkg/log/(format/(options|placeholders)|writer)/|pkg/options/)'
125125
paths:
126126
- docs
127127
- _ci

internal/report/report_test.go

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,8 @@ func TestWriteJSONWithDiscoveryWorkingDir(t *testing.T) {
15131513

15141514
// The name should be relative to the worktree dir, not the original repo dir
15151515
// Without the fix, this would be the full absolute path since unitPath doesn't start with originalRepoDir
1516-
assert.Equal(t, "module/unit", runs[0].Name, "Run name should be relative to DiscoveryWorkingDir, not report.workingDir")
1516+
assert.Equal(t, "module/unit", runs[0].Name,
1517+
"Run name should be relative to DiscoveryWorkingDir, not report.workingDir")
15171518
}
15181519

15191520
// TestWriteCSVWithDiscoveryWorkingDir verifies that CSV output also uses DiscoveryWorkingDir.
@@ -1554,7 +1555,8 @@ func TestWriteCSVWithDiscoveryWorkingDir(t *testing.T) {
15541555
require.Len(t, records, 2) // header + 1 data row
15551556

15561557
// The name (first column) should be relative to worktree dir
1557-
assert.Equal(t, "module/unit", records[1][0], "Run name should be relative to DiscoveryWorkingDir, not report.workingDir")
1558+
assert.Equal(t, "module/unit", records[1][0],
1559+
"Run name should be relative to DiscoveryWorkingDir, not report.workingDir")
15581560
}
15591561

15601562
// TestParseJSONRuns verifies that JSON report data can be parsed from bytes.
@@ -1649,7 +1651,8 @@ func TestParseJSONRunsFromFile(t *testing.T) {
16491651
t.Parallel()
16501652

16511653
reportFile := filepath.Join(tmp, "valid-report.json")
1652-
content := `[{"Name": "test-unit", "Started": "2024-01-01T10:00:00Z", "Ended": "2024-01-01T10:01:00Z", "Result": "succeeded"}]`
1654+
content := `[{"Name": "test-unit", "Started": "2024-01-01T10:00:00Z",` +
1655+
` "Ended": "2024-01-01T10:01:00Z", "Result": "succeeded"}]`
16531656

16541657
err := os.WriteFile(reportFile, []byte(content), 0644)
16551658
require.NoError(t, err)
@@ -1773,9 +1776,15 @@ func TestParseCSVRuns(t *testing.T) {
17731776
expected: report.CSVRuns{},
17741777
},
17751778
{
1776-
name: "single run",
1777-
input: "Name,Started,Ended,Result,Reason,Cause,Ref,Cmd,Args\nmodule/unit,2024-01-01T10:00:00Z,2024-01-01T10:01:00Z,succeeded,,,,,\n",
1778-
expected: report.CSVRuns{{Name: "module/unit", Started: "2024-01-01T10:00:00Z", Ended: "2024-01-01T10:01:00Z", Result: "succeeded"}},
1779+
name: "single run",
1780+
input: "Name,Started,Ended,Result,Reason,Cause,Ref,Cmd,Args\n" +
1781+
"module/unit,2024-01-01T10:00:00Z,2024-01-01T10:01:00Z,succeeded,,,,,\n",
1782+
expected: report.CSVRuns{{
1783+
Name: "module/unit",
1784+
Started: "2024-01-01T10:00:00Z",
1785+
Ended: "2024-01-01T10:01:00Z",
1786+
Result: "succeeded",
1787+
}},
17791788
},
17801789
{
17811790
name: "multiple runs with all fields",
@@ -1784,8 +1793,25 @@ unit-a,2024-01-01T10:00:00Z,2024-01-01T10:01:00Z,succeeded,,,HEAD~1,plan,-out=pl
17841793
unit-b,2024-01-01T10:01:00Z,2024-01-01T10:02:00Z,failed,run error,some error,main,apply,
17851794
`,
17861795
expected: report.CSVRuns{
1787-
{Name: "unit-a", Started: "2024-01-01T10:00:00Z", Ended: "2024-01-01T10:01:00Z", Result: "succeeded", Ref: "HEAD~1", Cmd: "plan", Args: "-out=plan.tfplan|-var=foo=bar"},
1788-
{Name: "unit-b", Started: "2024-01-01T10:01:00Z", Ended: "2024-01-01T10:02:00Z", Result: "failed", Reason: "run error", Cause: "some error", Ref: "main", Cmd: "apply"},
1796+
{
1797+
Name: "unit-a",
1798+
Started: "2024-01-01T10:00:00Z",
1799+
Ended: "2024-01-01T10:01:00Z",
1800+
Result: "succeeded",
1801+
Ref: "HEAD~1",
1802+
Cmd: "plan",
1803+
Args: "-out=plan.tfplan|-var=foo=bar",
1804+
},
1805+
{
1806+
Name: "unit-b",
1807+
Started: "2024-01-01T10:01:00Z",
1808+
Ended: "2024-01-01T10:02:00Z",
1809+
Result: "failed",
1810+
Reason: "run error",
1811+
Cause: "some error",
1812+
Ref: "main",
1813+
Cmd: "apply",
1814+
},
17891815
},
17901816
},
17911817
{
@@ -1832,7 +1858,8 @@ func TestParseCSVRunsFromFile(t *testing.T) {
18321858
t.Parallel()
18331859

18341860
reportFile := filepath.Join(tmp, "valid-report.csv")
1835-
content := "Name,Started,Ended,Result,Reason,Cause,Ref,Cmd,Args\ntest-unit,2024-01-01T10:00:00Z,2024-01-01T10:01:00Z,succeeded,,,,,\n"
1861+
content := "Name,Started,Ended,Result,Reason,Cause,Ref,Cmd,Args\n" +
1862+
"test-unit,2024-01-01T10:00:00Z,2024-01-01T10:01:00Z,succeeded,,,,,\n"
18361863

18371864
err := os.WriteFile(reportFile, []byte(content), 0644)
18381865
require.NoError(t, err)
@@ -1974,10 +2001,13 @@ func TestParseJSONRunsFromFileValidation(t *testing.T) {
19742001
},
19752002
{
19762003
name: "valid multiple runs",
1977-
input: `[
1978-
{"Name": "unit-a", "Started": "2024-01-01T10:00:00Z", "Ended": "2024-01-01T10:01:00Z", "Result": "succeeded"},
1979-
{"Name": "unit-b", "Started": "2024-01-01T10:01:00Z", "Ended": "2024-01-01T10:02:00Z", "Result": "failed", "Reason": "run error"}
1980-
]`,
2004+
input: "[" +
2005+
`{"Name": "unit-a", "Started": "2024-01-01T10:00:00Z",` +
2006+
` "Ended": "2024-01-01T10:01:00Z", "Result": "succeeded"},` +
2007+
`{"Name": "unit-b", "Started": "2024-01-01T10:01:00Z",` +
2008+
` "Ended": "2024-01-01T10:02:00Z", "Result": "failed",` +
2009+
` "Reason": "run error"}` +
2010+
"]",
19812011
expectError: false,
19822012
},
19832013
{

internal/report/summary.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,10 @@ func (s *Summary) writeUnitLevelSummary(w io.Writer, colorizer *Colorizer) error
336336
}
337337

338338
// writeUnitDuration writes unit duration with cleaner formatting
339-
func (s *Summary) writeUnitDuration(w io.Writer, run *Run, colorizer *Colorizer, unitColorizer func(string) string) error {
339+
func (s *Summary) writeUnitDuration(
340+
w io.Writer, run *Run, colorizer *Colorizer,
341+
unitColorizer func(string) string,
342+
) error {
340343
duration := run.Ended.Sub(run.Started)
341344

342345
name := run.Path

internal/report/writer.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type JSONRun struct {
3030
// Ended is the time when the run ended.
3131
Ended time.Time `json:"Ended" jsonschema:"required"`
3232
// Reason is the reason for the run result, if any.
33+
//nolint:lll
3334
Reason *string `json:"Reason,omitempty" jsonschema:"enum=retry succeeded,enum=error ignored,enum=run error,enum=exclude block,enum=ancestor error"`
3435
// Cause is the cause of the run result, if any.
3536
Cause *string `json:"Cause,omitempty"`
@@ -134,7 +135,9 @@ func ParseCSVRuns(data []byte) (CSVRuns, error) {
134135

135136
for i, record := range records[1:] {
136137
if len(record) < csvFieldCount {
137-
return nil, fmt.Errorf("invalid CSV record at row %d: expected %d fields, got %d", i+csvRowOffset, csvFieldCount, len(record))
138+
return nil, fmt.Errorf(
139+
"invalid CSV record at row %d: expected %d fields, got %d",
140+
i+csvRowOffset, csvFieldCount, len(record))
138141
}
139142

140143
runs = append(runs, CSVRun{

0 commit comments

Comments
 (0)