Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mymmrac committed Oct 25, 2021
1 parent ddf4f26 commit 5f8bb1a
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 28 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ telegram.
- [ ] Unit testing of:
- [X] Core functionality
- [ ] Helper methods
- [ ] Methods
- [X] Methods
- [X] Types
- [ ] `New<Type>` helper funcs
- [ ] Add more examples
- [ ] Create Wiki page
- [ ] Publish stable version
Expand Down
4 changes: 4 additions & 0 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ func (t testNamedReade) Read(p []byte) (n int, err error) {
func (t testNamedReade) Name() string {
return "test"
}

var testInputFile = InputFile{
File: testNamedReade{},
}
186 changes: 186 additions & 0 deletions methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2325,3 +2325,189 @@ func TestBot_GetGameHighScores(t *testing.T) {
assert.Nil(t, gameHighScores)
})
}

func TestSetWebhookParams_fileParameters(t *testing.T) {
p := &SetWebhookParams{
Certificate: &testInputFile,
}

assert.Equal(t, map[string]api.NamedReader{
"certificate": testNamedReade{},
}, p.fileParameters())
}

func TestSendPhotoParams_fileParameters(t *testing.T) {
p := &SendPhotoParams{
Photo: testInputFile,
}

assert.Equal(t, map[string]api.NamedReader{
"photo": testNamedReade{},
}, p.fileParameters())
}

func TestSendAudioParams_fileParameters(t *testing.T) {
p := &SendAudioParams{
Audio: testInputFile,
Thumb: &testInputFile,
}

assert.Equal(t, map[string]api.NamedReader{
"audio": testNamedReade{},
"thumb": testNamedReade{},
}, p.fileParameters())
}

func TestSendDocumentParams_fileParameters(t *testing.T) {
p := &SendDocumentParams{
Document: testInputFile,
Thumb: &testInputFile,
}

assert.Equal(t, map[string]api.NamedReader{
"document": testNamedReade{},
"thumb": testNamedReade{},
}, p.fileParameters())
}

func TestSendVideoParams_fileParameters(t *testing.T) {
p := &SendVideoParams{
Video: testInputFile,
Thumb: &testInputFile,
}

assert.Equal(t, map[string]api.NamedReader{
"video": testNamedReade{},
"thumb": testNamedReade{},
}, p.fileParameters())
}

func TestSendAnimationParams_fileParameters(t *testing.T) {
p := &SendAnimationParams{
Animation: testInputFile,
Thumb: &testInputFile,
}

assert.Equal(t, map[string]api.NamedReader{
"animation": testNamedReade{},
"thumb": testNamedReade{},
}, p.fileParameters())
}

func TestSendVoiceParams_fileParameters(t *testing.T) {
p := &SendVoiceParams{
Voice: testInputFile,
}

assert.Equal(t, map[string]api.NamedReader{
"voice": testNamedReade{},
}, p.fileParameters())
}

func TestSendVideoNoteParams_fileParameters(t *testing.T) {
p := &SendVideoNoteParams{
VideoNote: testInputFile,
Thumb: &testInputFile,
}

assert.Equal(t, map[string]api.NamedReader{
"video_note": testNamedReade{},
"thumb": testNamedReade{},
}, p.fileParameters())
}

func TestSendMediaGroupParams_fileParameters(t *testing.T) {
p := &SendMediaGroupParams{
Media: []InputMedia{
&InputMediaDocument{
Media: testInputFile,
Thumb: &testInputFile,
},
&InputMediaVideo{
Media: testInputFile,
Thumb: &InputFile{File: nil},
},
},
}

assert.Equal(t, map[string]api.NamedReader{
"test": testNamedReade{},
}, p.fileParameters())
}

func TestSetChatPhotoParams_fileParameters(t *testing.T) {
p := &SetChatPhotoParams{
Photo: testInputFile,
}

assert.Equal(t, map[string]api.NamedReader{
"photo": testNamedReade{},
}, p.fileParameters())
}

func TestEditMessageMediaParams_fileParameters(t *testing.T) {
p := &EditMessageMediaParams{
Media: &InputMediaVideo{
Media: testInputFile,
Thumb: &InputFile{File: nil},
},
}

assert.Equal(t, map[string]api.NamedReader{
"test": testNamedReade{},
}, p.fileParameters())
}

func TestSendStickerParams_fileParameters(t *testing.T) {
p := &SendStickerParams{
Sticker: testInputFile,
}

assert.Equal(t, map[string]api.NamedReader{
"sticker": testNamedReade{},
}, p.fileParameters())
}

func TestUploadStickerFileParams_fileParameters(t *testing.T) {
p := &UploadStickerFileParams{
PngSticker: testInputFile,
}

assert.Equal(t, map[string]api.NamedReader{
"png_sticker": testNamedReade{},
}, p.fileParameters())
}

func TestCreateNewStickerSetParams_fileParameters(t *testing.T) {
p := &CreateNewStickerSetParams{
PngSticker: &testInputFile,
TgsSticker: &testInputFile,
}

assert.Equal(t, map[string]api.NamedReader{
"png_sticker": testNamedReade{},
"tgs_sticker": testNamedReade{},
}, p.fileParameters())
}

func TestAddStickerToSetParams_fileParameters(t *testing.T) {
p := &AddStickerToSetParams{
PngSticker: &testInputFile,
TgsSticker: &testInputFile,
}

assert.Equal(t, map[string]api.NamedReader{
"png_sticker": testNamedReade{},
"tgs_sticker": testNamedReade{},
}, p.fileParameters())
}

func TestSetStickerSetThumbParams_fileParameters(t *testing.T) {
p := &SetStickerSetThumbParams{
Thumb: &testInputFile,
}

assert.Equal(t, map[string]api.NamedReader{
"thumb": testNamedReade{},
}, p.fileParameters())
}
36 changes: 9 additions & 27 deletions types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,7 @@ func TestInputFile_MarshalJSON(t *testing.T) {

func TestInputMedia_fileParameters(t *testing.T) {
im := &InputMediaPhoto{
Media: InputFile{
File: testNamedReade{},
},
Media: testInputFile,
}

assert.Equal(t, map[string]api.NamedReader{
Expand All @@ -489,12 +487,8 @@ func TestInputMedia_fileParameters(t *testing.T) {

func TestInputMediaVideo_fileParameters(t *testing.T) {
im := &InputMediaVideo{
Media: InputFile{
File: testNamedReade{},
},
Thumb: &InputFile{
File: testNamedReade{},
},
Media: testInputFile,
Thumb: &testInputFile,
}

assert.Equal(t, map[string]api.NamedReader{
Expand All @@ -506,12 +500,8 @@ func TestInputMediaVideo_fileParameters(t *testing.T) {

func TestInputMediaAnimation_fileParameters(t *testing.T) {
im := &InputMediaAnimation{
Media: InputFile{
File: testNamedReade{},
},
Thumb: &InputFile{
File: testNamedReade{},
},
Media: testInputFile,
Thumb: &testInputFile,
}

assert.Equal(t, map[string]api.NamedReader{
Expand All @@ -523,12 +513,8 @@ func TestInputMediaAnimation_fileParameters(t *testing.T) {

func TestInputMediaAudio_fileParameters(t *testing.T) {
im := &InputMediaAudio{
Media: InputFile{
File: testNamedReade{},
},
Thumb: &InputFile{
File: testNamedReade{},
},
Media: testInputFile,
Thumb: &testInputFile,
}

assert.Equal(t, map[string]api.NamedReader{
Expand All @@ -540,12 +526,8 @@ func TestInputMediaAudio_fileParameters(t *testing.T) {

func TestInputMediaDocument_fileParameters(t *testing.T) {
im := &InputMediaDocument{
Media: InputFile{
File: testNamedReade{},
},
Thumb: &InputFile{
File: testNamedReade{},
},
Media: testInputFile,
Thumb: &testInputFile,
}

assert.Equal(t, map[string]api.NamedReader{
Expand Down

0 comments on commit 5f8bb1a

Please sign in to comment.