@@ -31,6 +31,8 @@ const expectedInitScriptWithRepos = `initscript {
3131 }
3232}
3333
34+ apply plugin: com.jfrog.GradleDepTreeSettings
35+
3436allprojects {
3537 repositories {
3638 maven {
@@ -44,6 +46,30 @@ allprojects {
4446 apply plugin: com.jfrog.GradleDepTree
4547}`
4648
49+ const expectedInitScriptWithCuration = `initscript {
50+ repositories {
51+ mavenCentral()
52+ }
53+ dependencies {
54+ classpath files('%s')
55+ }
56+ }
57+
58+ apply plugin: com.jfrog.GradleDepTreeSettings
59+
60+ allprojects {
61+ repositories {
62+ maven {
63+ url "https://myartifactory.com/artifactory/api/curation/audit/deps-repo"
64+ credentials {
65+ username = 'admin'
66+ password = '%s'
67+ }
68+ }
69+ }
70+ apply plugin: com.jfrog.GradleDepTree
71+ }`
72+
4773func TestGradleTreesWithoutConfig (t * testing.T ) {
4874 // Create and change directory to test workspace
4975 tempDirPath , cleanUp := technologies .CreateTestWorkspace (t , filepath .Join ("projects" , "package-managers" , "gradle" , "gradle" ))
@@ -255,30 +281,51 @@ func TestConstructReleasesRemoteRepo(t *testing.T) {
255281 }
256282}
257283
258- func TestGradleCurationAuditMode (t * testing.T ) {
259- // Test that curation audit mode flag is added when IsCurationCmd is true
260- params := & DepTreeParams {
261- IsCurationCmd : true ,
262- }
263-
284+ func TestCreateDepTreeScriptWithCuration (t * testing.T ) {
264285 manager := & gradleDepTreeManager {
265- DepTreeManager : NewDepTreeManager (params ),
266- isCurationCmd : params .IsCurationCmd ,
286+ DepTreeManager : DepTreeManager {
287+ depsRepo : "deps-repo" ,
288+ server : & config.ServerDetails {
289+ Url : "https://myartifactory.com/" ,
290+ ArtifactoryUrl : "https://myartifactory.com/artifactory" ,
291+ AccessToken : dummyToken ,
292+ },
293+ },
294+ isCurationCmd : true ,
267295 }
296+ assert .True (t , manager .isCurationCmd )
268297
269- // Verify that the manager has the curation flag set
270- assert .True (t , manager .isCurationCmd , "isCurationCmd should be true for curation commands" )
298+ tmpDir , err := manager .createDepTreeScriptAndGetDir ()
299+ assert .NoError (t , err )
300+ defer func () {
301+ assert .NoError (t , os .Remove (filepath .Join (tmpDir , gradleDepTreeInitFile )))
302+ }()
271303
272- // Test with non-curation command
273- paramsNonCuration := & DepTreeParams {
274- IsCurationCmd : false ,
275- }
304+ content , err := os .ReadFile (filepath .Join (tmpDir , gradleDepTreeInitFile ))
305+ assert .NoError (t , err )
306+ gradleDepTreeJarPath := ioutils .DoubleWinPathSeparator (filepath .Join (tmpDir , gradleDepTreeJarFile ))
307+
308+ assert .Equal (t , fmt .Sprintf (expectedInitScriptWithCuration , gradleDepTreeJarPath , dummyToken ), string (content ))
309+ assert .Contains (t , string (content ), "api/curation/audit/deps-repo" )
310+ }
276311
277- managerNonCuration := & gradleDepTreeManager {
278- DepTreeManager : NewDepTreeManager (paramsNonCuration ),
279- isCurationCmd : paramsNonCuration .IsCurationCmd ,
312+ func TestCreateDepTreeScriptWithCurationEmptyRepo (t * testing.T ) {
313+ manager := & gradleDepTreeManager {
314+ DepTreeManager : DepTreeManager {},
315+ isCurationCmd : true ,
280316 }
317+ assert .True (t , manager .isCurationCmd )
318+
319+ tmpDir , err := manager .createDepTreeScriptAndGetDir ()
320+ assert .NoError (t , err )
321+ defer func () {
322+ assert .NoError (t , os .Remove (filepath .Join (tmpDir , gradleDepTreeInitFile )))
323+ }()
324+
325+ content , err := os .ReadFile (filepath .Join (tmpDir , gradleDepTreeInitFile ))
326+ assert .NoError (t , err )
327+ gradleDepTreeJarPath := ioutils .DoubleWinPathSeparator (filepath .Join (tmpDir , gradleDepTreeJarFile ))
281328
282- // Verify that the manager does not have the curation flag set
283- assert .False (t , managerNonCuration . isCurationCmd , "isCurationCmd should be false for non- curation commands " )
329+ assert . Equal ( t , fmt . Sprintf ( gradleDepTreeInitScript , "" , gradleDepTreeJarPath , "" ), string ( content ))
330+ assert .NotContains (t , string ( content ) , "api/ curation/audit " )
284331}
0 commit comments