forked from EverythingSuckz/github-telegram-notify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD: unit test for commit message testing
- Loading branch information
1 parent
2b2602c
commit ce582cc
Showing
5 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"cSpell.words": [ | ||
"godotenv", | ||
"joho" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module github-telegram-notify | ||
|
||
go 1.18 | ||
|
||
require github.com/joho/godotenv v1.4.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= | ||
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"github-telegram-notify/types" | ||
"github-telegram-notify/utils" | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
|
||
dotenv "github.com/joho/godotenv" | ||
) | ||
|
||
func loadEnvs(t *testing.T) (string, string) { | ||
err := dotenv.Load() | ||
if err != nil { | ||
t.Fatal("Error loading .env file") | ||
} | ||
tg_token := os.Getenv("BOT_TOKEN") | ||
if tg_token == "" { | ||
t.Fatal("Bot token not specified in .env file") | ||
} | ||
chatID := os.Getenv("CHAT_ID") | ||
if chatID == "" { | ||
t.Fatal("Chat ID not specified in .env file") | ||
} | ||
return tg_token, chatID | ||
} | ||
|
||
func parse(t *testing.T, rawData []byte) (string, string, string) { | ||
var gitEvent *types.Metadata | ||
err := json.Unmarshal([]byte(rawData), &gitEvent) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
text, markupText, markupUrl, err := utils.CreateContents(gitEvent) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return text, markupText, markupUrl | ||
} | ||
|
||
func TestCommitMessage(t *testing.T) { | ||
token, chatID := loadEnvs(t) | ||
data, err := ioutil.ReadFile("events/commit.json") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
text, markupText, markupUrl := parse(t, data) | ||
error := utils.SendMessage(token, chatID, text, markupText, markupUrl) | ||
if error.Description != "" { | ||
t.Fatal(error.String()) | ||
} | ||
} |