github.com/jfrog/jfrog-cli-core@v1.12.1/artifactory/utils/npm/pack_test.go (about)

     1  package npm
     2  
     3  import (
     4  	"github.com/stretchr/testify/assert"
     5  	"os"
     6  	"path/filepath"
     7  	"testing"
     8  )
     9  
    10  const testdataDir = "../testdata/npm/"
    11  
    12  func TestGetPackageFileNameFromOutput(t *testing.T) {
    13  	tests := []struct {
    14  		testName                string
    15  		outputTestDataFile      string
    16  		expectedPackageFilename string
    17  	}{
    18  		{"Get package filename for npm 6", "npmPackOutputV6", "npm-example-0.0.3.tgz"},
    19  		{"Get package filename for npm 7", "npmPackOutputV7", "npm-example-ver0.0.3.tgz"},
    20  	}
    21  	for _, test := range tests {
    22  		t.Run(test.testName, func(t *testing.T) {
    23  			output, err := os.ReadFile(filepath.Join(testdataDir, test.outputTestDataFile))
    24  			if err != nil {
    25  				assert.NoError(t, err)
    26  				return
    27  			}
    28  			actualFilename, err := getPackageFileNameFromOutput(string(output))
    29  			if err != nil {
    30  				assert.NoError(t, err)
    31  				return
    32  			}
    33  			assert.Equal(t, test.expectedPackageFilename, actualFilename)
    34  		})
    35  	}
    36  }