github.com/osievert/jfrog-cli-core@v1.2.7/artifactory/utils/pip/setuppy_test.go (about)

     1  package pip
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestGetProjectNameFromFileContent(t *testing.T) {
     8  	tests := []struct {
     9  		fileContent         string
    10  		expectedProjectName string
    11  	}{
    12  		{"Metadata-Version: 1.0\nName: jfrog-python-example-1\nVersion: 1.0\nSummary: Project example for building Python project with JFrog products\nHome-page: https://github.com/jfrog/project-examples\nAuthor: JFrog\nAuthor-email: jfrog@jfrog.com\nLicense: UNKNOWN\nDescription: UNKNOWN\nPlatform: UNKNOWN", "jfrog-python-example-1"},
    13  		{"Metadata-Version: Name: jfrog-python-example-2\nLicense: UNKNOWN\nDescription: UNKNOWN\nPlatform: UNKNOWN\nName: jfrog-python-example-2\nVersion: 1.0\nSummary: Project example for building Python project with JFrog products\nHome-page: https://github.com/jfrog/project-examples\nAuthor: JFrog\nAuthor-email: jfrog@jfrog.com", "jfrog-python-example-2"},
    14  		{"Name:Metadata-Version: 3.0\nName: jfrog-python-example-3\nVersion: 1.0\nSummary: Project example for building Python project with JFrog products\nHome-page: https://github.com/jfrog/project-examples\nAuthor: JFrog\nAuthor-email: jfrog@jfrog.com\nName: jfrog-python-example-4", "jfrog-python-example-3"},
    15  	}
    16  
    17  	for _, test := range tests {
    18  		actualValue, err := getProjectNameFromFileContent([]byte(test.fileContent))
    19  		if err != nil {
    20  			t.Error(err)
    21  		}
    22  		if actualValue != test.expectedProjectName {
    23  			t.Errorf("Expected value: %s, got: %s.", test.expectedProjectName, actualValue)
    24  		}
    25  	}
    26  }
    27  
    28  func TestExtractPkginfoPathFromCommandOutput(t *testing.T) {
    29  	tests := []struct {
    30  		commandOutput       string
    31  		expectedPkginfoPath string
    32  		shouldFail          bool
    33  	}{
    34  		{"running egg_info\nwriting jfrog_python_example_unix.egg-info/PKG-INFO\nwriting dependency_links to jfrog_python_example.egg-info/dependency_links.txt\nwriting requirements to jfrog_python_example.egg-info/requires.txt\nwriting top-level names to jfrog_python_example.egg-info/top_level.txt\nreading manifest file 'jfrog_python_example.egg-info/SOURCES.txt'\nwriting manifest file 'jfrog_python_example.egg-info/SOURCES.txt'", "jfrog_python_example_unix.egg-info/PKG-INFO", false},
    35  		{"running egg_info\nwriting jfrog_python_example_windows.egg-info\\PKG-INFO\nwriting dependency_links to jfrog_python_example.egg-info\\dependency_links.txt\nwriting requirements to jfrog_python_example.egg-info\\requires.txt\nwriting top-level names to jfrog_python_example.egg-info\\top_level.txt\nreading manifest file 'jfrog_python_example.egg-info\\SOURCES.txt'\nwriting manifest file 'jfrog_python_example.egg-info\\SOURCES.txt'", "jfrog_python_example_windows.egg-info\\PKG-INFO", false},
    36  		{"running egg_info\nwriting dependency_links to jfrog_python_example.egg-info/dependency_links.txt\nwriting requirements to jfrog_python_example.egg-info/requires.txt\nwriting top-level names to jfrog_python_example.egg-info/top_level.txt\nreading manifest file 'jfrog_python_example.egg-info/SOURCES.txt'\nwriting manifest file 'jfrog_python_example.egg-info/SOURCES.txt'", "jfrog_python_example_unix.egg-info/PKG-INFO", true},
    37  	}
    38  
    39  	for i, test := range tests {
    40  		actualValue, err := extractPkginfoPathFromCommandOutput(test.commandOutput)
    41  		if err != nil {
    42  			if !test.shouldFail {
    43  				t.Errorf("Test case %d - %s", i, err)
    44  			}
    45  			continue
    46  		}
    47  		if actualValue != test.expectedPkginfoPath {
    48  			t.Errorf("Test case %d - Expected value: %s, got: %s.", i, test.expectedPkginfoPath, actualValue)
    49  		}
    50  	}
    51  }