Added some tests and fixed some others

This commit is contained in:
Matthieu Grieger 2016-06-21 23:27:41 -07:00
parent 9160c02bee
commit 8da1edf2b6
3 changed files with 48 additions and 2 deletions

View file

@ -8,6 +8,8 @@
package commands package commands
import ( import (
"testing"
"github.com/layeh/gumble/gumbleffmpeg" "github.com/layeh/gumble/gumbleffmpeg"
"github.com/matthieugrieger/mumbledj/bot" "github.com/matthieugrieger/mumbledj/bot"
"github.com/spf13/viper" "github.com/spf13/viper"
@ -68,3 +70,7 @@ func (suite *CurrentTrackCommandTestSuite) TestExecuteWhenQueueNotEmpty() {
suite.True(isPrivateMessage, "This should be a private message.") suite.True(isPrivateMessage, "This should be a private message.")
suite.Nil(err, "No error should be returned.") suite.Nil(err, "No error should be returned.")
} }
func TestCurrentTrackCommandTestSuite(t *testing.T) {
suite.Run(t, new(CurrentTrackCommandTestSuite))
}

View file

@ -10,6 +10,7 @@ package commands
import ( import (
"testing" "testing"
"github.com/layeh/gumble/gumble"
"github.com/matthieugrieger/mumbledj/bot" "github.com/matthieugrieger/mumbledj/bot"
"github.com/spf13/viper" "github.com/spf13/viper"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
@ -44,14 +45,34 @@ func (suite *HelpCommandTestSuite) TestIsAdminCommand() {
suite.False(suite.Command.IsAdminCommand()) suite.False(suite.Command.IsAdminCommand())
} }
// TODO: Implement this test.
func (suite *HelpCommandTestSuite) TestExecuteWhenPermissionsEnabledAndUserIsNotAdmin() { 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() { 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() { func (suite *HelpCommandTestSuite) TestExecuteWhenPermissionsDisabled() {

View file

@ -8,9 +8,11 @@
package commands package commands
import ( import (
"fmt"
"testing" "testing"
"github.com/layeh/gumble/gumble" "github.com/layeh/gumble/gumble"
"github.com/layeh/gumble/gumbleffmpeg"
"github.com/matthieugrieger/mumbledj/bot" "github.com/matthieugrieger/mumbledj/bot"
"github.com/spf13/viper" "github.com/spf13/viper"
"github.com/stretchr/testify/suite" "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.") 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() { func (suite *VolumeCommandTestSuite) TestExecuteWithArgOutOfRange() {
message, isPrivateMessage, err := suite.Command.Execute(nil, "1.4") message, isPrivateMessage, err := suite.Command.Execute(nil, "1.4")