github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/internal/registry/github_test.go (about) 1 package registry_test 2 3 import ( 4 "testing" 5 6 "github.com/heroku/color" 7 "github.com/sclevine/spec" 8 "github.com/sclevine/spec/report" 9 10 "github.com/buildpacks/pack/internal/registry" 11 h "github.com/buildpacks/pack/testhelpers" 12 ) 13 14 func TestGithub(t *testing.T) { 15 color.Disable(true) 16 defer color.Disable(false) 17 spec.Run(t, "Github", testGitHub, spec.Parallel(), spec.Report(report.Terminal{})) 18 } 19 20 func testGitHub(t *testing.T, when spec.G, it spec.S) { 21 when("#CreateBrowserCommand", func() { 22 it("should error when browser URL is invalid", func() { 23 _, err := registry.CreateBrowserCmd("", "linux") 24 h.AssertError(t, err, "invalid URL") 25 }) 26 27 it("should error when os is unsupported", func() { 28 _, err := registry.CreateBrowserCmd("https://url.com", "valinor") 29 h.AssertError(t, err, "unsupported platform 'valinor'") 30 }) 31 32 it("should work for linux", func() { 33 cmd, err := registry.CreateBrowserCmd("https://buildpacks.io", "linux") 34 h.AssertNil(t, err) 35 h.AssertEq(t, len(cmd.Args), 2) 36 h.AssertEq(t, cmd.Args[0], "xdg-open") 37 h.AssertEq(t, cmd.Args[1], "https://buildpacks.io") 38 }) 39 40 it("should work for darwin", func() { 41 cmd, err := registry.CreateBrowserCmd("https://buildpacks.io", "darwin") 42 h.AssertNil(t, err) 43 h.AssertEq(t, len(cmd.Args), 2) 44 h.AssertEq(t, cmd.Args[0], "open") 45 h.AssertEq(t, cmd.Args[1], "https://buildpacks.io") 46 }) 47 48 it("should work for windows", func() { 49 cmd, err := registry.CreateBrowserCmd("https://buildpacks.io", "windows") 50 h.AssertNil(t, err) 51 h.AssertEq(t, len(cmd.Args), 3) 52 h.AssertEq(t, cmd.Args[0], "rundll32") 53 h.AssertEq(t, cmd.Args[1], "url.dll,FileProtocolHandler") 54 h.AssertEq(t, cmd.Args[2], "https://buildpacks.io") 55 }) 56 }) 57 58 when("#GetIssueURL", func() { 59 it("should return an issueURL", func() { 60 url, err := registry.GetIssueURL("https://github.com/buildpacks") 61 62 h.AssertNil(t, err) 63 h.AssertEq(t, url.String(), "https://github.com/buildpacks/issues/new") 64 }) 65 66 it("should fail when url is empty", func() { 67 _, err := registry.GetIssueURL("") 68 69 h.AssertError(t, err, "missing github URL") 70 }) 71 }) 72 }