@@ -3,16 +3,20 @@ package lifecycle
33import (
44 "encoding/json"
55 "fmt"
6- artifactoryAuth "github.com/jfrog/jfrog-client-go/artifactory/auth"
7- "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
8- "github.com/jfrog/jfrog-client-go/http/jfroghttpclient"
9- lifecycle "github.com/jfrog/jfrog-client-go/lifecycle/services"
10- "github.com/stretchr/testify/assert"
6+ "io"
117 "net/http"
128 "net/http/httptest"
139 "net/url"
1410 "testing"
1511 "time"
12+
13+ artifactoryAuth "github.com/jfrog/jfrog-client-go/artifactory/auth"
14+ "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
15+ "github.com/jfrog/jfrog-client-go/http/jfroghttpclient"
16+ lifecycle "github.com/jfrog/jfrog-client-go/lifecycle/services"
17+ distributionUtils "github.com/jfrog/jfrog-client-go/utils/distribution"
18+ "github.com/stretchr/testify/assert"
19+ "github.com/stretchr/testify/require"
1620)
1721
1822const (
@@ -248,6 +252,43 @@ func TestRemoteDeleteReleaseBundle(t *testing.T) {
248252 assert .NoError (t , rbService .RemoteDeleteReleaseBundle (testRb , lifecycle.ReleaseBundleRemoteDeleteParams {MaxWaitMinutes : 2 }))
249253}
250254
255+ func TestRemoteDeleteReleaseBundleSendsPriority (t * testing.T ) {
256+ var capturedBody []byte
257+ var capturedMethod string
258+ mockServer , rbService := createMockServer (t , func (w http.ResponseWriter , r * http.Request ) {
259+ expectedPath := "/" + lifecycle .GetRemoteDeleteReleaseBundleApi (testRb , true )
260+ if r .URL .Path == expectedPath {
261+ capturedMethod = r .Method
262+ body , err := io .ReadAll (r .Body )
263+ assert .NoError (t , err )
264+ capturedBody = body
265+ w .WriteHeader (http .StatusAccepted )
266+ return
267+ }
268+ w .WriteHeader (http .StatusNotFound )
269+ })
270+ defer mockServer .Close ()
271+
272+ params := lifecycle.ReleaseBundleRemoteDeleteParams {
273+ DistributionRules : []* distributionUtils.DistributionCommonParams {{SiteName : "edge1" , Priority : "medium" }},
274+ Priority : "high" ,
275+ DryRun : true ,
276+ }
277+ assert .NoError (t , rbService .RemoteDeleteReleaseBundle (testRb , params ))
278+ assert .Equal (t , http .MethodPost , capturedMethod )
279+
280+ var body map [string ]any
281+ require .NoError (t , json .Unmarshal (capturedBody , & body ))
282+ assert .Equal (t , "high" , body ["priority" ])
283+ rules , ok := body ["distribution_rules" ].([]any )
284+ require .True (t , ok )
285+ require .Len (t , rules , 1 )
286+ rule , ok := rules [0 ].(map [string ]any )
287+ require .True (t , ok )
288+ assert .Equal (t , "edge1" , rule ["site_name" ])
289+ assert .Equal (t , "medium" , rule ["priority" ])
290+ }
291+
251292func TestGetReleaseBundleVersionPromotions (t * testing.T ) {
252293 mockServer , rbService := createMockServer (t , func (w http.ResponseWriter , r * http.Request ) {
253294 if r .RequestURI == "/" + lifecycle .GetGetReleaseBundleVersionPromotionsApi (testRb ) {
0 commit comments