(t *testing.T)
| 112 | } |
| 113 | |
| 114 | func Test_ValidateInputCmd_SuccessMultipleFiles(t *testing.T) { |
| 115 | fs := afero.NewMemMapFs() |
| 116 | require.NoError(t, afero.WriteFile(fs, "/input1.yaml", []byte("some: data"), 0o644)) |
| 117 | require.NoError(t, afero.WriteFile(fs, "/input2.yaml", []byte("other: data"), 0o644)) |
| 118 | |
| 119 | // Mock validator: always returns success. |
| 120 | outMock := &output.Output{ |
| 121 | PolicyCheck: []evaluator.Outcome{ |
| 122 | { |
| 123 | Successes: []evaluator.Result{ |
| 124 | {Message: "Pass"}, |
| 125 | }, |
| 126 | }, |
| 127 | }, |
| 128 | } |
| 129 | |
| 130 | cmd, buf := setUpValidateInputCmd(mockValidate(outMock, nil), fs) |
| 131 | cmd.SetArgs([]string{ |
| 132 | "input", |
| 133 | "--file", "/input1.yaml", |
| 134 | "--file", "/input2.yaml", |
| 135 | "--policy", `{"name":"Default","description":"Stuff and things","sources":[{"name":"Default","policy":["/bacon/and/eggs/policy/lib","/bacon/and/eggs/policy/release"],"data":["/bacon/and/eggs/example/data"],"config":{"include":["sbom_cyclonedx"],"exclude":[]}}]}`, |
| 136 | "--output", "json", // Explicitly request JSON output |
| 137 | }) |
| 138 | |
| 139 | utils.SetTestRekorPublicKey(t) |
| 140 | err := cmd.Execute() |
| 141 | assert.NoError(t, err) |
| 142 | |
| 143 | var outJSON map[string]interface{} |
| 144 | err = json.Unmarshal(buf.Bytes(), &outJSON) |
| 145 | assert.NoError(t, err) |
| 146 | assert.True(t, outJSON["success"].(bool)) |
| 147 | |
| 148 | inputFiles, ok := outJSON["filepaths"].([]interface{}) |
| 149 | if !ok { |
| 150 | t.Fatal("expected 'filepaths' key in output") |
| 151 | } |
| 152 | assert.Len(t, inputFiles, 2) |
| 153 | |
| 154 | // Verify sorting by filepath descending as per code |
| 155 | filePaths := []string{} |
| 156 | for _, input := range inputFiles { |
| 157 | f := input.(map[string]interface{})["filepath"].(string) |
| 158 | filePaths = append(filePaths, f) |
| 159 | } |
| 160 | sorted := append([]string{}, filePaths...) |
| 161 | sort.Slice(sorted, func(i, j int) bool { |
| 162 | return sorted[i] > sorted[j] |
| 163 | }) |
| 164 | assert.Equal(t, sorted, filePaths) |
| 165 | } |
| 166 | |
| 167 | func Test_ValidateInputCmd_Failure(t *testing.T) { |
| 168 | fs := afero.NewMemMapFs() |
nothing calls this directly
no test coverage detected