-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
68 lines (59 loc) · 1.47 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
package main
import (
"os"
"testing"
)
func TestFormatStarCount(t *testing.T) {
tests := []struct {
stars int
expected string
}{
{999, "999"},
{1000, "1k"},
{2501, "2.5k"},
{4708, "4.7k"},
{5038, "5k"},
{6100, "6.1k"},
{12000, "12k"},
{78456, "78k"},
}
for _, test := range tests {
result := formatStarCount(test.stars)
if result != test.expected {
t.Errorf("For %d stars, expected '%s' but got '%s'", test.stars, test.expected, result)
}
}
}
func TestRemoveStarsInfo(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"Project1 (⭐1k)", "Project1"},
{"Project2 (⭐1.5k)", "Project2"},
{"Project3", "Project3"},
}
for _, test := range tests {
output := removeStarsInfo(test.input)
if output != test.expected {
t.Errorf("Input: %s\nExpected: %s\nGot: %s", test.input, test.expected, output)
}
}
}
func TestGetAccessToken(t *testing.T) {
// Backup the existing environment variable and set a temporary one for the test
oldToken := os.Getenv("GITHUB_TOKEN")
os.Setenv("GITHUB_TOKEN", "test_token")
token := getAccessToken()
if token != "test_token" {
t.Errorf("Expected 'test_token', got '%s'", token)
}
// Restore the original environment variable
os.Setenv("GITHUB_TOKEN", oldToken)
}
func TestParseRepoName(t *testing.T) {
owner, repo := parseRepoName("google/go-github")
if owner != "google" || repo != "go-github" {
t.Errorf("Expected google and go-github, got %s and %s", owner, repo)
}
}