Skip to content

Add test for twine with probs #3010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ require (

// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20250529104758-6d769a684388

replace github.com/jfrog/jfrog-cli-artifactory => github.com/jfrog/jfrog-cli-artifactory v0.3.3-0.20250623095509-b3fe2c4681ad
replace github.com/jfrog/jfrog-cli-artifactory => github.com/jfrog/jfrog-cli-artifactory v0.3.3-0.20250708062743-ea3521f9b71a

replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20250629143350-c43614bbffcd

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s=
github.com/jfrog/gofrog v1.7.6/go.mod h1:ntr1txqNOZtHplmaNd7rS4f8jpA5Apx8em70oYEe7+4=
github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYLipdsOFMY=
github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w=
github.com/jfrog/jfrog-cli-artifactory v0.3.3-0.20250623095509-b3fe2c4681ad h1:cnbcCK0VTHdLdmmv/9fYTRjuR1ewrYBW/S87pVE+d+s=
github.com/jfrog/jfrog-cli-artifactory v0.3.3-0.20250623095509-b3fe2c4681ad/go.mod h1:hnXaevmDyQpyhpH5kwDufIjUUXXuKs54i+AX2CEywKE=
github.com/jfrog/jfrog-cli-artifactory v0.3.3-0.20250708062743-ea3521f9b71a h1:6MGWtX26HBg3euJ8mbOIO0oR5p3LaHBzk8PzsFgbvTs=
github.com/jfrog/jfrog-cli-artifactory v0.3.3-0.20250708062743-ea3521f9b71a/go.mod h1:hnXaevmDyQpyhpH5kwDufIjUUXXuKs54i+AX2CEywKE=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20250629143350-c43614bbffcd h1:1Nw+HKbtQZGEogerQBNM77RvbUwHYNKFNYJk4lmNF9w=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20250629143350-c43614bbffcd/go.mod h1:BkDHfCVecjcRNC+aqmHtTrKe+/K8MyjzmHYe5rER5Yg=
github.com/jfrog/jfrog-cli-platform-services v1.10.0 h1:O+N/VAF+QjFvq9xkHpmzKLcdl9aJu3IP204Su0L14rw=
Expand Down
87 changes: 87 additions & 0 deletions pip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
biutils "github.com/jfrog/build-info-go/utils"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
coretests "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
"github.com/jfrog/jfrog-cli-security/commands/audit/sca/python"
Expand Down Expand Up @@ -305,3 +306,89 @@ func TestSetupPipCommand(t *testing.T) {
assert.Equal(t, http.StatusOK, res.StatusCode)
}
}

func TestTwineWithBuildNameAndNumberProperties(t *testing.T) {
initPipTest(t)

oldHomeDir, newHomeDir := prepareHomeDir(t)
defer func() {
clientTestUtils.SetEnvAndAssert(t, coreutils.HomeDir, oldHomeDir)
clientTestUtils.RemoveAllAndAssert(t, newHomeDir)
}()

allTests := []struct {
name string
project string
outputFolder string
expectedModuleId string
args []string
expectedArtifacts int
}{
{"twineWithProbs", "pyproject", "twine", "jfrog-python-example:1.0", []string{}, 2},
}

for testNumber, test := range allTests {
t.Run(test.name, func(t *testing.T) {
cleanVirtualEnv, err := prepareVirtualEnv(t)
assert.NoError(t, err)

buildNumber := strconv.Itoa(100 + testNumber)
test.args = append([]string{"twine", "upload", "dist/*", "--build-name=" + tests.PipBuildName, "--build-number=" + buildNumber}, test.args...)
VerifyBuildNameAndNumberPropertiesOnTwineArtifact(t, createPypiProject(t, test.outputFolder, test.project, "twine"), buildNumber, test.expectedModuleId, test.expectedArtifacts, test.args)

cleanVirtualEnv()
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.PipBuildName, artHttpDetails)
})
}
}

func VerifyBuildNameAndNumberPropertiesOnTwineArtifact(t *testing.T, projectPath, buildNumber, expectedModuleId string, expectedArtifacts int, args []string) {
wd, err := os.Getwd()
assert.NoError(t, err, "Failed to get current dir")
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()

jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
err = jfrogCli.Exec(args...)
if err != nil {
assert.Fail(t, "Failed executing twine upload command", err.Error())
return
}

assert.NoError(t, artifactoryCli.Exec("bp", tests.PipBuildName, buildNumber))

publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.PipBuildName, buildNumber)
if err != nil {
assert.NoError(t, err)
return
}
if !found {
assert.True(t, found, "build info was expected to be found")
return
}
buildInfo := publishedBuildInfo.BuildInfo
require.Len(t, buildInfo.Modules, 1)
twineModule := buildInfo.Modules[0]
assert.Equal(t, buildinfo.Python, twineModule.Type)
assert.Len(t, twineModule.Artifacts, expectedArtifacts)
assert.Equal(t, expectedModuleId, twineModule.Id)

serviceManager, err := utils.CreateServiceManager(serverDetails, 3, 1000, false)
if err != nil {
return
}

for _, artifact := range twineModule.Artifacts {
relativePath := artifact.OriginalDeploymentRepo + "/" + artifact.Path

probs, err := serviceManager.GetItemProps(relativePath)
if err != nil {
assert.Fail(t, "Failed to get item properties for the twine module artifact", err.Error())
continue
}

if probs == nil {
assert.Fail(t, "Properties for the twine module artifact are not set")
}
}
}
Loading