-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbm_test.go
158 lines (133 loc) · 4.55 KB
/
bm_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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package main
import (
"fmt"
"os"
"strings"
"testing"
"time"
"github.com/gernest/mention"
"github.com/mvdan/xurls"
)
func TestTweetHashTag(t *testing.T) {
message := "how does it feel to be rejected? # it is #loner tt ggg sjdsj dj #linker"
tags := mention.GetTags('#', strings.NewReader(message))
fmt.Println(tags)
message2 := "hello @gernest I would like to @ follow you on twitter"
tags2 := mention.GetTags('@', strings.NewReader(message2))
fmt.Println(tags2)
message3 := "hello @gernest I would * like to #follow #go #ilike "
tags3 := mention.GetTags('#', strings.NewReader(message3))
content := mention.GetTags('*', strings.NewReader(message3))
fmt.Println("tag:", tags3)
fmt.Println("bo dy:", content)
}
func TestStringWebLink(t *testing.T) {
str1 := xurls.Relaxed.FindString("Do gophers live in golang.org?")
if str1 == "" {
t.Errorf("Cannot find string")
}
fmt.Println(str1)
// "golang.org"
str2 := xurls.Relaxed.FindAllString("foo.com is https://foo.com/.", -1)
if str2 == nil {
t.Errorf("Cannot find string")
}
fmt.Println(str2)
// ["foo.com", "http://foo.com/"]
str3 := xurls.Strict.FindAllString("foo.com is https://foo.com/.", -1)
if str3 == nil {
t.Errorf("Cannot find string")
}
fmt.Println(str3)
}
// TestIssueList :
func TestIssueList(t *testing.T) {
// You need get your github token from https://github.com/settings/tokens
token := os.Getenv("Token")
user := os.Getenv("User")
repo := os.Getenv("Repo")
if len(token) == 0 {
t.Skip("no token")
return
}
t.Log(token, user, repo)
testString := "Stateless datacenter load-balancing with Beamer | the morning paper https://t.co/0GFghfriwB"
bm := NewBookmark(user, repo, token)
err := bm.SaveBookmark(testString)
if err != nil {
t.Error(err)
}
}
// TestPostToBlog tests the PostToBlog function with a real GitHub API call.
func TestPostToBlog(t *testing.T) {
// Set up the BookmarkMgr with real token, user, and repo values.
// WARNING: Do not hardcode tokens in your code; this is for demonstration purposes only.
// Use environment variables or a secure method to handle tokens.
token := os.Getenv("GITHUB_TOKEN")
user := os.Getenv("User")
repo := os.Getenv("Repo")
if token == "" {
t.Skip("Skipping test because GITHUB_TOKEN is not set")
}
bm := NewBookmark(user, repo, token)
// Call the PostToBlog function with a number of days.
sinceTime := time.Now().Add(-3 * 24 * time.Hour) // Example: 3 days ago
shouldModifyLabels := false // Set to false if you do not want to modify labels
issues, err := bm.PostToBlog(sinceTime, shouldModifyLabels)
if err != nil {
// handle error
t.Error(err)
}
// process issues
// Here you could add more assertions, such as checking if the issues are within the last 7 days.
for _, issue := range issues {
t.Log("Title: ", *issue.Title, " issue time:", issue.CreatedAt)
t.Log("Body:", *issue.Body)
t.Log("issue link:", issue.GetHTMLURL())
}
}
// TestScrapeURL tests the scrapeURL function with a real API call.
func TestScrapeURL(t *testing.T) {
// Load environment variables.
fc_token := os.Getenv("FC_AUTH_TOKEN")
if fc_token == "" {
t.Skip("Skipping test because FC_AUTH_TOKEN is not set")
}
// Set up the URL to scrape.
url := "https://developers.googleblog.com/en/gemini-15-flash-updates-google-ai-studio-gemini-api/"
// Call the scrapeURL function.
resp, err := scrapeURL(url)
if err != nil {
t.Error(err)
}
// Print the response.
t.Log("Title:", resp.Data.Metadata.Title)
t.Log("Description:", resp.Data.Metadata.Description)
t.Log("Source URL:", resp.Data.Metadata.SourceURL)
t.Log("Content:", resp.Data.Content)
}
// TestGeminiCompleteScrapeUR with scrappeURL result.
func TestGeminiCompleteScrapeURL(t *testing.T) {
// Load environment variables.
fc_token := os.Getenv("FC_AUTH_TOKEN")
if fc_token == "" {
t.Skip("Skipping test because FC_AUTH_TOKEN is not set")
}
geminiKey = os.Getenv("GEMINI_API_KEY")
// Set geminiKey as global variable
if geminiKey == "" {
t.Skip("Skipping test because GEMINI_API_KEY is not set")
}
// Set up the URL to scrape.
url := "https://developers.googleblog.com/en/gemini-15-flash-updates-google-ai-studio-gemini-api/"
// Call the scrapeURL function.
resp, err := scrapeURL(url)
if err != nil {
t.Error(err)
}
//Promot
prompt := "Summary the markdown content and metadata from the URL, and return data as following: 原本通點是什麼? 本篇文章的創新? 未來發展方向? reply in zh-TW ----"
// Using Gemini
ret := GeminiChatComplete(prompt+"title="+resp.Data.Metadata.Title+"\n"+resp.Data.Markdown, false)
t.Log("ScapeRet:", ret)
}