github.com/jfrog/jfrog-cli-core/v2@v2.52.0/utils/python/utils_test.go (about)

     1  package utils
     2  
     3  import (
     4  	"github.com/jfrog/jfrog-cli-core/v2/utils/config"
     5  	"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
     6  	"github.com/stretchr/testify/require"
     7  	"path/filepath"
     8  	"strings"
     9  	"testing"
    10  
    11  	"github.com/jfrog/jfrog-cli-core/v2/utils/tests"
    12  	"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
    13  	"github.com/stretchr/testify/assert"
    14  )
    15  
    16  func TestAddRepoToPyprojectFile(t *testing.T) {
    17  	poetryProjectPath, cleanUp := initPoetryTest(t)
    18  	defer cleanUp()
    19  	pyProjectPath := filepath.Join(poetryProjectPath, "pyproject.toml")
    20  	dummyRepoName := "test-repo-name"
    21  	dummyRepoURL := "https://ecosysjfrog.jfrog.io/"
    22  
    23  	err := addRepoToPyprojectFile(pyProjectPath, dummyRepoName, dummyRepoURL)
    24  	assert.NoError(t, err)
    25  	// Validate pyproject.toml file content
    26  	content, err := fileutils.ReadFile(pyProjectPath)
    27  	assert.NoError(t, err)
    28  	assert.Contains(t, string(content), dummyRepoURL)
    29  }
    30  
    31  func initPoetryTest(t *testing.T) (string, func()) {
    32  	// Create and change directory to test workspace
    33  	testAbs, err := filepath.Abs(filepath.Join("..", "..", "tests", "testdata", "poetry-project"))
    34  	assert.NoError(t, err)
    35  	poetryProjectPath, cleanUp := tests.CreateTestWorkspace(t, testAbs)
    36  	return poetryProjectPath, cleanUp
    37  }
    38  
    39  func TestGetPypiRepoUrlWithCredentials(t *testing.T) {
    40  	tests := []struct {
    41  		name        string
    42  		curationCmd bool
    43  	}{
    44  		{
    45  			name:        "test curation command true",
    46  			curationCmd: true,
    47  		},
    48  		{
    49  			name:        "test curation command false",
    50  			curationCmd: false,
    51  		},
    52  	}
    53  
    54  	for _, tt := range tests {
    55  		t.Run(tt.name, func(t *testing.T) {
    56  			url, _, _, err := GetPypiRepoUrlWithCredentials(&config.ServerDetails{}, "test", tt.curationCmd)
    57  			require.NoError(t, err)
    58  			assert.Equal(t, tt.curationCmd, strings.Contains(url.Path, coreutils.CurationPassThroughApi))
    59  		})
    60  	}
    61  }