generated from parrogo/gomod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ccaddrepo_test.go
128 lines (114 loc) · 3.07 KB
/
ccaddrepo_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package ccaddrepo
import (
"embed"
"io/fs"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
//go:embed fixtures
var fixtureRootFS embed.FS
var fixtureFS, _ = fs.Sub(fixtureRootFS, "fixtures")
func TestPlaceHolder(t *testing.T) {
content, err := fs.ReadFile(fixtureFS, "placeholder")
if assert.NoError(t, err) {
assert.Equal(t, "this is a placeholder", string(content))
}
}
func TestSetReporterIDSecret(t *testing.T) {
cctoken, ok := os.LookupEnv("GH_WORKFLOW")
if !ok {
t.Fatalf("\nTO RUN THIS TEST, DECLARE A GH_WORKFLOW ENV VAR WITH A GITHUB API TOKEN\n")
}
err := SetReporterIDSecret(SecretsOptions{
RepoSlug: "parrogo/ccaddrepo",
GHToken: cctoken,
ReporterID: "42",
BadgeID: "43",
ID: "44",
})
if assert.NoError(t, err) {
assert.Equal(t, nil, err)
}
}
func TestGetRepoID(t *testing.T) {
cctoken, ok := os.LookupEnv("CC_TOKEN")
if !ok {
t.Fatalf("\nTO RUN THIS TEST, DECLARE A CC_TOKEN ENV VAR WITH A GITHUB API TOKEN\n")
}
cc := CodeClimate(cctoken)
t.Run("check this repo ID", func(t *testing.T) {
ID, err := cc.GetRepoID("parrogo/ccaddrepo")
if assert.NoError(t, err) {
assert.Equal(t, "606b6ca958f8666dcc00a693", ID)
}
})
}
func TestAddRepo(t *testing.T) {
cctoken, ok := os.LookupEnv("CC_TOKEN")
if !ok {
t.Fatalf("\nTO RUN THIS TEST, DECLARE A CC_TOKEN ENV VAR WITH A GITHUB API TOKEN\n")
}
cc := CodeClimate(cctoken)
t.Run("check centro", func(t *testing.T) {
ID, err := cc.GetRepoID("parrogo/centro")
if err == nil {
err = cc.DeleteRepo(ID)
if !assert.NoError(t, err) {
return
}
}
repo, err := cc.AddRepo("parrogo/centro")
if !assert.NoError(t, err) {
return
}
assert.Greater(t, len(repo.Data.ID), 10)
assert.Greater(t, len(repo.Data.Attributes.BadgeTokenID), 10)
assert.Greater(t, len(repo.Data.Attributes.TestReporterID), 10)
})
}
func TestDeleteRepo(t *testing.T) {
cctoken, ok := os.LookupEnv("CC_TOKEN")
if !ok {
t.Fatalf("\nTO RUN THIS TEST, DECLARE A CC_TOKEN ENV VAR WITH A GITHUB API TOKEN\n")
}
cc := CodeClimate(cctoken)
t.Run("check centro", func(t *testing.T) {
ID, err := cc.GetRepoID("parrogo/centro")
if err != nil && err.Error() == "repository not found: parrogo/centro" {
_, err := cc.AddRepo("parrogo/centro")
if !assert.NoError(t, err) {
return
}
}
if !assert.NoError(t, err) {
return
}
assert.NoError(t, cc.DeleteRepo(ID))
})
}
func TestGetOwnOrgID(t *testing.T) {
cctoken, ok := os.LookupEnv("CC_TOKEN")
if !ok {
t.Fatalf("\nTO RUN THIS TEST, DECLARE A CC_TOKEN ENV VAR WITH A GITHUB API TOKEN\n")
}
cc := CodeClimate(cctoken)
t.Run("check wrong org name", func(t *testing.T) {
ID, err := cc.GetOwnOrgID("nonexistentorg")
if assert.Error(t, err) {
assert.Equal(t, "", ID)
}
})
t.Run("check parrogo ID", func(t *testing.T) {
ID, err := cc.GetOwnOrgID("parrogo")
if assert.NoError(t, err) {
assert.Equal(t, "606ddb6085fc77593c001ec5", ID)
}
})
t.Run("check parro-it ID", func(t *testing.T) {
ID, err := cc.GetOwnOrgID("parro-it")
if assert.NoError(t, err) {
assert.Equal(t, "5610f3b56956806eff013739", ID)
}
})
}