package fetch

import (
	"testing"

	log "github.com/Sirupsen/logrus"

	"github.com/stretchr/testify/assert"
)

func TestFetchPublicKeys(t *testing.T) {
	log.SetLevel(log.DebugLevel)

	keys, err := GitHubKeys("devopsfinland", GithubFetchParams{PublicMembersOnly: true})

	assert.NoError(t, err, "Fetch GitHub keys returned error")
	assert.True(t, len(keys) > 0, "should return SSH at least one public key")
	assert.True(t, len(keys["ernoaapa"]) > 0, "should return ernoaapa public SSH key")
	assert.True(t, len(keys["ernoaapa"][0]) > 0, "should not return empty key for ernoaapa")
}

package fetch

import (
	"os"
	"testing"

	log "github.com/Sirupsen/logrus"

	"github.com/stretchr/testify/assert"
)

func TestFetchPublicKeys(t *testing.T) {
	log.SetLevel(log.DebugLevel)

	keys, err := GitHubKeys("devopsfinland", GithubFetchParams{
		// Use token if it's available to avoid hitting API rate limits with the tests...
		Token:             os.Getenv("GITHUB_TOKEN"),
		PublicMembersOnly: true,
	})

	assert.NoError(t, err, "Fetch GitHub keys returned error")
	assert.True(t, len(keys) > 0, "should return SSH at least one public key")
	assert.True(t, len(keys["ernoaapa"]) > 0, "should return ernoaapa public SSH key")
	assert.True(t, len(keys["ernoaapa"][0]) > 0, "should not return empty key for ernoaapa")
}

Use GITHUB_TOKEN in tests if available
Use GITHUB_TOKEN in tests if available

Previously we were running tests against Github API as unauthorized.
Problem is that we hit the API rate limits. So updated test to
use GITHUB_TOKEN if it's available and Travis we do have token.
