Restrict the sampledata generation to not run without enough users for group channels (#15275)
* Restrict the sampledata generation to not run without enough users for group channels * Adding test cases
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3d8a87029c
Коммит
f16fb6f855
@@ -240,6 +240,10 @@ func sampleDataCmdF(command *cobra.Command, args []string) error {
|
|||||||
return errors.New("You can't have more channel memberships than channels per team.")
|
return errors.New("You can't have more channel memberships than channels per team.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if users < 6 && groupChannels > 0 {
|
||||||
|
return errors.New("You can't have group channels generation with less than 6 users. Use --group-channels 0 or increase the number of users.")
|
||||||
|
}
|
||||||
|
|
||||||
var bulkFile *os.File
|
var bulkFile *os.File
|
||||||
switch bulk {
|
switch bulk {
|
||||||
case "":
|
case "":
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -13,12 +15,35 @@ func TestSampledataBadParameters(t *testing.T) {
|
|||||||
th := Setup(t).InitBasic()
|
th := Setup(t).InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
// should fail because you need at least 1 worker
|
t.Run("should fail because you need at least 1 worker", func(t *testing.T) {
|
||||||
require.Error(t, th.RunCommand(t, "sampledata", "--workers", "0"))
|
require.Error(t, th.RunCommand(t, "sampledata", "--workers", "0"))
|
||||||
|
})
|
||||||
|
|
||||||
// should fail because you have more team memberships than teams
|
t.Run("should fail because you have more team memberships than teams", func(t *testing.T) {
|
||||||
require.Error(t, th.RunCommand(t, "sampledata", "--teams", "10", "--teams-memberships", "11"))
|
require.Error(t, th.RunCommand(t, "sampledata", "--teams", "10", "--teams-memberships", "11"))
|
||||||
|
})
|
||||||
|
|
||||||
// should fail because you have more channel memberships than channels per team
|
t.Run("should fail because you have more channel memberships than channels per team", func(t *testing.T) {
|
||||||
require.Error(t, th.RunCommand(t, "sampledata", "--channels-per-team", "10", "--channel-memberships", "11"))
|
require.Error(t, th.RunCommand(t, "sampledata", "--channels-per-team", "10", "--channel-memberships", "11"))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("should fail because you have group channels and don't have enough users (6 users)", func(t *testing.T) {
|
||||||
|
require.Error(t, th.RunCommand(t, "sampledata", "--group-channels", "1", "--users", "5"))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("should not fail with less than 6 users and no group channels", func(t *testing.T) {
|
||||||
|
f, err := ioutil.TempFile("", "*")
|
||||||
|
require.Nil(t, err)
|
||||||
|
f.Close()
|
||||||
|
defer os.Remove(f.Name())
|
||||||
|
require.NoError(t, th.RunCommand(t, "sampledata", "--group-channels", "0", "--users", "5", "--bulk", f.Name()))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("should not fail with less than 6 users and no group channels", func(t *testing.T) {
|
||||||
|
f, err := ioutil.TempFile("", "*")
|
||||||
|
require.Nil(t, err)
|
||||||
|
f.Close()
|
||||||
|
defer os.Remove(f.Name())
|
||||||
|
require.NoError(t, th.RunCommand(t, "sampledata", "--group-channels", "0", "--users", "5", "--bulk", f.Name()))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user