From 8da1edf2b62ce5cea8a2277dd2553e4a7f2cb220 Mon Sep 17 00:00:00 2001 From: Matthieu Grieger Date: Tue, 21 Jun 2016 23:27:41 -0700 Subject: [PATCH] Added some tests and fixed some others --- commands/currenttrack_test.go | 6 ++++++ commands/help_test.go | 25 +++++++++++++++++++++++-- commands/volume_test.go | 19 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/commands/currenttrack_test.go b/commands/currenttrack_test.go index 65bc6d3..5467a25 100644 --- a/commands/currenttrack_test.go +++ b/commands/currenttrack_test.go @@ -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)) +} diff --git a/commands/help_test.go b/commands/help_test.go index 4295087..1668b5e 100644 --- a/commands/help_test.go +++ b/commands/help_test.go @@ -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() { diff --git a/commands/volume_test.go b/commands/volume_test.go index ee041c2..7bcf17c 100644 --- a/commands/volume_test.go +++ b/commands/volume_test.go @@ -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")