-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
80 lines (67 loc) · 1.61 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"errors"
"io/ioutil"
"log"
"path"
"strings"
"testing"
"github.com/adamliesko/go-thanks/discover"
"github.com/adamliesko/go-thanks/thank"
)
const goodAPIToken = "pass123"
func init() {
log.SetOutput(ioutil.Discard)
}
func TestThankingTheGiants(t *testing.T) {
*projectPath = path.Join("discover", "test", "project_dep")
ft := &FakeGithubThanker{
apiToken: goodAPIToken,
thanked: map[string]bool{},
}
err := thankGiants([]thank.Thanker{ft}, *projectPath)
if err != nil {
t.Fatal(err)
}
if len(ft.thanked) != 3 {
t.Errorf("bad thanked count, got %d want %d", len(ft.thanked), 3)
}
}
func TestThankingTheGiantsWithBadTokenFails(t *testing.T) {
*projectPath = path.Join("discover", "test", "project_dep")
ft := &FakeGithubThanker{
apiToken: "bad-token",
thanked: map[string]bool{},
}
err := thankGiants([]thank.Thanker{ft}, *projectPath)
if err == nil {
t.Fatal(err)
}
if len(ft.thanked) != 0 {
t.Errorf("bad thanked count, got %d want %d", len(ft.thanked), 0)
}
}
func TestRunnerReturnsErrorIfNoThankerAuthenticated(t *testing.T) {
*projectPath = path.Join("discover", "test", "project_dep")
err := run()
if err == nil {
t.Fatal(err)
}
}
type FakeGithubThanker struct {
apiToken string
thanked map[string]bool
}
func (ft *FakeGithubThanker) CanThank(r discover.Repository) bool {
return strings.HasPrefix(r.URL, "github.com")
}
func (ft *FakeGithubThanker) Thank(r discover.Repository) error {
ft.thanked[r.URL] = true
return nil
}
func (ft *FakeGithubThanker) Auth() error {
if ft.apiToken == goodAPIToken {
return nil
}
return errors.New("bad auth")
}