-
Notifications
You must be signed in to change notification settings - Fork 294
Expand file tree
/
Copy pathconan_test.go
More file actions
1164 lines (958 loc) · 40.8 KB
/
conan_test.go
File metadata and controls
1164 lines (958 loc) · 40.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package main
import (
"crypto/sha256"
"encoding/hex"
"os"
"os/exec"
"path/filepath"
"strconv"
"testing"
buildinfo "github.com/jfrog/build-info-go/entities"
biutils "github.com/jfrog/build-info-go/utils"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
coreBuild "github.com/jfrog/jfrog-cli-core/v2/common/build"
coretests "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
"github.com/jfrog/jfrog-cli/inttestutils"
"github.com/jfrog/jfrog-cli/utils/tests"
clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestConanInstall tests 'jf conan install' command with build info collection.
// This is Scenario 1: Install + Build Publish (dependencies only)
func TestConanInstall(t *testing.T) {
initConanTest(t)
buildNumber := "1"
// Prepare project
projectPath := createConanProject(t, "conan-install-test")
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
// Configure Conan remote
configureConanRemote(t)
defer cleanupConanRemote()
// Run conan install with build info
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
args := []string{
"conan", "install", ".",
"--build=missing",
"-r", tests.ConanVirtualRepo,
"--build-name=" + tests.ConanBuildName,
"--build-number=" + buildNumber,
}
require.NoError(t, jfrogCli.Exec(args...))
// Publish build info
require.NoError(t, artifactoryCli.Exec("bp", tests.ConanBuildName, buildNumber))
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.ConanBuildName, artHttpDetails)
// Validate build info
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.ConanBuildName, buildNumber)
require.NoError(t, err)
require.True(t, found, "build info was expected to be found")
buildInfoModules := publishedBuildInfo.BuildInfo.Modules
require.Len(t, buildInfoModules, 1, "Expected 1 module")
assert.Equal(t, buildinfo.Conan, buildInfoModules[0].Type, "Module type should be conan")
// Should have dependencies (at least zlib)
assert.GreaterOrEqual(t, len(buildInfoModules[0].Dependencies), 1, "Expected at least 1 dependency (zlib)")
// No artifacts should be present (only install was run, no upload)
assert.Len(t, buildInfoModules[0].Artifacts, 0, "No artifacts expected for install-only scenario")
}
// TestConanInstallCreate tests 'jf conan install' + 'jf conan create' command flow.
// This is Scenario 2: Install + Create + Build Publish (dependencies only)
func TestConanInstallCreate(t *testing.T) {
initConanTest(t)
buildNumber := "1"
// Prepare project
projectPath := createConanProject(t, "conan-install-create-test")
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
// Configure Conan remote
configureConanRemote(t)
defer cleanupConanRemote()
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
// Run conan install
installArgs := []string{
"conan", "install", ".",
"--build=missing",
"-r", tests.ConanVirtualRepo,
"--build-name=" + tests.ConanBuildName,
"--build-number=" + buildNumber,
}
assert.NoError(t, jfrogCli.Exec(installArgs...))
// Run conan create
createArgs := []string{
"conan", "create", ".",
"--build=missing",
"--build-name=" + tests.ConanBuildName,
"--build-number=" + buildNumber,
}
assert.NoError(t, jfrogCli.Exec(createArgs...))
// Publish build info
assert.NoError(t, artifactoryCli.Exec("bp", tests.ConanBuildName, buildNumber))
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.ConanBuildName, artHttpDetails)
// Validate build info
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.ConanBuildName, buildNumber)
require.NoError(t, err)
require.True(t, found, "build info was expected to be found")
buildInfoModules := publishedBuildInfo.BuildInfo.Modules
assert.Len(t, buildInfoModules, 1, "Expected 1 module")
// Should have dependencies
assert.GreaterOrEqual(t, len(buildInfoModules[0].Dependencies), 1, "Expected at least 1 dependency")
// No artifacts without upload
assert.Len(t, buildInfoModules[0].Artifacts, 0, "No artifacts expected without upload")
}
// TestConanFullFlow tests the complete flow: install + create + upload + build publish.
// This is Scenario 3: Install + Create + Upload + Build Publish (deps + artifacts)
func TestConanFullFlow(t *testing.T) {
initConanTest(t)
buildNumber := "1"
// Prepare project
projectPath := createConanProject(t, "conan-full-flow-test")
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
// Configure Conan remote
configureConanRemote(t)
defer cleanupConanRemote()
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
// Run conan install
installArgs := []string{
"conan", "install", ".",
"--build=missing",
"-r", tests.ConanVirtualRepo,
"--build-name=" + tests.ConanBuildName,
"--build-number=" + buildNumber,
}
assert.NoError(t, jfrogCli.Exec(installArgs...))
// Run conan create
createArgs := []string{
"conan", "create", ".",
"--build=missing",
"--build-name=" + tests.ConanBuildName,
"--build-number=" + buildNumber,
}
assert.NoError(t, jfrogCli.Exec(createArgs...))
// Run conan upload
uploadArgs := []string{
"conan", "upload", "cli-test-package/*",
"-r", tests.ConanLocalRepo,
"--confirm",
"--build-name=" + tests.ConanBuildName,
"--build-number=" + buildNumber,
}
assert.NoError(t, jfrogCli.Exec(uploadArgs...))
// Publish build info
assert.NoError(t, artifactoryCli.Exec("bp", tests.ConanBuildName, buildNumber))
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.ConanBuildName, artHttpDetails)
// Validate build info
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.ConanBuildName, buildNumber)
require.NoError(t, err)
require.True(t, found, "build info was expected to be found")
buildInfoModules := publishedBuildInfo.BuildInfo.Modules
assert.Len(t, buildInfoModules, 1, "Expected 1 module")
// Should have both dependencies and artifacts
assert.GreaterOrEqual(t, len(buildInfoModules[0].Dependencies), 1, "Expected at least 1 dependency")
assert.GreaterOrEqual(t, len(buildInfoModules[0].Artifacts), 1, "Expected at least 1 artifact after upload")
// Validate artifacts have checksums
for _, artifact := range buildInfoModules[0].Artifacts {
assert.NotEmpty(t, artifact.Sha1, "Artifact %s should have SHA1", artifact.Name)
}
}
// TestConanCreateUpload tests create + upload flow without install.
// This is Scenario 4: Create + Upload + Build Publish (deps + artifacts)
func TestConanCreateUpload(t *testing.T) {
initConanTest(t)
buildNumber := "1"
// Prepare project
projectPath := createConanProject(t, "conan-create-upload-test")
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
// Configure Conan remote
configureConanRemote(t)
defer cleanupConanRemote()
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
// Run conan create (this also installs dependencies)
createArgs := []string{
"conan", "create", ".",
"--build=missing",
"--build-name=" + tests.ConanBuildName,
"--build-number=" + buildNumber,
}
assert.NoError(t, jfrogCli.Exec(createArgs...))
// Run conan upload
uploadArgs := []string{
"conan", "upload", "cli-test-package/*",
"-r", tests.ConanLocalRepo,
"--confirm",
"--build-name=" + tests.ConanBuildName,
"--build-number=" + buildNumber,
}
assert.NoError(t, jfrogCli.Exec(uploadArgs...))
// Publish build info
assert.NoError(t, artifactoryCli.Exec("bp", tests.ConanBuildName, buildNumber))
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.ConanBuildName, artHttpDetails)
// Validate build info
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.ConanBuildName, buildNumber)
require.NoError(t, err)
require.True(t, found, "build info was expected to be found")
buildInfoModules := publishedBuildInfo.BuildInfo.Modules
assert.Len(t, buildInfoModules, 1, "Expected 1 module")
// Should have both dependencies and artifacts
assert.GreaterOrEqual(t, len(buildInfoModules[0].Dependencies), 1, "Expected at least 1 dependency")
assert.GreaterOrEqual(t, len(buildInfoModules[0].Artifacts), 1, "Expected at least 1 artifact after upload")
}
// TestConanAutoLogin tests that auto-login works for Artifactory remotes.
func TestConanAutoLogin(t *testing.T) {
initConanTest(t)
// Prepare project
projectPath := createConanProject(t, "conan-auto-login-test")
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
// Configure Conan remote (without manual login)
configureConanRemote(t)
defer cleanupConanRemote()
// Run conan install - auto-login should happen
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
args := []string{
"conan", "install", ".",
"--build=missing",
"-r", tests.ConanVirtualRepo,
}
// If auto-login works, this should not fail with authentication error
err = jfrogCli.Exec(args...)
assert.NoError(t, err, "Conan install with auto-login should succeed")
}
// TestConanBuildInfoModuleFromProject tests that module ID is derived from the conanfile.py project info.
func TestConanBuildInfoModuleFromProject(t *testing.T) {
initConanTest(t)
buildNumber := "1"
// Prepare project
projectPath := createConanProject(t, "conan-module-test")
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
// Configure Conan remote
configureConanRemote(t)
defer cleanupConanRemote()
// Run conan install
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
args := []string{
"conan", "install", ".",
"--build=missing",
"-r", tests.ConanVirtualRepo,
"--build-name=" + tests.ConanBuildName,
"--build-number=" + buildNumber,
}
assert.NoError(t, jfrogCli.Exec(args...))
// Publish build info
assert.NoError(t, artifactoryCli.Exec("bp", tests.ConanBuildName, buildNumber))
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.ConanBuildName, artHttpDetails)
// Validate build info module ID comes from conanfile.py (name:version)
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.ConanBuildName, buildNumber)
require.NoError(t, err)
require.True(t, found, "build info was expected to be found")
buildInfoModules := publishedBuildInfo.BuildInfo.Modules
assert.Len(t, buildInfoModules, 1, "Expected 1 module")
// Module ID should be derived from conanfile.py: "cli-test-package:1.0.0"
assert.Equal(t, "cli-test-package:1.0.0", buildInfoModules[0].Id, "Module ID should be derived from conanfile.py")
}
// TestConanMultipleBuilds tests that multiple Conan builds don't interfere with each other.
func TestConanMultipleBuilds(t *testing.T) {
initConanTest(t)
// Prepare project
projectPath := createConanProject(t, "conan-multi-build-test")
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
// Configure Conan remote
configureConanRemote(t)
defer cleanupConanRemote()
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
// Run multiple builds
for i := 1; i <= 3; i++ {
buildNumber := strconv.Itoa(i)
args := []string{
"conan", "install", ".",
"--build=missing",
"-r", tests.ConanVirtualRepo,
"--build-name=" + tests.ConanBuildName,
"--build-number=" + buildNumber,
}
assert.NoError(t, jfrogCli.Exec(args...))
// Publish each build
assert.NoError(t, artifactoryCli.Exec("bp", tests.ConanBuildName, buildNumber))
}
// Cleanup all builds
defer func() {
for i := 1; i <= 3; i++ {
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.ConanBuildName, artHttpDetails)
}
}()
// Verify all builds exist
for i := 1; i <= 3; i++ {
buildNumber := strconv.Itoa(i)
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.ConanBuildName, buildNumber)
require.NoError(t, err)
require.True(t, found, "build info %s/%s was expected to be found", tests.ConanBuildName, buildNumber)
assert.Len(t, publishedBuildInfo.BuildInfo.Modules, 1)
}
}
// TestConanDependencyChecksums tests that dependencies have proper checksums.
func TestConanDependencyChecksums(t *testing.T) {
initConanTest(t)
buildNumber := "1"
// Prepare project
projectPath := createConanProject(t, "conan-checksum-test")
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
// Configure Conan remote
configureConanRemote(t)
defer cleanupConanRemote()
// Run conan install
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
args := []string{
"conan", "install", ".",
"--build=missing",
"-r", tests.ConanVirtualRepo,
"--build-name=" + tests.ConanBuildName,
"--build-number=" + buildNumber,
}
assert.NoError(t, jfrogCli.Exec(args...))
// Publish build info
assert.NoError(t, artifactoryCli.Exec("bp", tests.ConanBuildName, buildNumber))
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.ConanBuildName, artHttpDetails)
// Validate checksums
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.ConanBuildName, buildNumber)
require.NoError(t, err)
require.True(t, found, "build info was expected to be found")
buildInfoModules := publishedBuildInfo.BuildInfo.Modules
require.Len(t, buildInfoModules, 1)
checksumCount := 0
for _, dep := range buildInfoModules[0].Dependencies {
if dep.Sha1 != "" || dep.Sha256 != "" {
checksumCount++
t.Logf("Dependency %s has checksums: SHA1=%s, SHA256=%s", dep.Id, dep.Sha1, dep.Sha256)
}
}
assert.Greater(t, checksumCount, 0, "At least some dependencies should have checksums")
}
// Helper functions
func initConanTest(t *testing.T) {
if !*tests.TestConan {
t.Skip("Skipping Conan test. To run Conan test add the '-test.conan=true' option.")
}
// Ensure Conan is installed
_, err := exec.LookPath("conan")
require.NoError(t, err, "Conan must be installed to run Conan tests")
// Ensure Conan default profile exists (required for conan install/create)
_ = exec.Command("conan", "profile", "detect").Run()
// Initialize CLI if not already done
if artifactoryCli == nil {
initArtifactoryCli()
}
// Set up home directory configuration
createJfrogHomeConfig(t, true)
}
func createConanProject(t *testing.T, outputFolder string) string {
projectSrc := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "conan", "conanproject")
tmpDir, cleanupCallback := coretests.CreateTempDirWithCallbackAndAssert(t)
projectPath := filepath.Join(tmpDir, outputFolder)
require.NoError(t, biutils.CopyDir(projectSrc, projectPath, true, nil))
// Register cleanup to run at the end of the test
t.Cleanup(cleanupCallback)
return projectPath
}
func createConanProjectNoName(t *testing.T, outputFolder string) string {
projectSrc := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "conan", "conanproject-noname")
tmpDir, cleanupCallback := coretests.CreateTempDirWithCallbackAndAssert(t)
projectPath := filepath.Join(tmpDir, outputFolder)
require.NoError(t, biutils.CopyDir(projectSrc, projectPath, true, nil))
t.Cleanup(cleanupCallback)
return projectPath
}
func createConanProjectSubdir(t *testing.T, outputFolder string) string {
projectSrc := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "conan", "conanproject-subdir")
tmpDir, cleanupCallback := coretests.CreateTempDirWithCallbackAndAssert(t)
projectPath := filepath.Join(tmpDir, outputFolder)
require.NoError(t, biutils.CopyDir(projectSrc, projectPath, true, nil))
t.Cleanup(cleanupCallback)
return projectPath
}
func configureConanRemote(t *testing.T) {
// Remove existing remote if any
_ = exec.Command("conan", "remote", "remove", tests.ConanVirtualRepo).Run()
_ = exec.Command("conan", "remote", "remove", tests.ConanLocalRepo).Run()
// Add Conan remotes pointing to Artifactory
virtualUrl := serverDetails.ArtifactoryUrl + "api/conan/" + tests.ConanVirtualRepo
localUrl := serverDetails.ArtifactoryUrl + "api/conan/" + tests.ConanLocalRepo
addVirtualCmd := exec.Command("conan", "remote", "add", tests.ConanVirtualRepo, virtualUrl)
require.NoError(t, addVirtualCmd.Run(), "Failed to add Conan virtual remote")
addLocalCmd := exec.Command("conan", "remote", "add", tests.ConanLocalRepo, localUrl)
require.NoError(t, addLocalCmd.Run(), "Failed to add Conan local remote")
}
func cleanupConanRemote() {
_ = exec.Command("conan", "remote", "remove", tests.ConanVirtualRepo).Run()
_ = exec.Command("conan", "remote", "remove", tests.ConanLocalRepo).Run()
}
// TestConanInstallRequiresNoRecipe tests 'jf conan install --requires' without any conanfile.
func TestConanInstallRequiresNoRecipe(t *testing.T) {
initConanTest(t)
buildNumber := "1"
// Create empty project dir (no conanfile)
tmpDir, cleanupCallback := coretests.CreateTempDirWithCallbackAndAssert(t)
t.Cleanup(cleanupCallback)
projectPath := filepath.Join(tmpDir, "no-recipe-test")
require.NoError(t, os.MkdirAll(projectPath, 0755))
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
configureConanRemote(t)
defer cleanupConanRemote()
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
args := []string{
"conan", "install",
"--requires", "zlib/1.3.1",
"--build", "missing",
"-r", tests.ConanVirtualRepo,
"--build-name=" + tests.ConanBuildName,
"--build-number=" + buildNumber,
}
require.NoError(t, jfrogCli.Exec(args...), "conan install --requires should succeed without a conanfile")
require.NoError(t, artifactoryCli.Exec("bp", tests.ConanBuildName, buildNumber))
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.ConanBuildName, artHttpDetails)
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.ConanBuildName, buildNumber)
require.NoError(t, err)
require.True(t, found, "build info was expected to be found")
buildInfoModules := publishedBuildInfo.BuildInfo.Modules
require.Len(t, buildInfoModules, 1, "Expected 1 module")
assert.Equal(t, buildinfo.Conan, buildInfoModules[0].Type, "Module type should be conan")
assert.GreaterOrEqual(t, len(buildInfoModules[0].Dependencies), 1, "Expected at least 1 dependency (zlib)")
}
// TestConanInstallWithNameVersionOverrides tests conan install with --name and --version overrides
// applied to a local conanfile.py. Conan 2.x does not allow --name/--version with --requires,
// so a conanfile is required.
func TestConanInstallWithNameVersionOverrides(t *testing.T) {
initConanTest(t)
buildNumber := "1"
projectPath := createConanProjectNoName(t, "conan-name-version-override-test")
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
configureConanRemote(t)
defer cleanupConanRemote()
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
args := []string{
"conan", "install", ".",
"--build", "missing",
"--name", "my-custom-project",
"--version", "2.5.0",
"-r", tests.ConanVirtualRepo,
"--build-name=" + tests.ConanBuildName,
"--build-number=" + buildNumber,
}
require.NoError(t, jfrogCli.Exec(args...))
require.NoError(t, artifactoryCli.Exec("bp", tests.ConanBuildName, buildNumber))
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.ConanBuildName, artHttpDetails)
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.ConanBuildName, buildNumber)
require.NoError(t, err)
require.True(t, found, "build info was expected to be found")
buildInfoModules := publishedBuildInfo.BuildInfo.Modules
require.Len(t, buildInfoModules, 1)
assert.Equal(t, "my-custom-project:2.5.0", buildInfoModules[0].Id,
"Module ID should reflect --name and --version overrides")
assert.GreaterOrEqual(t, len(buildInfoModules[0].Dependencies), 1)
}
// TestConanInstallRecipeInSubdir tests 'jf conan install <subdir>' where the recipe is not in cwd.
func TestConanInstallRecipeInSubdir(t *testing.T) {
initConanTest(t)
buildNumber := "1"
projectPath := createConanProjectSubdir(t, "conan-subdir-install-test")
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
configureConanRemote(t)
defer cleanupConanRemote()
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
args := []string{
"conan", "install", "recipes/mylib",
"--build=missing",
"-r", tests.ConanVirtualRepo,
"--build-name=" + tests.ConanBuildName,
"--build-number=" + buildNumber,
}
require.NoError(t, jfrogCli.Exec(args...), "conan install with recipe in subdirectory should succeed")
require.NoError(t, artifactoryCli.Exec("bp", tests.ConanBuildName, buildNumber))
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.ConanBuildName, artHttpDetails)
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.ConanBuildName, buildNumber)
require.NoError(t, err)
require.True(t, found, "build info was expected to be found")
buildInfoModules := publishedBuildInfo.BuildInfo.Modules
require.Len(t, buildInfoModules, 1)
assert.Equal(t, buildinfo.Conan, buildInfoModules[0].Type)
assert.Equal(t, "cli-test-subdir-package:1.0.0", buildInfoModules[0].Id,
"Module ID should come from the subdirectory's conanfile.py")
assert.GreaterOrEqual(t, len(buildInfoModules[0].Dependencies), 1)
}
// TestConanCreateRecipeInSubdir tests 'jf conan create <subdir>' where the recipe is not in cwd.
func TestConanCreateRecipeInSubdir(t *testing.T) {
initConanTest(t)
buildNumber := "1"
projectPath := createConanProjectSubdir(t, "conan-subdir-create-test")
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
configureConanRemote(t)
defer cleanupConanRemote()
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
createArgs := []string{
"conan", "create", "recipes/mylib",
"--build=missing",
"--build-name=" + tests.ConanBuildName,
"--build-number=" + buildNumber,
}
require.NoError(t, jfrogCli.Exec(createArgs...), "conan create with recipe in subdirectory should succeed")
require.NoError(t, artifactoryCli.Exec("bp", tests.ConanBuildName, buildNumber))
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.ConanBuildName, artHttpDetails)
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.ConanBuildName, buildNumber)
require.NoError(t, err)
require.True(t, found, "build info was expected to be found")
buildInfoModules := publishedBuildInfo.BuildInfo.Modules
require.Len(t, buildInfoModules, 1)
assert.Equal(t, "cli-test-subdir-package:1.0.0", buildInfoModules[0].Id)
assert.GreaterOrEqual(t, len(buildInfoModules[0].Dependencies), 1)
}
// TestConanInstallMultipleRequires tests --requires with multiple dependencies.
func TestConanInstallMultipleRequires(t *testing.T) {
initConanTest(t)
buildNumber := "1"
tmpDir, cleanupCallback := coretests.CreateTempDirWithCallbackAndAssert(t)
t.Cleanup(cleanupCallback)
projectPath := filepath.Join(tmpDir, "multi-requires-test")
require.NoError(t, os.MkdirAll(projectPath, 0755))
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
configureConanRemote(t)
defer cleanupConanRemote()
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
args := []string{
"conan", "install",
"--requires", "zlib/1.3.1",
"--requires", "bzip2/1.0.8",
"--build", "missing",
"-r", tests.ConanVirtualRepo,
"--build-name=" + tests.ConanBuildName,
"--build-number=" + buildNumber,
}
require.NoError(t, jfrogCli.Exec(args...))
require.NoError(t, artifactoryCli.Exec("bp", tests.ConanBuildName, buildNumber))
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.ConanBuildName, artHttpDetails)
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.ConanBuildName, buildNumber)
require.NoError(t, err)
require.True(t, found, "build info was expected to be found")
buildInfoModules := publishedBuildInfo.BuildInfo.Modules
require.Len(t, buildInfoModules, 1)
assert.GreaterOrEqual(t, len(buildInfoModules[0].Dependencies), 2,
"Expected at least 2 dependencies (zlib + bzip2)")
}
// TestConanCreateWithProjectKey tests that 'jf conan create --project=<key>' stores build info
// in the correct local build dir (SHA includes the project key).
func TestConanCreateWithProjectKey(t *testing.T) {
initConanTest(t)
buildName := tests.ConanBuildName + "-project"
buildNumber := "1"
projectKey := "testprj"
projectPath := createConanProject(t, "conan-create-project-test")
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
configureConanRemote(t)
defer cleanupConanRemote()
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
createArgs := []string{
"conan", "create", ".",
"--build=missing",
"--build-name=" + buildName,
"--build-number=" + buildNumber,
"--project=" + projectKey,
}
require.NoError(t, jfrogCli.Exec(createArgs...))
// Verify local build info was stored under the project-key-aware directory
builds, err := coreBuild.GetGeneratedBuildsInfo(buildName, buildNumber, projectKey)
require.NoError(t, err)
require.Len(t, builds, 1, "Expected 1 build info file stored with project key '%s'", projectKey)
assert.Equal(t, buildName, builds[0].Name)
assert.Equal(t, buildNumber, builds[0].Number)
// Verify that the build is NOT found under the empty-project directory
buildsNoProject, err := coreBuild.GetGeneratedBuildsInfo(buildName, buildNumber, "")
assert.NoError(t, err)
assert.Empty(t, buildsNoProject, "Build info should NOT exist under empty project key directory")
// Cleanup local build dir
assert.NoError(t, coreBuild.RemoveBuildDir(buildName, buildNumber, projectKey))
}
// TestConanCreateWithoutProjectKey verifies no regression: 'jf conan create' without --project
// still stores build info in the default (empty project) directory.
func TestConanCreateWithoutProjectKey(t *testing.T) {
initConanTest(t)
buildName := tests.ConanBuildName + "-noproject"
buildNumber := "1"
projectPath := createConanProject(t, "conan-create-noproject-test")
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
configureConanRemote(t)
defer cleanupConanRemote()
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
createArgs := []string{
"conan", "create", ".",
"--build=missing",
"--build-name=" + buildName,
"--build-number=" + buildNumber,
}
require.NoError(t, jfrogCli.Exec(createArgs...))
// Verify local build info was stored under the empty project directory
builds, err := coreBuild.GetGeneratedBuildsInfo(buildName, buildNumber, "")
require.NoError(t, err)
require.Len(t, builds, 1, "Expected 1 build info file stored without project key")
assert.Equal(t, buildName, builds[0].Name)
// Cleanup local build dir
assert.NoError(t, coreBuild.RemoveBuildDir(buildName, buildNumber, ""))
}
// TestConanInstallWithProjectKey tests that 'jf conan install --project=<key>' stores
// build info in the project-key-aware directory.
func TestConanInstallWithProjectKey(t *testing.T) {
initConanTest(t)
buildName := tests.ConanBuildName + "-install-project"
buildNumber := "1"
projectKey := "testprj"
projectPath := createConanProject(t, "conan-install-project-test")
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
configureConanRemote(t)
defer cleanupConanRemote()
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
installArgs := []string{
"conan", "install", ".",
"--build=missing",
"-r", tests.ConanVirtualRepo,
"--build-name=" + buildName,
"--build-number=" + buildNumber,
"--project=" + projectKey,
}
require.NoError(t, jfrogCli.Exec(installArgs...))
// Verify local build info was stored with project key
builds, err := coreBuild.GetGeneratedBuildsInfo(buildName, buildNumber, projectKey)
require.NoError(t, err)
require.Len(t, builds, 1, "Expected 1 build info file stored with project key '%s'", projectKey)
// Verify NOT stored under empty-project dir
buildsNoProject, err := coreBuild.GetGeneratedBuildsInfo(buildName, buildNumber, "")
assert.NoError(t, err)
assert.Empty(t, buildsNoProject, "Build info should NOT exist under empty project key directory")
// Cleanup
assert.NoError(t, coreBuild.RemoveBuildDir(buildName, buildNumber, projectKey))
}
// TestConanUploadWithProjectKey tests that 'jf conan upload --project=<key>' stores
// build info in the project-key-aware directory.
func TestConanUploadWithProjectKey(t *testing.T) {
initConanTest(t)
buildName := tests.ConanBuildName + "-upload-project"
buildNumber := "1"
projectKey := "testprj"
projectPath := createConanProject(t, "conan-upload-project-test")
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
configureConanRemote(t)
defer cleanupConanRemote()
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
// First create the package so it can be uploaded
createArgs := []string{
"conan", "create", ".",
"--build=missing",
"--build-name=" + buildName,
"--build-number=" + buildNumber,
"--project=" + projectKey,
}
require.NoError(t, jfrogCli.Exec(createArgs...))
// Upload with --project
uploadArgs := []string{
"conan", "upload", "cli-test-package/*",
"-r", tests.ConanLocalRepo,
"--confirm",
"--build-name=" + buildName,
"--build-number=" + buildNumber,
"--project=" + projectKey,
}
require.NoError(t, jfrogCli.Exec(uploadArgs...))
// Verify local build info was stored with project key
builds, err := coreBuild.GetGeneratedBuildsInfo(buildName, buildNumber, projectKey)
require.NoError(t, err)
require.NotEmpty(t, builds, "Expected build info files stored with project key '%s'", projectKey)
// Cleanup
assert.NoError(t, coreBuild.RemoveBuildDir(buildName, buildNumber, projectKey))
}
// TestConanBuildPublishWithProjectKey verifies that build info stored with --project
// is isolated from builds without --project.
func TestConanBuildPublishWithProjectKey(t *testing.T) {
initConanTest(t)
buildName := tests.ConanBuildName + "-bp-project"
buildNumber := "1"
projectKey := "testprj"
projectPath := createConanProject(t, "conan-bp-project-test")
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
configureConanRemote(t)
defer cleanupConanRemote()
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
// Create with --project so build info is stored with project key in the dir hash
createArgs := []string{
"conan", "create", ".",
"--build=missing",
"--build-name=" + buildName,
"--build-number=" + buildNumber,
"--project=" + projectKey,
}
require.NoError(t, jfrogCli.Exec(createArgs...))
// Verify the project-key-aware build dir has build info files
buildsInfo, err := coreBuild.GetGeneratedBuildsInfo(buildName, buildNumber, projectKey)
require.NoError(t, err)
assert.NotEmpty(t, buildsInfo, "Build info should exist in the project-key-aware build dir")
// Verify the build dir WITHOUT project key does NOT have build info files
buildsInfoNoProject, err := coreBuild.GetGeneratedBuildsInfo(buildName, buildNumber, "")
require.NoError(t, err)
assert.Empty(t, buildsInfoNoProject, "Build info should NOT exist in the non-project build dir")
// Cleanup
assert.NoError(t, coreBuild.RemoveBuildDir(buildName, buildNumber, projectKey))
assert.NoError(t, coreBuild.RemoveBuildDir(buildName, buildNumber, ""))
}
// TestConanProjectKeyBuildDirHash verifies the SHA256 directory name computation.
// With --project=vsm the local build dir should be SHA256("buildName_buildNumber_vsm"),
func TestConanProjectKeyBuildDirHash(t *testing.T) {
initConanTest(t)
buildName := tests.ConanBuildName + "-hash"
buildNumber := "1"
projectKey := "vsm"
projectPath := createConanProject(t, "conan-hash-test")
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
configureConanRemote(t)
defer cleanupConanRemote()
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
createArgs := []string{
"conan", "create", ".",
"--build=missing",
"--build-name=" + buildName,
"--build-number=" + buildNumber,
"--project=" + projectKey,
}
require.NoError(t, jfrogCli.Exec(createArgs...))
// Compute expected directory names
expectedWithProject := sha256.Sum256([]byte(buildName + "_" + buildNumber + "_" + projectKey))
expectedDirWithProject := hex.EncodeToString(expectedWithProject[:])
buggyNoProject := sha256.Sum256([]byte(buildName + "_" + buildNumber + "_"))
buggyDirNoProject := hex.EncodeToString(buggyNoProject[:])
// Get the actual build dir path (should include project key)
buildDir, err := coreBuild.GetBuildDir(buildName, buildNumber, projectKey)
require.NoError(t, err)
actualDirName := filepath.Base(buildDir)
assert.Equal(t, expectedDirWithProject, actualDirName,
"Build dir should be SHA256 of '%s_%s_%s'", buildName, buildNumber, projectKey)
assert.NotEqual(t, buggyDirNoProject, actualDirName,
"Build dir must NOT be SHA256 of '%s_%s_' (old bug)", buildName, buildNumber)
// Verify build info file exists in that directory
builds, err := coreBuild.GetGeneratedBuildsInfo(buildName, buildNumber, projectKey)
require.NoError(t, err)
require.Len(t, builds, 1, "Expected build info to exist in the project-key-aware directory")
assert.NoError(t, coreBuild.RemoveBuildDir(buildName, buildNumber, projectKey))
}
// TestConanMultipleProjectKeys tests that builds with different project keys
// are stored in separate directories and don't interfere with each other.
func TestConanMultipleProjectKeys(t *testing.T) {
initConanTest(t)
buildName := tests.ConanBuildName + "-multiproj"
buildNumber := "1"
projectKeys := []string{"proj1", "proj2", ""}
projectPath := createConanProject(t, "conan-multi-project-test")
wd, err := os.Getwd()
require.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()
configureConanRemote(t)
defer cleanupConanRemote()
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
// Run create with different project keys
for _, pk := range projectKeys {
args := []string{
"conan", "create", ".",
"--build=missing",
"--build-name=" + buildName,
"--build-number=" + buildNumber,
}
if pk != "" {
args = append(args, "--project="+pk)
}
require.NoError(t, jfrogCli.Exec(args...), "Failed for project key '%s'", pk)
}
// Verify each project key has its own build info, isolated from the others
for _, pk := range projectKeys {