|
7 | 7 | "strings" |
8 | 8 | "testing" |
9 | 9 |
|
| 10 | + bidotnet "github.com/jfrog/build-info-go/build/utils/dotnet" |
10 | 11 | "github.com/jfrog/build-info-go/build/utils/dotnet/solution" |
11 | 12 | "github.com/jfrog/build-info-go/utils" |
12 | 13 | "github.com/jfrog/jfrog-cli-security/sca/bom/buildinfo/technologies" |
@@ -229,3 +230,59 @@ func TestSkipBuildDepTreeWhenInstallForbidden(t *testing.T) { |
229 | 230 | }) |
230 | 231 | } |
231 | 232 | } |
| 233 | + |
| 234 | +func TestSolutionFilePathParameter(t *testing.T) { |
| 235 | + testCases := []struct { |
| 236 | + name string |
| 237 | + solutionFilePath string |
| 238 | + expectedFileName string |
| 239 | + }{ |
| 240 | + { |
| 241 | + name: "solution file path from params", |
| 242 | + solutionFilePath: "/path/to/my-solution.sln", |
| 243 | + expectedFileName: "my-solution.sln", |
| 244 | + }, |
| 245 | + { |
| 246 | + name: "no solution file path", |
| 247 | + solutionFilePath: "", |
| 248 | + expectedFileName: "", |
| 249 | + }, |
| 250 | + } |
| 251 | + |
| 252 | + for _, test := range testCases { |
| 253 | + t.Run(test.name, func(t *testing.T) { |
| 254 | + params := technologies.BuildInfoBomGeneratorParams{ |
| 255 | + SolutionFilePath: test.solutionFilePath, |
| 256 | + } |
| 257 | + |
| 258 | + // Get the solution file path using the same logic as runDotnetRestore |
| 259 | + var solutionFilePath string |
| 260 | + if params.SolutionFilePath != "" { |
| 261 | + solutionFilePath = params.SolutionFilePath |
| 262 | + } |
| 263 | + var solutionFileName string |
| 264 | + if solutionFilePath != "" { |
| 265 | + solutionFileName = filepath.Base(solutionFilePath) |
| 266 | + } |
| 267 | + |
| 268 | + assert.Equal(t, test.expectedFileName, solutionFileName) |
| 269 | + }) |
| 270 | + } |
| 271 | +} |
| 272 | + |
| 273 | +func TestRunDotnetRestoreWithRealSolutionFile(t *testing.T) { |
| 274 | + testDataDir := filepath.Join("..", "..", "..", "..", "..", "tests", "testdata", "projects", "package-managers") |
| 275 | + multiProjectPath := filepath.Join(testDataDir, "nuget", "multi") |
| 276 | + solutionFilePath := filepath.Join(multiProjectPath, "TestSolution.sln") |
| 277 | + _, err := os.Stat(solutionFilePath) |
| 278 | + assert.NoError(t, err, "Test solution file should exist") |
| 279 | + |
| 280 | + params := technologies.BuildInfoBomGeneratorParams{ |
| 281 | + SolutionFilePath: solutionFilePath, |
| 282 | + } |
| 283 | + toolType := bidotnet.ConvertNameToToolType("dotnet") |
| 284 | + err = runDotnetRestore(multiProjectPath, params, toolType, []string{}) |
| 285 | + if err != nil { |
| 286 | + assert.NotContains(t, err.Error(), "this folder contains more than one project or solution file") |
| 287 | + } |
| 288 | +} |
0 commit comments