github.com/cobalt77/jfrog-client-go@v0.14.5/artifactory/services/utils/artifactoryutils_test.go (about)

     1  package utils
     2  
     3  import (
     4  	"path/filepath"
     5  	"testing"
     6  
     7  	"github.com/cobalt77/jfrog-client-go/utils"
     8  	"github.com/cobalt77/jfrog-client-go/utils/io/content"
     9  	"github.com/cobalt77/jfrog-client-go/utils/io/fileutils"
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestLoadMissingProperties(t *testing.T) {
    14  	oldMaxSize := utils.MaxBufferSize
    15  	defer func() { utils.MaxBufferSize = oldMaxSize }()
    16  	for i := 0; i < 2; i++ {
    17  		testDataPath, err := getBaseTestDir()
    18  		assert.NoError(t, err)
    19  		notSortedWithProps := content.NewContentReader(filepath.Join(testDataPath, "load_missing_props_nosorted_withprops.json"), content.DefaultKey)
    20  		sortedNoProps := content.NewContentReader(filepath.Join(testDataPath, "load_missing_props_sorted_noprops.json"), content.DefaultKey)
    21  		reader, err := loadMissingProperties(sortedNoProps, notSortedWithProps)
    22  		defer reader.Close()
    23  		assert.NoError(t, err)
    24  		isMatch, err := fileutils.FilesIdentical(reader.GetFilePath(), filepath.Join(testDataPath, "load_missing_props_expected_results.json"))
    25  		assert.NoError(t, err)
    26  		assert.True(t, isMatch)
    27  		utils.MaxBufferSize = 3
    28  	}
    29  	testDataPath, err := getBaseTestDir()
    30  	assert.NoError(t, err)
    31  	notSortedWithProps := content.NewContentReader(filepath.Join(testDataPath, "load_missing_props_nosorted_by_created_withprops.json"), content.DefaultKey)
    32  	sortedNoProps := content.NewContentReader(filepath.Join(testDataPath, "load_missing_props_sorted_by_created_noprops.json"), content.DefaultKey)
    33  	reader, err := loadMissingProperties(sortedNoProps, notSortedWithProps)
    34  	defer reader.Close()
    35  	assert.NoError(t, err)
    36  	isMatch, err := fileutils.FilesIdentical(reader.GetFilePath(), filepath.Join(testDataPath, "load_missing_props_by_created_expected_results.json"))
    37  	assert.NoError(t, err)
    38  	assert.True(t, isMatch)
    39  	utils.MaxBufferSize = 3
    40  }
    41  
    42  func TestFilterBuildAqlSearchResults(t *testing.T) {
    43  	testDataPath, err := getBaseTestDir()
    44  	assert.NoError(t, err)
    45  	resultsToFilter := content.NewContentReader(filepath.Join(testDataPath, "filter_build_aql_search.json"), content.DefaultKey)
    46  	buildArtifactsSha := map[string]int{"a": 2, "b": 2, "c": 2}
    47  	resultReader, err := filterBuildAqlSearchResults(resultsToFilter, buildArtifactsSha, "myBuild", "1")
    48  	defer resultReader.Close()
    49  	assert.NoError(t, err)
    50  	isMatch, err := fileutils.FilesIdentical(resultReader.GetFilePath(), filepath.Join(testDataPath, "filter_build_aql_search_expected.json"))
    51  	assert.NoError(t, err)
    52  	assert.True(t, isMatch)
    53  }