Skip to content

Commit

Permalink
Add test for setupHiddenBot
Browse files Browse the repository at this point in the history
  • Loading branch information
ryukinix committed Jul 28, 2020
1 parent 1398ef0 commit 7acb3b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
26 changes: 14 additions & 12 deletions troll_shield.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,24 +196,26 @@ func setupBot(envVar string) (*telegram.BotAPI, error) {
return bot, nil
}

func setupBots() (*telegram.BotAPI, *telegram.BotAPI, error) {
var bot, botHidden *telegram.BotAPI
var err error

log.Println("Setup the main bot")
bot, err = setupBot("TELEGRAM_BOT_TOKEN")
if err != nil {
return nil, nil, err
}

func setupHiddenBot(bot *telegram.BotAPI) *telegram.BotAPI {
log.Println("Setup the hidden bot")
botHidden, err = setupBot("TELEGRAM_BOT_HIDDEN_TOKEN")
botHidden, err := setupBot("TELEGRAM_BOT_HIDDEN_TOKEN")
if err != nil {
log.Printf("Bot setup failed: %v. Fallback to main bot.", err)
botHidden = bot
}

return bot, botHidden, nil
return botHidden

}

func setupBots() (*telegram.BotAPI, *telegram.BotAPI, error) {
log.Println("Setup the main bot")
bot, err := setupBot("TELEGRAM_BOT_TOKEN")
if err != nil {
return nil, nil, err
}

return bot, setupHiddenBot(bot), nil
}

func leaveChat(bot TrollShieldBot, update *telegram.Update, trollGroup string) {
Expand Down
7 changes: 6 additions & 1 deletion troll_shield_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,14 @@ func TestSetupBot(t *testing.T) {
}

func TestSetupBots(t *testing.T) {
if _, _, err := setupBots(); err == nil {
bot, _, err := setupBots()
if err == nil {
t.Errorf("setupBots fail with invalid tokens.")
}
botHidden := setupHiddenBot(bot)
if botHidden != bot {
t.Errorf("When botHidden fails to start, use bot as fallback")
}
}

func TestSetupLogging(t *testing.T) {
Expand Down

0 comments on commit 7acb3b9

Please sign in to comment.