Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
65 lines (58 sloc) 2 KB
package importserver
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestGetPage(t *testing.T) {
pathToPage := map[string][]byte{
"foo": []byte("1"),
"bar": []byte("2"),
"foo.master": []byte("3"),
}
checkPage(t, pathToPage, "1", "foo")
checkPage(t, pathToPage, "2", "bar")
checkPage(t, pathToPage, "3", "foo.master")
checkPage(t, pathToPage, "1", "foo/bar")
checkPage(t, pathToPage, "2", "bar/bar")
checkPage(t, pathToPage, "3", "foo.master/foo")
}
func TestStandardGithubGoRedirect(t *testing.T) {
goRedirect := &GoRedirect{
VCS: "git",
URL: "hello.com/foo",
Repository: "https://github.com/alice/go-foo",
Images: []*Image{
{
URL: "https://circleci.com/gh/alice/go-foo/tree/master",
Source: "https://circleci.com/gh/alice/go-foo/tree/master.png",
},
{
URL: "http://goreportcard.com/report/hello.com/foo",
Source: "http://goreportcard.com/badge/hello.com/foo",
},
{
URL: "https://godoc.org/hello.com/foo",
Source: "http://img.shields.io/badge/GoDoc-Reference-blue.svg",
},
{
URL: "https://github.com/alice/go-foo/blob/master/LICENSE",
Source: "http://img.shields.io/badge/License-MIT-blue.svg",
},
},
}
require.Equal(t, StandardGithubGoRedirect("hello.com/foo", "alice", "go-foo"), goRedirect)
require.Equal(t, NewStandardGithubGoRedirectBuilder("hello.com", "alice").GoRedirect("foo", "go-foo"), goRedirect)
}
func TestStandardPrivateGithubGoRedirect(t *testing.T) {
goRedirect := &GoRedirect{
VCS: "git",
URL: "hello.com/foo",
Repository: "https://github.com/alice/go-foo",
Private: true,
}
require.Equal(t, StandardPrivateGithubGoRedirect("hello.com/foo", "alice", "go-foo"), goRedirect)
require.Equal(t, NewStandardGithubGoRedirectBuilder("hello.com", "alice").PrivateGoRedirect("foo", "go-foo"), goRedirect)
}
func checkPage(t *testing.T, pathToPage map[string][]byte, pageString string, path string) {
require.Equal(t, []byte(pageString), getPage(pathToPage, path))
}