2016-06-21 02:16:05 +02:00
|
|
|
/*
|
|
|
|
* MumbleDJ
|
|
|
|
* By Matthieu Grieger
|
|
|
|
* Copyright (c) 2016 Matthieu Grieger (MIT License)
|
|
|
|
* commands/reset_test.go
|
|
|
|
*/
|
|
|
|
|
|
|
|
package commands
|
2018-07-21 01:39:53 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-07-21 02:13:20 +02:00
|
|
|
"github.com/layeh/gumble/gumble"
|
2018-07-21 01:39:53 +02:00
|
|
|
"github.com/layeh/gumble/gumbleffmpeg"
|
|
|
|
"github.com/matthieugrieger/mumbledj/bot"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ResetCommandTestSuite struct {
|
|
|
|
Command ResetCommand
|
|
|
|
suite.Suite
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *ResetCommandTestSuite) 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.reset.aliases", []string{"reset", "re"})
|
|
|
|
viper.Set("commands.reset.description", "Resets the queue by removing all queue items.")
|
|
|
|
viper.Set("commands.reset.is_admin", true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *ResetCommandTestSuite) SetupTest() {
|
|
|
|
DJ.Queue = bot.NewQueue()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *ResetCommandTestSuite) TestAliases() {
|
|
|
|
suite.Equal([]string{"reset", "re"}, suite.Command.Aliases())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *ResetCommandTestSuite) TestDescription() {
|
2018-07-21 02:13:20 +02:00
|
|
|
suite.Equal("Resets the queue by removing all queue items.", suite.Command.Description())
|
2018-07-21 01:39:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *ResetCommandTestSuite) TestIsAdminCommand() {
|
2018-07-21 02:13:20 +02:00
|
|
|
suite.True(suite.Command.IsAdminCommand())
|
2018-07-21 01:39:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *ResetCommandTestSuite) TestResetWorksOnEmpty() {
|
|
|
|
// TODO: Assuming the Queue is currently empty, is that the case?
|
2018-07-21 02:13:20 +02:00
|
|
|
suite.Command.Execute(new(gumble.User))
|
2018-07-21 01:39:53 +02:00
|
|
|
suite.Zero(DJ.Queue.Length())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *ResetCommandTestSuite) TestResetWorksOneTrack() {
|
|
|
|
track := new(bot.Track)
|
|
|
|
track.Submitter = "test"
|
|
|
|
track.Title = "test"
|
|
|
|
|
|
|
|
DJ.Queue.AppendTrack(track)
|
2018-07-21 02:13:20 +02:00
|
|
|
// If this is non-nil, an error will occur the stream is not valid.
|
|
|
|
DJ.AudioStream = nil
|
|
|
|
suite.Command.Execute(new(gumble.User))
|
2018-07-21 01:39:53 +02:00
|
|
|
suite.Zero(DJ.Queue.Length())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *ResetCommandTestSuite) TestResetWorksMultipleTracks() {
|
|
|
|
track1 := new(bot.Track)
|
|
|
|
track1.Submitter = "test"
|
|
|
|
track1.Title = "test"
|
|
|
|
track2 := new(bot.Track)
|
|
|
|
track2.Submitter = "test"
|
|
|
|
track2.Title = "test"
|
|
|
|
|
|
|
|
DJ.Queue.AppendTrack(track1)
|
|
|
|
DJ.Queue.AppendTrack(track2)
|
2018-07-21 02:13:20 +02:00
|
|
|
// If this is non-nil, an error will occur the stream is not valid.
|
|
|
|
DJ.AudioStream = nil
|
|
|
|
suite.Command.Execute(new(gumble.User))
|
2018-07-21 01:39:53 +02:00
|
|
|
suite.Zero(DJ.Queue.Length())
|
2018-07-21 02:13:20 +02:00
|
|
|
DJ.AudioStream = new(gumbleffmpeg.Stream)
|
2018-07-21 01:39:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestResetCommandTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(ResetCommandTestSuite))
|
|
|
|
}
|