forked from jfrog/jfrog-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconan_test.go
More file actions
469 lines (387 loc) · 15.7 KB
/
conan_test.go
File metadata and controls
469 lines (387 loc) · 15.7 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
package main
import (
"os"
"os/exec"
"path/filepath"
"strconv"
"testing"
buildinfo "github.com/jfrog/build-info-go/entities"
biutils "github.com/jfrog/build-info-go/utils"
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 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()
}