Skip to content

Commit 576ae49

Browse files
authored
JGC-429 - Bump go 1.25.4 (#1483)
1 parent 8c79bb0 commit 576ae49

23 files changed

+153
-125
lines changed

artifactory/commands/transferfiles/state/runstatus_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ func TestSaveAndLoadRunStatus(t *testing.T) {
1717
assert.NoError(t, err)
1818
assert.True(t, exists)
1919
assert.Equal(t, transferRunStatusVersion, actualStatus.Version)
20-
actualStatus.TimeEstimationManager.stateManager = stateManager
20+
actualStatus.stateManager = stateManager
2121
assert.Equal(t, stateManager.TransferRunStatus, actualStatus)
2222
}

artifactory/commands/transferfiles/state/state_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func TestGetTransferStateAndSnapshotLoading(t *testing.T) {
126126
assert.NoError(t, stateManager.SaveStateAndSnapshots())
127127
// Modify state again, and assert that the loaded state from snapshot was not modified and remained as saved.
128128
assert.NoError(t, stateManager.IncTransferredSizeAndFilesPhase1(2, 3))
129-
assert.NotEqual(t, stateManager.TransferState.CurrentRepo, originalState.CurrentRepo)
129+
assert.NotEqual(t, stateManager.CurrentRepo, originalState.CurrentRepo)
130130
assertGetTransferStateAndSnapshot(t, false, originalState, stateManager.repoTransferSnapshot, true)
131131

132132
// After repo fully transferred, expected to load state without snapshots.

artifactory/commands/transferfiles/state/statemanager.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package state
22

33
import (
44
"fmt"
5-
"github.com/jfrog/gofrog/safeconvert"
65
"path/filepath"
76
"time"
87

8+
"github.com/jfrog/gofrog/safeconvert"
9+
910
"github.com/jfrog/gofrog/datastructures"
1011
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/transferfiles/api"
1112
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
@@ -49,7 +50,7 @@ func NewTransferStateManager(loadRunStatus bool) (*TransferStateManager, error)
4950
}
5051
stateManager.TransferRunStatus = transferRunStatus
5152
}
52-
stateManager.TimeEstimationManager.stateManager = &stateManager
53+
stateManager.stateManager = &stateManager
5354
return &stateManager, nil
5455
}
5556

@@ -128,7 +129,7 @@ func (ts *TransferStateManager) SetRepoState(repoKey string, totalSizeBytes, tot
128129
func (ts *TransferStateManager) SetRepoFullTransferStarted(startTime time.Time) error {
129130
// We do not want to change the start time if it already exists, because it means we continue transferring from a snapshot.
130131
// Some dirs may not be searched again (if done exploring or completed), so handling their diffs from the original time is required.
131-
return ts.TransferState.Action(func(state *TransferState) error {
132+
return ts.Action(func(state *TransferState) error {
132133
if state.CurrentRepo.FullTransfer.Started == "" {
133134
state.CurrentRepo.FullTransfer.Started = ConvertTimeToRFC3339(startTime)
134135
}
@@ -137,23 +138,23 @@ func (ts *TransferStateManager) SetRepoFullTransferStarted(startTime time.Time)
137138
}
138139

139140
func (ts *TransferStateManager) SetRepoFullTransferCompleted() error {
140-
return ts.TransferState.Action(func(state *TransferState) error {
141+
return ts.Action(func(state *TransferState) error {
141142
state.CurrentRepo.FullTransfer.Ended = ConvertTimeToRFC3339(time.Now())
142143
return nil
143144
})
144145
}
145146

146147
// Increasing Transferred Diff files (modified files) and SizeByBytes value in suitable repository progress state
147148
func (ts *TransferStateManager) IncTransferredSizeAndFilesPhase1(chunkTotalFiles, chunkTotalSizeInBytes int64) error {
148-
err := ts.TransferState.Action(func(state *TransferState) error {
149+
err := ts.Action(func(state *TransferState) error {
149150
atomicallyAddInt64(&state.CurrentRepo.Phase1Info.TransferredSizeBytes, chunkTotalSizeInBytes)
150151
atomicallyAddInt64(&state.CurrentRepo.Phase1Info.TransferredUnits, chunkTotalFiles)
151152
return nil
152153
})
153154
if err != nil {
154155
return err
155156
}
156-
return ts.TransferRunStatus.action(func(transferRunStatus *TransferRunStatus) error {
157+
return ts.action(func(transferRunStatus *TransferRunStatus) error {
157158
atomicallyAddInt64(&transferRunStatus.OverallTransfer.TransferredSizeBytes, chunkTotalSizeInBytes)
158159
atomicallyAddInt64(&transferRunStatus.OverallTransfer.TransferredUnits, chunkTotalFiles)
159160

@@ -165,15 +166,15 @@ func (ts *TransferStateManager) IncTransferredSizeAndFilesPhase1(chunkTotalFiles
165166
}
166167

167168
func (ts *TransferStateManager) IncTransferredSizeAndFilesPhase2(chunkTotalFiles, chunkTotalSizeInBytes int64) error {
168-
return ts.TransferState.Action(func(state *TransferState) error {
169+
return ts.Action(func(state *TransferState) error {
169170
atomicallyAddInt64(&state.CurrentRepo.Phase2Info.TransferredSizeBytes, chunkTotalSizeInBytes)
170171
atomicallyAddInt64(&state.CurrentRepo.Phase2Info.TransferredUnits, chunkTotalFiles)
171172
return nil
172173
})
173174
}
174175

175176
func (ts *TransferStateManager) IncTotalSizeAndFilesPhase2(filesNumber, totalSize int64) error {
176-
return ts.TransferState.Action(func(state *TransferState) error {
177+
return ts.Action(func(state *TransferState) error {
177178
atomicallyAddInt64(&state.CurrentRepo.Phase2Info.TotalSizeBytes, totalSize)
178179
atomicallyAddInt64(&state.CurrentRepo.Phase2Info.TotalUnits, filesNumber)
179180
return nil
@@ -182,7 +183,7 @@ func (ts *TransferStateManager) IncTotalSizeAndFilesPhase2(filesNumber, totalSiz
182183

183184
// Set relevant information of files and storage we need to transfer in phase3
184185
func (ts *TransferStateManager) SetTotalSizeAndFilesPhase3(filesNumber, totalSize int64) error {
185-
return ts.TransferState.Action(func(state *TransferState) error {
186+
return ts.Action(func(state *TransferState) error {
186187
state.CurrentRepo.Phase3Info.TransferredUnits = 0
187188
state.CurrentRepo.Phase3Info.TransferredSizeBytes = 0
188189
atomicallyAddInt64(&state.CurrentRepo.Phase3Info.TotalSizeBytes, totalSize)
@@ -193,7 +194,7 @@ func (ts *TransferStateManager) SetTotalSizeAndFilesPhase3(filesNumber, totalSiz
193194

194195
// Increase transferred storage and files in phase 3
195196
func (ts *TransferStateManager) IncTransferredSizeAndFilesPhase3(chunkTotalFiles, chunkTotalSizeInBytes int64) error {
196-
return ts.TransferState.Action(func(state *TransferState) error {
197+
return ts.Action(func(state *TransferState) error {
197198
atomicallyAddInt64(&state.CurrentRepo.Phase3Info.TransferredSizeBytes, chunkTotalSizeInBytes)
198199
atomicallyAddInt64(&state.CurrentRepo.Phase3Info.TransferredUnits, chunkTotalFiles)
199200
return nil
@@ -202,7 +203,7 @@ func (ts *TransferStateManager) IncTransferredSizeAndFilesPhase3(chunkTotalFiles
202203

203204
// Returns pointers to TotalStorage, TotalFiles, TransferredFiles and TransferredStorage from progressState of a specific Repository.
204205
func (ts *TransferStateManager) GetStorageAndFilesRepoPointers(phase int) (totalFailedStorage, totalUploadedFailedStorage, totalFailedFiles, totalUploadedFailedFiles *int64, err error) {
205-
err = ts.TransferState.Action(func(state *TransferState) error {
206+
err = ts.Action(func(state *TransferState) error {
206207
switch phase {
207208
case api.Phase1:
208209
totalFailedStorage = &ts.CurrentRepo.Phase1Info.TotalSizeBytes
@@ -228,7 +229,7 @@ func (ts *TransferStateManager) GetStorageAndFilesRepoPointers(phase int) (total
228229
// Adds new diff details to the repo's diff array in state.
229230
// Marks files handling as started, and sets the handling range.
230231
func (ts *TransferStateManager) AddNewDiffToState(startTime time.Time) error {
231-
return ts.TransferState.Action(func(state *TransferState) error {
232+
return ts.Action(func(state *TransferState) error {
232233

233234
newDiff := DiffDetails{}
234235

@@ -254,7 +255,7 @@ func (ts *TransferStateManager) AddNewDiffToState(startTime time.Time) error {
254255
}
255256

256257
func (ts *TransferStateManager) SetFilesDiffHandlingCompleted() error {
257-
return ts.TransferState.Action(func(state *TransferState) error {
258+
return ts.Action(func(state *TransferState) error {
258259
state.CurrentRepo.Diffs[len(state.CurrentRepo.Diffs)-1].FilesDiffRunTime.Ended = ConvertTimeToRFC3339(time.Now())
259260
state.CurrentRepo.Diffs[len(state.CurrentRepo.Diffs)-1].Completed = true
260261
return nil
@@ -281,14 +282,14 @@ func (ts *TransferStateManager) GetReposTransferredSizeBytes(repoKeys ...string)
281282
}
282283

283284
func (ts *TransferStateManager) GetTransferredSizeBytes() (transferredSizeBytes int64, err error) {
284-
return transferredSizeBytes, ts.TransferRunStatus.action(func(transferRunStatus *TransferRunStatus) error {
285+
return transferredSizeBytes, ts.action(func(transferRunStatus *TransferRunStatus) error {
285286
transferredSizeBytes = transferRunStatus.OverallTransfer.TransferredSizeBytes
286287
return nil
287288
})
288289
}
289290

290291
func (ts *TransferStateManager) GetDiffHandlingRange() (start, end time.Time, err error) {
291-
return start, end, ts.TransferState.Action(func(state *TransferState) error {
292+
return start, end, ts.Action(func(state *TransferState) error {
292293
var inErr error
293294
start, inErr = ConvertRFC3339ToTime(state.CurrentRepo.Diffs[len(state.CurrentRepo.Diffs)-1].HandledRange.Started)
294295
if inErr != nil {
@@ -307,42 +308,42 @@ func (ts *TransferStateManager) IncVisitedFolders() error {
307308
}
308309

309310
func (ts *TransferStateManager) ChangeDelayedFilesCountBy(count uint64, increase bool) error {
310-
return ts.TransferRunStatus.action(func(transferRunStatus *TransferRunStatus) error {
311+
return ts.action(func(transferRunStatus *TransferRunStatus) error {
311312
atomicallyAddUint64(&transferRunStatus.DelayedFiles, count, increase)
312313
return nil
313314
})
314315
}
315316

316317
func (ts *TransferStateManager) ChangeTransferFailureCountBy(count uint64, increase bool) error {
317-
return ts.TransferRunStatus.action(func(transferRunStatus *TransferRunStatus) error {
318+
return ts.action(func(transferRunStatus *TransferRunStatus) error {
318319
atomicallyAddUint64(&transferRunStatus.TransferFailures, count, increase)
319320
return nil
320321
})
321322
}
322323

323324
func (ts *TransferStateManager) IncRepositoriesTransferred() error {
324-
return ts.TransferRunStatus.action(func(transferRunStatus *TransferRunStatus) error {
325+
return ts.action(func(transferRunStatus *TransferRunStatus) error {
325326
transferRunStatus.TotalRepositories.TransferredUnits++
326327
return nil
327328
})
328329
}
329330

330331
func (ts *TransferStateManager) SetRepoPhase(phaseId int) error {
331-
return ts.TransferRunStatus.action(func(transferRunStatus *TransferRunStatus) error {
332+
return ts.action(func(transferRunStatus *TransferRunStatus) error {
332333
transferRunStatus.CurrentRepoPhase = phaseId
333334
return nil
334335
})
335336
}
336337

337338
func (ts *TransferStateManager) SetWorkingThreads(workingThreads int) error {
338-
return ts.TransferRunStatus.action(func(transferRunStatus *TransferRunStatus) error {
339+
return ts.action(func(transferRunStatus *TransferRunStatus) error {
339340
transferRunStatus.WorkingThreads = workingThreads
340341
return nil
341342
})
342343
}
343344

344345
func (ts *TransferStateManager) GetWorkingThreads() (workingThreads int, err error) {
345-
return workingThreads, ts.TransferRunStatus.action(func(transferRunStatus *TransferRunStatus) error {
346+
return workingThreads, ts.action(func(transferRunStatus *TransferRunStatus) error {
346347
workingThreads = transferRunStatus.WorkingThreads
347348
return nil
348349
})

artifactory/commands/transferfiles/transfer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func (tdc *TransferFilesCommand) initStateManager(allSourceLocalRepos, sourceBui
237237
tdc.stateManager.OverallTransfer.TotalUnits = totalFiles
238238
tdc.stateManager.TotalRepositories.TotalUnits = int64(len(allSourceLocalRepos))
239239
tdc.stateManager.OverallBiFiles.TotalUnits = totalBiFiles
240-
tdc.stateManager.TimeEstimationManager.CurrentTotalTransferredBytes = 0
240+
tdc.stateManager.CurrentTotalTransferredBytes = 0
241241
if !tdc.ignoreState {
242242
numberInitialErrors, e := getRetryErrorCount(allSourceLocalRepos)
243243
if e != nil {

artifactory/commands/transferfiles/transfer_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,11 @@ func writeMockResponse(t *testing.T, w http.ResponseWriter, resp interface{}) {
298298

299299
func initPollUploadsTestMockServer(t *testing.T, totalChunkStatusVisits *int, totalUploadChunkVisits *int, file api.FileRepresentation) (*httptest.Server, *coreConfig.ServerDetails, artifactory.ArtifactoryServicesManager) {
300300
return commonTests.CreateRtRestsMockServer(t, func(w http.ResponseWriter, r *http.Request) {
301-
if r.RequestURI == "/"+utils.PluginsExecuteRestApi+"uploadChunk" {
301+
switch r.RequestURI {
302+
case "/" + utils.PluginsExecuteRestApi + "uploadChunk":
302303
*totalUploadChunkVisits++
303304
getUploadChunkMockResponse(t, w, totalUploadChunkVisits)
304-
} else if r.RequestURI == "/"+utils.PluginsExecuteRestApi+syncChunks {
305+
case "/" + utils.PluginsExecuteRestApi + syncChunks:
305306
*totalChunkStatusVisits++
306307
validateChunkStatusBody(t, r)
307308
// If already visited chunk status, return status done this time.

artifactory/commands/transferfiles/utils_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func TestStopTransferOnArtifactoryNodes(t *testing.T) {
101101
nodeId = "node-2"
102102
stoppedNodeTwo = true
103103
}
104-
_, err := w.Write([]byte(fmt.Sprintf(`{"node_id": "%s"}`, nodeId)))
104+
_, err := fmt.Fprintf(w, `{"node_id": "%s"}`, nodeId)
105105
assert.NoError(t, err)
106106
requestNumber++
107107
})
@@ -231,7 +231,7 @@ func TestUpdateMaxUniqueSnapshots(t *testing.T) {
231231
default:
232232
assert.Fail(t, "tried to update the Max Unique Snapshots setting of a repository of an unsupported package type")
233233
}
234-
_, err = w.Write([]byte(fmt.Sprintf("Repository %s-local update successfully.", packageType)))
234+
_, err = fmt.Fprintf(w, "Repository %s-local update successfully.", packageType)
235235
assert.NoError(t, err)
236236
})
237237
defer testServer.Close()

artifactory/commands/transferinstall/datatransferinstall.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ package transferinstall
22

33
import (
44
"fmt"
5+
"net/http"
6+
"net/url"
7+
"os"
8+
"path"
9+
"path/filepath"
10+
"strings"
11+
512
biutils "github.com/jfrog/build-info-go/utils"
613
"github.com/jfrog/gofrog/version"
714
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
@@ -10,12 +17,6 @@ import (
1017
"github.com/jfrog/jfrog-client-go/utils/errorutils"
1118
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
1219
"github.com/jfrog/jfrog-client-go/utils/log"
13-
"net/http"
14-
"net/url"
15-
"os"
16-
"path"
17-
"path/filepath"
18-
"strings"
1920
)
2021

2122
const (
@@ -36,9 +37,9 @@ var (
3637
originalDirPath = FileItem{"etc", "plugins"}
3738
v7DirPath = FileItem{"var", "etc", "artifactory", "plugins"}
3839
// Error types
39-
notValidDestinationErr = fmt.Errorf("can't find the directory in which to install the data-transfer plugin. Please ensure you're running this command on the machine on which Artifactory is installed. You can also use the --home-dir option to specify the directory.")
40+
errNotValidDestination = fmt.Errorf("can't find the directory in which to install the data-transfer plugin. Please ensure you're running this command on the machine on which Artifactory is installed. You can also use the --home-dir option to specify the directory")
4041
downloadConnectionErr = func(baseUrl, fileName, err string) error {
41-
return fmt.Errorf("Could not download the plugin file - '%s' from '%s' due to the following error: '%s'. If this machine has no network access to the download URL, you can download these files from another machine and place them in a directory on this machine. You can then run this command again with the --dir command option, with the directory containing the files as the value.", fileName, baseUrl, err)
42+
return fmt.Errorf("could not download the plugin file - '%s' from '%s' due to the following error: '%s'. If this machine has no network access to the download URL, you can download these files from another machine and place them in a directory on this machine. You can then run this command again with the --dir command option, with the directory containing the files as the value", fileName, baseUrl, err)
4243
}
4344
// Plugin files
4445
transferPluginFiles = PluginFiles{
@@ -222,7 +223,7 @@ func (idtp *InstallDataTransferPluginCommand) getPluginDirDestination() (target
222223
return
223224
}
224225
if !exists {
225-
err = notValidDestinationErr
226+
err = errNotValidDestination
226227
return
227228
}
228229
}
@@ -242,7 +243,7 @@ func (idtp *InstallDataTransferPluginCommand) getPluginDirDestination() (target
242243
}
243244
}
244245

245-
err = notValidDestinationErr
246+
err = errNotValidDestination
246247
return
247248
}
248249

artifactory/commands/transferinstall/datatransferinstall_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ package transferinstall
22

33
import (
44
"fmt"
5-
"github.com/jfrog/gofrog/version"
6-
commonTests "github.com/jfrog/jfrog-cli-core/v2/common/tests"
7-
"github.com/jfrog/jfrog-cli-core/v2/utils/tests"
8-
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
9-
testsutils "github.com/jfrog/jfrog-client-go/utils/tests"
10-
"github.com/stretchr/testify/assert"
115
"net/http"
126
"net/url"
137
"os"
@@ -17,6 +11,13 @@ import (
1711
"runtime"
1812
"strings"
1913
"testing"
14+
15+
"github.com/jfrog/gofrog/version"
16+
commonTests "github.com/jfrog/jfrog-cli-core/v2/common/tests"
17+
"github.com/jfrog/jfrog-cli-core/v2/utils/tests"
18+
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
19+
testsutils "github.com/jfrog/jfrog-client-go/utils/tests"
20+
"github.com/stretchr/testify/assert"
2021
)
2122

2223
func TestPluginFileItemNameAndDirs(t *testing.T) {
@@ -148,7 +149,7 @@ func TestGetPluginDirDestination(t *testing.T) {
148149
assert.NoError(t, err)
149150
assert.True(t, dst.toPath() == originalDirPath.toPath(defaultSearchPath) || (dst.toPath() == v7DirPath.toPath(defaultSearchPath)))
150151
} else {
151-
assert.Errorf(t, err, notValidDestinationErr.Error())
152+
assert.Errorf(t, err, errNotValidDestination.Error())
152153
}
153154

154155
// Env var override
@@ -164,7 +165,7 @@ func TestGetPluginDirDestination(t *testing.T) {
164165
assert.Equal(t, filepath.Join(testHomePath, testCustomDir, "confuse-"+artifactory, targetDir), dst.toPath())
165166
cmd.SetJFrogHomePath("not_existing_dir")
166167
_, err = cmd.getPluginDirDestination()
167-
assert.Errorf(t, err, notValidDestinationErr.Error())
168+
assert.Errorf(t, err, errNotValidDestination.Error())
168169
}
169170

170171
func TestGetTransferSourceAndAction(t *testing.T) {

artifactory/commands/utils/transferconfigbase_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,15 @@ func testDeactivateKeyEncryption(t *testing.T, wasEncrypted bool) {
255255
decrypted := false
256256
reactivated := false
257257
testServer, serverDetails, _ := commonTests.CreateRtRestsMockServer(t, func(w http.ResponseWriter, r *http.Request) {
258-
if r.RequestURI == "/api/system/decrypt" {
258+
switch r.RequestURI {
259+
case "/api/system/decrypt":
259260
if wasEncrypted {
260261
w.WriteHeader(http.StatusOK)
261262
} else {
262263
w.WriteHeader(http.StatusConflict)
263264
}
264265
decrypted = true
265-
} else if r.RequestURI == "/api/system/encrypt" {
266+
case "/api/system/encrypt":
266267
reactivated = true
267268
w.WriteHeader(http.StatusOK)
268269
}

artifactory/utils/commandsummary/buildinfosummary.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,11 @@ func appendBuildInfoRow(tableBuilder *strings.Builder, build *buildInfo.BuildInf
335335
if err != nil {
336336
return err
337337
}
338-
tableBuilder.WriteString(fmt.Sprintf("| [%s](%s) %s | %s | %s | \n", buildName, buildInfoUrl, appendSpacesToTableColumn(""), appendSpacesToTableColumn(buildScanResult.GetViolations()), appendSpacesToTableColumn(buildScanResult.GetVulnerabilities())))
338+
fmt.Fprintf(tableBuilder, "| [%s](%s) %s | %s | %s | \n", buildName, buildInfoUrl, appendSpacesToTableColumn(""), appendSpacesToTableColumn(buildScanResult.GetViolations()), appendSpacesToTableColumn(buildScanResult.GetVulnerabilities()))
339339
} else {
340340
upgradeMessage := fmt.Sprintf(basicSummaryUpgradeNotice, StaticMarkdownConfig.GetExtendedSummaryLangPage())
341341
buildName = fmt.Sprintf(" %s %s", upgradeMessage, buildName)
342-
tableBuilder.WriteString(fmt.Sprintf("| %s %s | %s | %s |\n", fitInsideMarkdownTable(buildName), appendSpacesToTableColumn(""), appendSpacesToTableColumn(buildScanResult.GetViolations()), appendSpacesToTableColumn(buildScanResult.GetVulnerabilities())))
342+
fmt.Fprintf(tableBuilder, "| %s %s | %s | %s |\n", fitInsideMarkdownTable(buildName), appendSpacesToTableColumn(""), appendSpacesToTableColumn(buildScanResult.GetViolations()), appendSpacesToTableColumn(buildScanResult.GetVulnerabilities()))
343343
}
344344
return nil
345345
}

0 commit comments

Comments
 (0)