Exemplo n.º 1
0
func TestGetContribs(t *testing.T) {
	server := httptest.NewServer(
		http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			fmt.Fprint(w, contribs)
		}),
	)
	defer server.Close()

	cfg := libs.NewConfig()
	gh := libs.NewGithub(cfg)
	require.NotNil(t, gh)

	gh.DocGetter = func(c *libs.Config) (*goquery.Document, error) {
		return goquery.NewDocument(server.URL)
	}

	gc, err := gh.GetContribs()
	require.Nil(t, err)
	require.NotNil(t, gc)

	b, err := json.Marshal(gc)
	require.Nil(t, err)
	require.NotEmpty(t, b)

	var dst bytes.Buffer
	json.Indent(&dst, b, "", "  ")

	assert.Equal(t, githubContribs, dst.String())
}
Exemplo n.º 2
0
func TestGetRepos(t *testing.T) {
	mux := http.NewServeMux()
	server := httptest.NewServer(mux)
	defer server.Close()

	mux.HandleFunc("/user/repos", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprint(w, repos)
	})

	cfg := libs.NewConfig()
	cfg.Github.Username = "******"
	cfg.Github.Token = "xxx"

	gh := libs.NewGithub(cfg)
	require.NotNil(t, gh)

	gh.Client = github.NewClient(nil)
	require.NotNil(t, gh.Client)

	url, _ := url.Parse(server.URL)
	gh.Client.BaseURL = url

	gr, err := gh.GetRepos()
	require.Nil(t, err)
	require.NotNil(t, gr)

	b, err := json.Marshal(gr)
	require.Nil(t, err)
	require.NotEmpty(t, b)

	var dst bytes.Buffer
	json.Indent(&dst, b, "", "  ")

	assert.Equal(t, githubRepos, dst.String())
}
Exemplo n.º 3
0
func TestCreateApp(t *testing.T) {
	config := libs.NewConfig()
	config.Template.Path = "../"
	require.NotNil(t, config)

	app := libs.NewApp(config)
	assert.NotNil(t, app)
}
Exemplo n.º 4
0
func TestEmptyConfig(t *testing.T) {
	libs.NewConfig()
}