github.com/joey-fossa/fossa-cli@v0.7.34-0.20190708193710-569f1e8679f0/api/fossa/locator_test.go (about) 1 package fossa_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/fossas/fossa-cli/api/fossa" 9 "github.com/fossas/fossa-cli/pkg" 10 ) 11 12 func TestLocatorFetcher(t *testing.T) { 13 testcases := []struct { 14 Type pkg.Type 15 Fetcher string 16 }{ 17 {pkg.Ant, "mvn"}, 18 {pkg.Bower, "bower"}, 19 {pkg.Cocoapods, "pod"}, 20 {pkg.Composer, "comp"}, 21 {pkg.Go, "go"}, 22 {pkg.Git, "git"}, 23 {pkg.Gradle, "mvn"}, 24 {pkg.Maven, "mvn"}, 25 {pkg.NodeJS, "npm"}, 26 {pkg.NuGet, "nuget"}, 27 {pkg.Python, "pip"}, 28 {pkg.Ruby, "gem"}, 29 {pkg.Scala, "mvn"}, 30 {pkg.Raw, "archive"}, 31 } 32 for _, tc := range testcases { 33 id := pkg.ID{ 34 Type: tc.Type, 35 } 36 assert.Equal(t, tc.Fetcher, fossa.LocatorOf(id).Fetcher, tc.Fetcher) 37 } 38 } 39 40 func TestStringGit(t *testing.T) { 41 ssh := fossa.Locator{ 42 Fetcher: "git", 43 Project: "git@github.com:fossas/fossa-cli.git", 44 Revision: "SHAVALUE", 45 } 46 47 http := fossa.Locator{ 48 Fetcher: "git", 49 Project: "http://github.com/fossas/fossa-cli.git", 50 Revision: "SHAVALUE", 51 } 52 53 sshActual := ssh.String() 54 httpActual := http.String() 55 expected := "git+github.com/fossas/fossa-cli$SHAVALUE" 56 assert.Equal(t, sshActual, expected) 57 assert.Equal(t, httpActual, expected) 58 } 59 60 func TestStringCustom(t *testing.T) { 61 fossa.MockOrgID = "3000" 62 custom := fossa.Locator{ 63 Fetcher: "custom", 64 Project: "fossa-cli", 65 Revision: "SHAVALUE", 66 } 67 68 customActual := custom.String() 69 expected := "custom+fossa-cli$SHAVALUE" 70 assert.Equal(t, customActual, expected) 71 } 72 73 func TestStringCustomGitHTTP(t *testing.T) { 74 http := fossa.Locator{ 75 Fetcher: "custom", 76 Project: "http://github.com/fossa/fossa-cli.git", 77 Revision: "SHAVALUE", 78 } 79 80 stringified := http.String() 81 expected := "custom+http://github.com/fossa/fossa-cli.git$SHAVALUE" 82 assert.Equal(t, stringified, expected) 83 } 84 85 func TestStringCustomGitSSH(t *testing.T) { 86 ssh := fossa.Locator{ 87 Fetcher: "custom", 88 Project: "git@github.com:fossa/fossa-cli.git", 89 Revision: "SHAVALUE", 90 } 91 92 stringified := ssh.String() 93 expected := "custom+git@github.com:fossa/fossa-cli.git$SHAVALUE" 94 assert.Equal(t, stringified, expected) 95 } 96 97 func TestOrgStringGit(t *testing.T) { 98 ssh := fossa.Locator{ 99 Fetcher: "git", 100 Project: "git@github.com:fossas/fossa-cli.git", 101 Revision: "SHAVALUE", 102 } 103 104 http := fossa.Locator{ 105 Fetcher: "git", 106 Project: "http://github.com/fossas/fossa-cli.git", 107 Revision: "SHAVALUE", 108 } 109 110 sshActual := ssh.OrgString() 111 httpActual := http.OrgString() 112 expected := "git+github.com/fossas/fossa-cli$SHAVALUE" 113 assert.Equal(t, sshActual, expected) 114 assert.Equal(t, httpActual, expected) 115 } 116 117 func TestOrgStringCustom(t *testing.T) { 118 fossa.MockOrgID = "3000" 119 git := fossa.Locator{ 120 Fetcher: "custom", 121 Project: "fossa-cli", 122 Revision: "SHAVALUE", 123 } 124 125 stringified := git.OrgString() 126 expected := "custom+3000/fossa-cli$SHAVALUE" 127 assert.Equal(t, stringified, expected) 128 } 129 130 func TestOrgStringCustomGitHTTP(t *testing.T) { 131 fossa.MockOrgID = "3000" 132 http := fossa.Locator{ 133 Fetcher: "custom", 134 Project: "http://github.com/fossa/fossa-cli.git", 135 Revision: "SHAVALUE", 136 } 137 138 stringified := http.OrgString() 139 expected := "custom+3000/github.com/fossa/fossa-cli$SHAVALUE" 140 assert.Equal(t, stringified, expected) 141 } 142 143 func TestOrgStringCustomGitSSH(t *testing.T) { 144 fossa.MockOrgID = "3000" 145 ssh := fossa.Locator{ 146 Fetcher: "custom", 147 Project: "git@github.com:fossa/fossa-cli.git", 148 Revision: "SHAVALUE", 149 } 150 151 stringified := ssh.OrgString() 152 expected := "custom+3000/git@github.com:fossa/fossa-cli.git$SHAVALUE" 153 assert.Equal(t, stringified, expected) 154 } 155 156 func TestURL(t *testing.T) { 157 git := fossa.Locator{ 158 Fetcher: "git", 159 Project: "git@github.com:fossas/fossa-cli.git", 160 Revision: "SHAVALUE", 161 } 162 163 stringified := git.URL() 164 expected := "https://app.fossa.com/projects/git+git@github.com:fossas%2Ffossa-cli.git/refs/branch/master/SHAVALUE" 165 assert.Equal(t, stringified, expected) 166 }