github.com/jfrog/jfrog-cli-core/v2@v2.51.0/artifactory/commands/transferconfigmerge/transferconfigmerge_test.go (about) 1 package transferconfigmerge 2 3 import ( 4 "github.com/jfrog/jfrog-client-go/access/services" 5 artifactoryServices "github.com/jfrog/jfrog-client-go/artifactory/services" 6 clientutils "github.com/jfrog/jfrog-client-go/utils" 7 "github.com/stretchr/testify/assert" 8 "strings" 9 "testing" 10 ) 11 12 const ( 13 quotaNumber = 1073741825 14 ) 15 16 func TestCreateAndValidateConflicts(t *testing.T) { 17 tests := []struct { 18 sameKey bool 19 sameName bool 20 sameDescription bool 21 sameAdmin bool 22 sameQuotaBytes bool 23 sameSoftLimit bool 24 expectedDiffCount int 25 }{ 26 {true, true, true, true, true, true, 0}, 27 {true, true, true, true, true, false, 1}, 28 {true, true, true, true, false, false, 2}, 29 {true, true, true, false, false, false, 3}, 30 {true, true, false, false, false, false, 4}, 31 {true, false, false, false, false, false, 5}, 32 {false, false, false, false, false, false, 6}, 33 } 34 for _, test := range tests { 35 source, target := createProjects(test.sameKey, test.sameName, test.sameDescription, test.sameAdmin, test.sameQuotaBytes, test.sameSoftLimit) 36 conflicts, err := compareProjects(source, target) 37 assert.NoError(t, err) 38 diffCount := 0 39 if conflicts != nil { 40 diffCount = len(strings.Split(conflicts.DifferentProperties, ";")) 41 } 42 assert.Equal(t, test.expectedDiffCount, diffCount) 43 } 44 } 45 46 func createProjects(sameKey, sameName, sameDescription, sameAdmin, sameQuotaBytes, sameSoftLimit bool) (source, target services.Project) { 47 sourceKey := "ProjectKey" 48 targetKey := sourceKey 49 sourceName := "ProjectName" 50 targetName := sourceName 51 sourceDescription := "ProjectDescription" 52 targetDescription := sourceDescription 53 sourceAdmin := &services.AdminPrivileges{} 54 targetAdmin := &services.AdminPrivileges{} 55 sourceQuotaBytes := float64(quotaNumber) 56 targetQuotaBytes := float64(quotaNumber) 57 if !sameKey { 58 targetKey = sourceKey + "Target" 59 } 60 if !sameName { 61 targetName = sourceName + "Target" 62 } 63 if !sameDescription { 64 targetDescription = sourceDescription + "Target" 65 } 66 if !sameAdmin { 67 targetAdmin.ManageMembers = clientutils.Pointer(true) 68 targetAdmin.IndexResources = clientutils.Pointer(true) 69 } 70 var sourceSoftLimit = clientutils.Pointer(false) 71 var targetSoftLimit = clientutils.Pointer(false) 72 73 if !sameSoftLimit { 74 targetSoftLimit = clientutils.Pointer(true) 75 } 76 if !sameQuotaBytes { 77 targetQuotaBytes += 125 78 } 79 source = services.Project{DisplayName: sourceName, Description: sourceDescription, AdminPrivileges: sourceAdmin, SoftLimit: sourceSoftLimit, StorageQuotaBytes: sourceQuotaBytes, ProjectKey: sourceKey} 80 target = services.Project{DisplayName: targetName, Description: targetDescription, AdminPrivileges: targetAdmin, SoftLimit: targetSoftLimit, StorageQuotaBytes: targetQuotaBytes, ProjectKey: targetKey} 81 return 82 } 83 84 func TestCompareInterfaces(t *testing.T) { 85 first := artifactoryServices.DockerRemoteRepositoryParams{} 86 first.RemoteRepositoryBaseParams = artifactoryServices.RemoteRepositoryBaseParams{Password: "ppppp"} 87 first.Key = "string1" 88 first.BlackedOut = clientutils.Pointer(true) 89 first.AssumedOfflinePeriodSecs = clientutils.Pointer(1111) 90 first.Environments = []string{"111", "aaa"} 91 first.ContentSynchronisation = &artifactoryServices.ContentSynchronisation{Enabled: clientutils.Pointer(true)} 92 93 second := artifactoryServices.DockerRemoteRepositoryParams{} 94 second.RemoteRepositoryBaseParams = artifactoryServices.RemoteRepositoryBaseParams{Password: "sssss"} 95 second.Key = "string2" 96 second.BlackedOut = clientutils.Pointer(false) 97 second.AssumedOfflinePeriodSecs = clientutils.Pointer(2222) 98 second.Environments = []string{"222", "bbb"} 99 second.ContentSynchronisation = &artifactoryServices.ContentSynchronisation{Enabled: clientutils.Pointer(false)} 100 101 diff, err := compareInterfaces(first, second, filteredRepoKeys...) 102 assert.NoError(t, err) 103 // Expect 5 differences (password should be filtered) 104 assert.Len(t, strings.Split(diff, ";"), 5) 105 }