github.com/jfrog/jfrog-cli-go@v1.22.1-0.20200318093948-4826ef344ffd/artifactory/utils/npm/packageInfo_test.go (about) 1 package npm 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func TestReadPackageInfoFromPackageJson(t *testing.T) { 9 tests := []struct { 10 json string 11 pi *PackageInfo 12 }{ 13 {`{ "name": "jfrog-cli-tests", "version": "1.0.0", "description": "test package"}`, 14 &PackageInfo{Name: "jfrog-cli-tests", Version: "1.0.0", Scope: ""}}, 15 {`{ "name": "@jfrog/jfrog-cli-tests", "version": "1.0.0", "description": "test package"}`, 16 &PackageInfo{Name: "jfrog-cli-tests", Version: "1.0.0", Scope: "@jfrog"}}, 17 } 18 for _, test := range tests { 19 t.Run(test.json, func(t *testing.T) { 20 packInfo, err := ReadPackageInfo([]byte(test.json)) 21 if err != nil { 22 t.Error("No error was expected in this test", err) 23 } 24 25 equals := reflect.DeepEqual(test.pi, packInfo) 26 if !equals { 27 t.Error("expected:", test.pi, "got:", packInfo) 28 } 29 }) 30 } 31 } 32 33 func TestGetDeployPath(t *testing.T) { 34 tests := []struct { 35 expectedPath string 36 pi *PackageInfo 37 }{ 38 {`jfrog-cli-tests/-/jfrog-cli-tests-1.0.0.tgz`, &PackageInfo{Name: "jfrog-cli-tests", Version: "1.0.0", Scope: ""}}, 39 {`@jfrog/jfrog-cli-tests/-/jfrog-cli-tests-1.0.0.tgz`, &PackageInfo{Name: "jfrog-cli-tests", Version: "1.0.0", Scope: "@jfrog"}}, 40 } 41 for _, test := range tests { 42 t.Run(test.expectedPath, func(t *testing.T) { 43 actualPath := test.pi.GetDeployPath() 44 if actualPath != test.expectedPath { 45 t.Error("expected:", test.expectedPath, "got:", actualPath) 46 } 47 }) 48 } 49 } 50 51 func TestGetExpectedPackedFileName(t *testing.T) { 52 tests := []struct { 53 fileName string 54 pi *PackageInfo 55 }{ 56 {`jfrog-cli-tests-1.0.0.tgz`, &PackageInfo{Name: "jfrog-cli-tests", Version: "1.0.0", Scope: ""}}, 57 {`jfrog-jfrog-cli-tests-1.0.0.tgz`, &PackageInfo{Name: "jfrog-cli-tests", Version: "1.0.0", Scope: "@jfrog"}}, 58 } 59 for _, test := range tests { 60 t.Run(test.fileName, func(t *testing.T) { 61 actualFileName := test.pi.GetExpectedPackedFileName() 62 if actualFileName != test.fileName { 63 t.Error("expected:", test.fileName, "got:", actualFileName) 64 } 65 }) 66 } 67 }