github.com/jfrog/jfrog-cli-core/v2@v2.51.0/artifactory/commands/transferconfig/configxmlutils/includerepos_test.go (about)

     1  package configxmlutils
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  var testCases = []struct {
    13  	expectedXml          string
    14  	includedRepositories []string
    15  	excludedRepositories []string
    16  }{
    17  	{"filter-all", []string{}, []string{"*"}},
    18  	{"select-local", []string{"default-libs-release-local"}, []string{}},
    19  	{"select-remote", []string{"default-maven-remote"}, []string{}},
    20  	{"select-release-bundle", []string{"release-bundles"}, []string{}},
    21  	{"select-one-from-all", []string{"default-libs-release-local", "default-maven-remote", "default-libs-release", "release-bundles"}, []string{}},
    22  	{"select-all", []string{"default-libs-release-local", "default-libs-snapshot-local", "default-maven-remote", "artifactory-build-info", "ecosys-build-info",
    23  		"ecosys-generic-local", "default-libs-release", "example-repo-local", "ecosys-npm-remote", "default-go-remote", "default-libs-snapshot", "release-bundles"}, []string{}},
    24  }
    25  
    26  func TestRemoveNonIncludedRepositories(t *testing.T) {
    27  	for _, testCase := range testCases {
    28  		includeExcludeFilter := &utils.IncludeExcludeFilter{
    29  			IncludePatterns: testCase.includedRepositories,
    30  			ExcludePatterns: testCase.excludedRepositories,
    31  		}
    32  		t.Run(testCase.expectedXml, func(t *testing.T) {
    33  			testCasesDir := filepath.Join("..", "..", "testdata", "config_xmls_exclude_repos")
    34  
    35  			// Read input artifactory.config.xml
    36  			inputConfigXmlPath := filepath.Join(testCasesDir, "input", "artifactory.config.xml")
    37  			inputConfigXml, err := os.ReadFile(inputConfigXmlPath)
    38  			assert.NoError(t, err)
    39  
    40  			// Read expected artifactory.config.xml
    41  			expectedConfigXmlPath := filepath.Join(testCasesDir, "cases", testCase.expectedXml+".xml")
    42  			expectedConfigXml, err := os.ReadFile(expectedConfigXmlPath)
    43  			assert.NoError(t, err)
    44  
    45  			// Run RemoveNonIncludedRepositories and compare
    46  			result, err := RemoveNonIncludedRepositories(string(inputConfigXml), includeExcludeFilter)
    47  			assert.NoError(t, err)
    48  			assert.Equal(t, string(expectedConfigXml), result)
    49  		})
    50  	}
    51  }