This repository has been archived on 2019-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
mumbledj/commands/currenttrack_test.go

77 lines
2.2 KiB
Go
Raw Normal View History

2016-06-21 02:16:05 +02:00
/*
* MumbleDJ
* By Matthieu Grieger
* commands/currenttrack_test.go
* Copyright (c) 2016 Matthieu Grieger (MIT License)
*/
package commands
import (
2016-06-22 08:27:41 +02:00
"testing"
2016-06-21 02:16:05 +02:00
"github.com/layeh/gumble/gumbleffmpeg"
"github.com/matthieugrieger/mumbledj/bot"
"github.com/spf13/viper"
"github.com/stretchr/testify/suite"
)
type CurrentTrackCommandTestSuite struct {
Command CurrentTrackCommand
suite.Suite
}
func (suite *CurrentTrackCommandTestSuite) SetupSuite() {
DJ = bot.NewMumbleDJ()
// Trick the tests into thinking audio is already playing to avoid
// attempting to play tracks that don't exist.
DJ.AudioStream = new(gumbleffmpeg.Stream)
viper.Set("commands.currenttrack.aliases", []string{"currenttrack", "current"})
viper.Set("commands.currenttrack.description", "currenttrack")
viper.Set("commands.currenttrack.is_admin", false)
}
func (suite *CurrentTrackCommandTestSuite) SetupTest() {
DJ.Queue = bot.NewQueue()
}
func (suite *CurrentTrackCommandTestSuite) TestAliases() {
suite.Equal([]string{"currenttrack", "current"}, suite.Command.Aliases())
}
func (suite *CurrentTrackCommandTestSuite) TestDescription() {
suite.Equal("currenttrack", suite.Command.Description())
}
func (suite *CurrentTrackCommandTestSuite) TestIsAdminCommand() {
suite.False(suite.Command.IsAdminCommand())
}
func (suite *CurrentTrackCommandTestSuite) TestExecuteWhenQueueIsEmpty() {
message, isPrivateMessage, err := suite.Command.Execute(nil)
suite.Equal("", message, "No message should be returned since an error occurred.")
suite.True(isPrivateMessage, "This should be a private message.")
suite.NotNil(err, "An error should be returned since the queue is empty.")
}
func (suite *CurrentTrackCommandTestSuite) TestExecuteWhenQueueNotEmpty() {
track := new(bot.Track)
track.Submitter = "test"
track.Title = "test"
DJ.Queue.AppendTrack(track)
message, isPrivateMessage, err := suite.Command.Execute(nil)
suite.NotEqual("", message, "A message should be returned with the current track information.")
suite.True(isPrivateMessage, "This should be a private message.")
suite.Nil(err, "No error should be returned.")
}
2016-06-22 08:27:41 +02:00
func TestCurrentTrackCommandTestSuite(t *testing.T) {
suite.Run(t, new(CurrentTrackCommandTestSuite))
}