Skip to content

Commit 6bbb65c

Browse files
Merge pull request #56 from snyk/chore/add-output-comments
chore: comment the workflow output return data
2 parents 5c08a66 + d07202e commit 6bbb65c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

internal/commands/ostest/depgraph_flow.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ func testAllDepGraphs(
103103
return allLegacyFindings, allOutputData, nil
104104
}
105105

106+
// createTestSubject creates a test subject from a depGraph and display target file.
106107
func createTestSubject(
107108
depGraph *testapi.IoSnykApiV1testdepgraphRequestDepGraph,
108109
displayTargetFile string,
109110
) (testapi.TestSubjectCreate, error) {
110-
// Create depgraph subject
111111
depGraphSubject := testapi.DepGraphSubjectCreate{
112112
Type: testapi.DepGraphSubjectCreateTypeDepGraph,
113113
DepGraph: *depGraph,
@@ -117,7 +117,6 @@ func createTestSubject(
117117
},
118118
}
119119

120-
// Create test subject with depgraph
121120
var subject testapi.TestSubjectCreate
122121
err := subject.FromDepGraphSubjectCreate(depGraphSubject)
123122
if err != nil {
@@ -140,6 +139,10 @@ func getProjectName(
140139
return projectName
141140
}
142141

142+
// handleOutput processes both legacy JSON and human-readable findings into their respective outputs.
143+
// Human-readable output is processed by the local template renderer.
144+
// JSON file output is written to file here, while JSON stdout is added to the output workflow.
145+
// Summary data is added to the output workflow for exit code calculation.
143146
func handleOutput(
144147
ictx workflow.InvocationContext,
145148
allLegacyFindings []definitions.LegacyVulnerabilityResponse,
@@ -198,6 +201,7 @@ func handleOutput(
198201
return finalOutput, nil
199202
}
200203

204+
// prepareJSONOutput prepares legacy JSON output from findings.
201205
func prepareJSONOutput(
202206
allLegacyFindings []definitions.LegacyVulnerabilityResponse,
203207
errFactory *errors.ErrorFactory,

internal/commands/ostest/test_execution.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const LogFieldCount = "count"
3232
var ErrNoSummaryData = std_errors.New("no summary data to create")
3333

3434
// RunTest executes the common test flow with the provided test subject.
35+
// Returns legacy JSON and/or human-readable workflow data, depending on parameters.
3536
func RunTest(
3637
ctx context.Context,
3738
ictx workflow.InvocationContext,
@@ -155,7 +156,10 @@ func executeTest(
155156
return finalResult, findingsData, nil
156157
}
157158

158-
// prepareOutput prepares the workflow data for output.
159+
// prepareOutput prepares raw test result findings into data for the output workflow.
160+
// If JSON is requested (either to file or stdout), it generates legacy JSON findings.
161+
// If JSON-stdout is not requested, then human-readable findings are added to the output workflow.
162+
// Human-readable stdout with JSON file output is a valid combination and returns both human-readable and legacy JSON types.
159163
func prepareOutput(
160164
ictx workflow.InvocationContext,
161165
findingsData []testapi.FindingData,

0 commit comments

Comments
 (0)