diff --git a/.env b/.env new file mode 100644 index 0000000..30f3f41 --- /dev/null +++ b/.env @@ -0,0 +1,6 @@ +# Env vars used to run integration tests with Telegram Bot API +TELEGRAM_TESTBOT_TOKEN= +TELEGRAM_SUPERGROUP_CHAT_ID= +TELEGRAM_CHANNEL= +TELEGRAM_CHAT_ID= +TELEGRAM_REPLY_TO_MESSAGE_ID= \ No newline at end of file diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml new file mode 100644 index 0000000..4a77490 --- /dev/null +++ b/.github/workflows/integration_tests.yml @@ -0,0 +1,36 @@ +name: Integration Tests + +on: + push: + branches: + - master + - develop + pull_request: + branches: + - master +jobs: + build: + name: Test + runs-on: ubuntu-latest + env: + TELEGRAM_TESTBOT_TOKEN=${{ secrets.TELEGRAM_TESTBOT_TOKEN }} + steps: + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: ^1.21 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: Build + run: go build -v . + + - name: Test + run: go test -coverprofile=coverage.out -covermode=atomic -v tests/. + + - name: Upload coverage report + uses: codecov/codecov-action@v1 + with: + file: ./coverage.out diff --git a/.github/workflows/test.yml b/.github/workflows/unit_tests.yml similarity index 92% rename from .github/workflows/test.yml rename to .github/workflows/unit_tests.yml index a94ff54..8e1550c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/unit_tests.yml @@ -1,4 +1,4 @@ -name: Test +name: Unit Tests on: push: diff --git a/bot_test.go b/bot_test.go index e67f69c..a9d1550 100644 --- a/bot_test.go +++ b/bot_test.go @@ -12,32 +12,12 @@ import ( ) const ( - TestToken = "153667468:AAHlSHlMqSt1f_uFmVRJbm5gntu2HI4WW8I" - ChatID = 76918703 - Channel = "@tgbotapitest" - SupergroupChatID = -1001120141283 - ReplyToMessageID = 35 - ExistingPhotoFileID = "AgACAgIAAxkDAAEBFUZhIALQ9pZN4BUe8ZSzUU_2foSo1AACnrMxG0BucEhezsBWOgcikQEAAwIAA20AAyAE" - ExistingDocumentFileID = "BQADAgADOQADjMcoCcioX1GrDvp3Ag" - ExistingAudioFileID = "BQADAgADRgADjMcoCdXg3lSIN49lAg" - ExistingVoiceFileID = "AwADAgADWQADjMcoCeul6r_q52IyAg" - ExistingVideoFileID = "BAADAgADZgADjMcoCav432kYe0FRAg" - ExistingVideoNoteFileID = "DQADAgADdQAD70cQSUK41dLsRMqfAg" - ExistingStickerFileID = "BQADAgADcwADjMcoCbdl-6eB--YPAg" + TestToken = "153667468:AAHlSHlMqSt1f_uFmVRJbm5gntu2HI4WW8I" + ChatID = 111 + SupergroupChatID = -1111 + ReplyToMessageID = 1 ) -type testLogger struct { - t *testing.T -} - -func (t testLogger) Println(v ...interface{}) { - t.t.Log(v...) -} - -func (t testLogger) Printf(format string, v ...interface{}) { - t.t.Logf(format, v...) -} - func prepareHttpClient(t *testing.T) *MockHTTPClient { ctrl := gomock.NewController(t) httpMock := NewMockHTTPClient(ctrl) diff --git a/tests/bot_integration_test.go b/tests/bot_integration_test.go index f21c691..ac0de31 100644 --- a/tests/bot_integration_test.go +++ b/tests/bot_integration_test.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" "os" + "strconv" "testing" "time" @@ -13,11 +14,6 @@ import ( ) const ( - TestToken = "6152026236:AAHccoTeFxTezeSceAOKRMZW_A5vaIFo4aI" - ChatID = 6064981043 - Channel = "@testapiintegration" - SupergroupChatID = -1002055786965 - ReplyToMessageID = 1 ExistingPhotoFileID = "AgACAgIAAxkDAAEBFUZhIALQ9pZN4BUe8ZSzUU_2foSo1AACnrMxG0BucEhezsBWOgcikQEAAwIAA20AAyAE" ExistingDocumentFileID = "BQADAgADOQADjMcoCcioX1GrDvp3Ag" ExistingAudioFileID = "BQADAgADRgADjMcoCdXg3lSIN49lAg" @@ -27,6 +23,32 @@ const ( ExistingStickerFileID = "BQADAgADcwADjMcoCbdl-6eB--YPAg" ) +var ( + TestToken string + Channel string + ChatID int64 + SupergroupChatID int64 + ReplyToMessageID int +) + +func init() { + var err error + TestToken = os.Getenv("TELEGRAM_TESTBOT_TOKEN") + SupergroupChatID, err = strconv.ParseInt(os.Getenv("TELEGRAM_SUPERGROUP_CHAT_ID"), 10, 64) + if err != nil { + panic(err) + } + Channel = os.Getenv("TELEGRAM_CHANNEL") + ChatID, err = strconv.ParseInt(os.Getenv("TELEGRAM_CHAT_ID"), 10, 64) + if err != nil { + panic(err) + } + ReplyToMessageID, err = strconv.Atoi(os.Getenv("TELEGRAM_REPLY_TO_MESSAGE_ID")) + if err != nil { + panic(err) + } +} + type testLogger struct { t *testing.T }