-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathartifactorystorage_test.go
139 lines (124 loc) · 4.45 KB
/
artifactorystorage_test.go
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
package tests
import (
"errors"
"path"
"strings"
"testing"
"time"
"github.com/jfrog/jfrog-client-go/artifactory/services"
servicesutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
"github.com/jfrog/jfrog-client-go/utils"
"github.com/stretchr/testify/assert"
)
func TestArtifactoryStorage(t *testing.T) {
initArtifactoryTest(t)
uploadDummyFile(t)
t.Run("folder info test", folderInfoTest)
t.Run("file info test", fileInfoTest)
t.Run("file list test", fileListTest)
t.Run("storage info test", storageInfoTest)
artifactoryCleanup(t)
}
func folderInfoTest(t *testing.T) {
info, err := testsStorageService.FolderInfo(getRtTargetRepo() + "test/")
if !assert.NoError(t, err) {
return
}
assert.Equal(t, utils.AddTrailingSlashIfNeeded(*RtUrl)+path.Join(services.StorageRestApi, getRtTargetRepo()+"test/"), info.Uri)
assert.Equal(t, strings.TrimSuffix(getRtTargetRepo(), "/"), info.Repo)
assert.Equal(t, "/test", info.Path)
assert.NotEmpty(t, info.Created)
assert.NotEmpty(t, info.CreatedBy)
assert.NotEmpty(t, info.LastModified)
assert.NotEmpty(t, info.LastUpdated)
assert.Len(t, info.Children, 1)
assert.Equal(t, "/a.in", info.Children[0].Uri)
assert.False(t, info.Children[0].Folder)
}
func fileInfoTest(t *testing.T) {
info, err := testsStorageService.FileInfo(getRtTargetRepo() + "test/a.in")
if !assert.NoError(t, err) {
return
}
assert.Equal(t, utils.AddTrailingSlashIfNeeded(*RtUrl)+path.Join(services.StorageRestApi, getRtTargetRepo()+"test/a.in"), info.Uri)
assert.Equal(t, strings.TrimSuffix(getRtTargetRepo(), "/"), info.Repo)
assert.Equal(t, "/test/a.in", info.Path)
assert.NotEmpty(t, info.Created)
assert.NotEmpty(t, info.CreatedBy)
assert.NotEmpty(t, info.LastModified)
assert.NotEmpty(t, info.LastUpdated)
}
func fileListTest(t *testing.T) {
params := servicesutils.NewFileListParams()
params.Deep = true
params.Depth = 2
params.ListFolders = true
params.MetadataTimestamps = true
params.IncludeRootPath = true
fileList, err := testsStorageService.FileList(getRtTargetRepo(), params)
if !assert.NoError(t, err) {
return
}
assert.Equal(t, utils.AddTrailingSlashIfNeeded(*RtUrl)+path.Join(services.StorageRestApi, getRtTargetRepo()), fileList.Uri)
assert.NotEmpty(t, fileList.Created)
assert.Len(t, fileList.Files, 5)
for _, file := range fileList.Files {
if strings.HasSuffix(file.Uri, "a.in") {
assert.Equal(t, "/test/a.in", file.Uri)
assert.NotEmpty(t, file.Size)
assert.NotEmpty(t, file.LastModified)
assert.False(t, file.Folder)
assert.NotEmpty(t, file.Sha1)
assert.NotEmpty(t, file.Sha2)
assert.NotEmpty(t, file.MetadataTimestamps.Properties)
return
}
}
assert.Fail(t, "could not find the expected dummy file")
}
func storageInfoTest(t *testing.T) {
err := testsStorageService.StorageInfoRefresh()
if !assert.NoError(t, err) {
return
}
info, err := waitForRepoInStorageInfo(testsStorageService, getRtTargetRepoKey(), 5)
if !assert.NoError(t, err) {
return
}
assert.NotEmpty(t, info.BinariesCount)
assert.NotEmpty(t, info.BinariesSize)
assert.NotEmpty(t, info.ArtifactsSize)
assert.NotEmpty(t, info.Optimization)
assert.NotEmpty(t, info.ItemsCount)
assert.NotEmpty(t, info.ArtifactsCount)
assert.NotEmpty(t, info.StorageType)
assert.NotEmpty(t, info.StorageDirectory)
for _, repoSummary := range info.RepositoriesSummaryList {
if repoSummary.RepoKey == getRtTargetRepoKey() {
assert.NotEmpty(t, repoSummary.RepoType)
assert.NotEmpty(t, repoSummary.FoldersCount)
assert.NotEmpty(t, repoSummary.FilesCount)
assert.NotEmpty(t, repoSummary.UsedSpace)
assert.NotEmpty(t, repoSummary.UsedSpaceInBytes)
assert.NotEmpty(t, repoSummary.ItemsCount)
assert.NotEmpty(t, repoSummary.PackageType)
assert.NotEmpty(t, repoSummary.ProjectKey)
assert.NotEmpty(t, repoSummary.Percentage)
return
}
}
assert.Fail(t, "could not find the summary of repo '"+getRtTargetRepoKey()+"' in the storage info")
}
func waitForRepoInStorageInfo(testsStorageService *services.StorageService, repositoryKey string, timeoutInSeconds int) (*servicesutils.StorageInfo, error) {
for i := 0; i < timeoutInSeconds; i++ {
storageInfo, err := testsStorageService.StorageInfo()
if err != nil {
return nil, err
}
if _, err := storageInfo.FindRepositoryWithKey(repositoryKey); err == nil {
return storageInfo, nil
}
time.Sleep(1 * time.Second)
}
return nil, errors.New("Failed to find a repositoryKey with the key " + repositoryKey + " within " + string(rune(timeoutInSeconds)) + " seconds")
}