Added some tests and fixed some others
This commit is contained in:
parent
9160c02bee
commit
8da1edf2b6
|
@ -8,6 +8,8 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/layeh/gumble/gumbleffmpeg"
|
||||
"github.com/matthieugrieger/mumbledj/bot"
|
||||
"github.com/spf13/viper"
|
||||
|
@ -68,3 +70,7 @@ func (suite *CurrentTrackCommandTestSuite) TestExecuteWhenQueueNotEmpty() {
|
|||
suite.True(isPrivateMessage, "This should be a private message.")
|
||||
suite.Nil(err, "No error should be returned.")
|
||||
}
|
||||
|
||||
func TestCurrentTrackCommandTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(CurrentTrackCommandTestSuite))
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ package commands
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/layeh/gumble/gumble"
|
||||
"github.com/matthieugrieger/mumbledj/bot"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
@ -44,14 +45,34 @@ func (suite *HelpCommandTestSuite) TestIsAdminCommand() {
|
|||
suite.False(suite.Command.IsAdminCommand())
|
||||
}
|
||||
|
||||
// TODO: Implement this test.
|
||||
func (suite *HelpCommandTestSuite) TestExecuteWhenPermissionsEnabledAndUserIsNotAdmin() {
|
||||
viper.Set("admins.names", []string{"SuperUser"})
|
||||
user := new(gumble.User)
|
||||
user.Name = "Test"
|
||||
|
||||
message, isPrivateMessage, err := suite.Command.Execute(user)
|
||||
|
||||
suite.NotEqual("", message, "A message should be returned.")
|
||||
suite.True(isPrivateMessage, "This should be a private message.")
|
||||
suite.Nil(err, "No error should be returned.")
|
||||
suite.Contains(message, "help", "The returned message should contain command descriptions.")
|
||||
suite.Contains(message, "add", "The returned message should contain command descriptions.")
|
||||
suite.NotContains(message, "Admin Commands", "The returned message should not contain admin command descriptions.")
|
||||
}
|
||||
|
||||
// TODO: Implement this test.
|
||||
func (suite *HelpCommandTestSuite) TestExecuteWhenPermissionsEnabledAndUserIsAdmin() {
|
||||
viper.Set("admins.names", []string{"SuperUser"})
|
||||
user := new(gumble.User)
|
||||
user.Name = "SuperUser"
|
||||
|
||||
message, isPrivateMessage, err := suite.Command.Execute(user)
|
||||
|
||||
suite.NotEqual("", message, "A message should be returned.")
|
||||
suite.True(isPrivateMessage, "This should be a private message.")
|
||||
suite.Nil(err, "No error should be returned.")
|
||||
suite.Contains(message, "help", "The returned message should contain command descriptions.")
|
||||
suite.Contains(message, "add", "The returned message should contain command descriptions.")
|
||||
suite.Contains(message, "Admin Commands", "The returned message should contain admin command descriptions.")
|
||||
}
|
||||
|
||||
func (suite *HelpCommandTestSuite) TestExecuteWhenPermissionsDisabled() {
|
||||
|
|
|
@ -8,9 +8,11 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/layeh/gumble/gumble"
|
||||
"github.com/layeh/gumble/gumbleffmpeg"
|
||||
"github.com/matthieugrieger/mumbledj/bot"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
@ -70,6 +72,23 @@ func (suite *VolumeCommandTestSuite) TestExecuteWithValidArg() {
|
|||
suite.Contains(message, "test", "The returned string should contain the username of whomever changed the volume.")
|
||||
}
|
||||
|
||||
func (suite *VolumeCommandTestSuite) TestExecuteWithValidArgAndNonNilStream() {
|
||||
dummyUser := &gumble.User{
|
||||
Name: "test",
|
||||
}
|
||||
DJ.AudioStream = new(gumbleffmpeg.Stream)
|
||||
DJ.AudioStream.Volume = 0.2
|
||||
|
||||
message, isPrivateMessage, err := suite.Command.Execute(dummyUser, "0.6")
|
||||
|
||||
suite.NotEqual("", message, "A message should be returned.")
|
||||
suite.False(isPrivateMessage, "This should not be a private message.")
|
||||
suite.Nil(err, "No error should be returned.")
|
||||
suite.Contains(message, "0.6", "The returned string should contain the new volume.")
|
||||
suite.Contains(message, "test", "The returned string should contain the username of whomever changed the volume.")
|
||||
suite.Equal("0.60", fmt.Sprintf("%.2f", DJ.AudioStream.Volume), "The audio stream value should match the new volume.")
|
||||
}
|
||||
|
||||
func (suite *VolumeCommandTestSuite) TestExecuteWithArgOutOfRange() {
|
||||
message, isPrivateMessage, err := suite.Command.Execute(nil, "1.4")
|
||||
|
||||
|
|
Reference in a new issue