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/nexttrack_test.go

98 lines
2.8 KiB
Go
Raw Normal View History

2016-06-21 02:16:05 +02:00
/*
* MumbleDJ
* By Matthieu Grieger
* commands/nexttrack_test.go
* Copyright (c) 2016 Matthieu Grieger (MIT License)
*/
package commands
import (
"testing"
"github.com/layeh/gumble/gumbleffmpeg"
"github.com/matthieugrieger/mumbledj/bot"
"github.com/spf13/viper"
"github.com/stretchr/testify/suite"
)
type NextTrackCommandTestSuite struct {
Command NextTrackCommand
suite.Suite
}
func (suite *NextTrackCommandTestSuite) SetupSuite() {
DJ = bot.NewMumbleDJ()
bot.DJ = DJ
// 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.nexttrack.aliases", []string{"nexttrack", "next"})
viper.Set("commands.nexttrack.description", "nexttrack")
viper.Set("commands.nexttrack.is_admin", false)
}
func (suite *NextTrackCommandTestSuite) SetupTest() {
DJ.Queue = bot.NewQueue()
}
func (suite *NextTrackCommandTestSuite) TestAliases() {
suite.Equal([]string{"nexttrack", "next"}, suite.Command.Aliases())
}
func (suite *NextTrackCommandTestSuite) TestDescription() {
suite.Equal("nexttrack", suite.Command.Description())
}
func (suite *NextTrackCommandTestSuite) TestIsAdminCommand() {
suite.False(suite.Command.IsAdminCommand())
}
func (suite *NextTrackCommandTestSuite) TestExecuteWhenQueueIsEmpty() {
message, isPrivateMessage, err := suite.Command.Execute(nil)
suite.Equal("", message, "No message should be returned.")
suite.True(isPrivateMessage, "This should be a private message.")
suite.NotNil(err, "An error should be returned due to the queue being empty.")
}
func (suite *NextTrackCommandTestSuite) TestExecuteWhenQueueHasOneTrack() {
track := new(bot.Track)
track.Title = "test"
track.Submitter = "test"
DJ.Queue.AppendTrack(track)
message, isPrivateMessage, err := suite.Command.Execute(nil)
suite.Equal("", message, "No message should be returned.")
suite.True(isPrivateMessage, "This should be a private message.")
suite.NotNil(err, "An error should be returned due to the queue having only one track.")
}
func (suite *NextTrackCommandTestSuite) TestExecuteWhenQueueHasTwoOrMoreTracks() {
track1 := new(bot.Track)
track1.Title = "first"
track1.Submitter = "test"
track2 := new(bot.Track)
track2.Title = "second"
track2.Submitter = "test"
DJ.Queue.AppendTrack(track1)
DJ.Queue.AppendTrack(track2)
message, isPrivateMessage, err := suite.Command.Execute(nil)
suite.NotEqual("", "A message containing information for the next track should be returned.")
suite.Contains(message, "second", "The returned message should contain information about the second track in the queue.")
suite.True(isPrivateMessage, "This should be a private message.")
suite.Nil(err, "No error should be returned.")
}
func TestNextTrackCommandTestSuite(t *testing.T) {
suite.Run(t, new(NextTrackCommandTestSuite))
}