Skip to content

Commit

Permalink
Add troll_shield_test.go with simple test for getUserName
Browse files Browse the repository at this point in the history
The other functions is just too hard to mocking properly. I need
to refactor it later to make easier to test.

Currently, the most critical function that needs test it is
findTrollHouses.
  • Loading branch information
ryukinix committed Jul 24, 2020
1 parent f1478b0 commit 015f763
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions troll_shield_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"testing"

tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
)

func TestGetUserName(t *testing.T) {
user1 := tgbotapi.User{
FirstName: "Rolisvaldo",
}
if got := getUserName(user1); got != "Rolisvaldo" {
t.Errorf("getUserName when only FirstName is available should return it, not %v", got)
}

user2 := tgbotapi.User{
FirstName: "Rolisvaldo",
LastName: "Da Silva",
}
if got := getUserName(user2); got != "Rolisvaldo Da Silva" {
t.Errorf("getUserName when FirstName and LastName are available should return it, not %v", got)
}

user3 := tgbotapi.User{
FirstName: "Rolisvaldo",
LastName: "Da Silva",
UserName: "rolisvaldo",
}
if got := getUserName(user3); got != "@rolisvaldo" {
t.Errorf("getUserName when only UserName is available should return it with @, not %v", got)
}
}

0 comments on commit 015f763

Please sign in to comment.