Skip to content

Commit

Permalink
Add npm distribution tags test (#2513)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNino committed May 2, 2024
1 parent b6c104e commit bf350dc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ require (
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
Expand All @@ -137,7 +137,7 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240424135031-dac0f92a2aae
replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240502151649-934fb7391b5c

replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240430132902-9d4dfaf05041

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ github.com/jfrog/gofrog v1.7.1 h1:ME1Meg4hukAT/7X6HUQCVSe4DNjMZACCP8aCY37EW/w=
github.com/jfrog/gofrog v1.7.1/go.mod h1:X7bjfWoQDN0Z4FQGbE91j3gbPP7Urwzm4Z8tkvrlbRI=
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-core/v2 v2.31.1-0.20240424135031-dac0f92a2aae h1:Lgn3WxoSc4YwhitPF2sPlqVviDZ4WRMI8eLOQqV9GZs=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240424135031-dac0f92a2aae/go.mod h1:/rNY4nIB8hIsL+MLGrZOgOYpY4QnJ+CHeTHPQDdGmOk=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240502151649-934fb7391b5c h1:7pvL4q0Mo3i7b7/r8+FriL/j2JwI6AIDn5QTfCKvLSk=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240502151649-934fb7391b5c/go.mod h1:S0hIZcojq4GehyOOSt0o9x4fExWFtamwfFc7bfIWW+4=
github.com/jfrog/jfrog-cli-security v1.1.0 h1:ifCjFJSa1D1pWyW/ADYPqnMkOddzkAT/WY4vHAufn1g=
github.com/jfrog/jfrog-cli-security v1.1.0/go.mod h1:086t7e/einVAGfBXxRdEGDKovWt67I6SqUb1rcpdiZc=
github.com/jfrog/jfrog-client-go v1.28.1-0.20240430132902-9d4dfaf05041 h1:cDTm4RxkI+RA8aNmdfM2BVxb5iCoXjLjhb+M+ReEIrE=
Expand Down Expand Up @@ -335,8 +335,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
44 changes: 44 additions & 0 deletions npm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"fmt"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/generic"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -460,6 +462,48 @@ func TestNpmPublishDetailedSummary(t *testing.T) {
assert.Equal(t, 64, len(files[0].Sha256), "Summary validation failed - sha256 should be in size 64 digits.")
}

func TestNpmDistTag(t *testing.T) {
initNpmTest(t)
defer cleanNpmTest(t)
wd, err := os.Getwd()
assert.NoError(t, err, "Failed to get current dir")
npmPath := initNpmProjectTest(t)
chdirCallBack := clientTestUtils.ChangeDirWithCallback(t, wd, npmPath)
defer chdirCallBack()

jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")

// Publish package with tag.
tagP := "tag-from-publish"
assert.NoError(t, jfrogCli.Exec("npm", "p", "--tag="+tagP))

// Add tag using dist-tag add command.
tagDt := "tag-from-dist-tag"
assert.NoError(t, jfrogCli.Exec("npm", "dist-tag", "add", "jfrog-cli-tests@v1.0.0", tagDt))

assertDistTagsExist(t, []string{tagP, tagDt, "latest"})
}

func assertDistTagsExist(t *testing.T, expectedTags []string) {
searchSpecBuilder := spec.NewBuilder().Pattern(tests.NpmRepo + "/*jfrog-cli-tests*1.0.0.tgz").Recursive(true)
searchCmd := generic.NewSearchCommand()
searchCmd.SetServerDetails(serverDetails)
searchCmd.SetSpec(searchSpecBuilder.BuildSpec())

reader, err := searchCmd.Search()
assert.NoError(t, err)
readerGetErrorAndAssert(t, reader)
defer readerCloseAndAssert(t, reader)
length, err := reader.Length()
assert.NoError(t, err)
if !assert.Equal(t, length, 1) {
return
}
for resultItem := new(utils.SearchResult); reader.NextRecord(resultItem) == nil; resultItem = new(utils.SearchResult) {
assert.ElementsMatch(t, resultItem.Props[npm.DistTagPropKey], expectedTags)
}
}

func TestNpmPublishWithDeploymentView(t *testing.T) {
initNpmTest(t)
defer cleanNpmTest(t)
Expand Down

0 comments on commit bf350dc

Please sign in to comment.