Move sensitive credentials to the secrets

This commit is contained in:
Ilja Lapkovskis 2024-01-19 17:40:39 +02:00
parent 18ddf275ef
commit f6bd2d0113
No known key found for this signature in database
GPG key ID: 53D2AA4F0D1079C4
5 changed files with 74 additions and 30 deletions

6
.env Normal file
View file

@ -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=

36
.github/workflows/integration_tests.yml vendored Normal file
View file

@ -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

View file

@ -1,4 +1,4 @@
name: Test
name: Unit Tests
on:
push:

View file

@ -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)

View file

@ -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
}