github.com/masterhung0112/hk_server/v5@v5.0.0-20220302090640-ec71aef15e1c/cmd/hkserver/commands/sampledata_test.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package commands
     5  
     6  import (
     7  	"io/ioutil"
     8  	"os"
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func TestSampledataBadParameters(t *testing.T) {
    15  	th := Setup(t).InitBasic()
    16  	defer th.TearDown()
    17  
    18  	t.Run("should fail because you need at least 1 worker", func(t *testing.T) {
    19  		require.Error(t, th.RunCommand(t, "sampledata", "--workers", "0"))
    20  	})
    21  
    22  	t.Run("should fail because you have more team memberships than teams", func(t *testing.T) {
    23  		require.Error(t, th.RunCommand(t, "sampledata", "--teams", "10", "--teams-memberships", "11"))
    24  	})
    25  
    26  	t.Run("should fail because you have more channel memberships than channels per team", func(t *testing.T) {
    27  		require.Error(t, th.RunCommand(t, "sampledata", "--channels-per-team", "10", "--channel-memberships", "11"))
    28  	})
    29  
    30  	t.Run("should fail because you have group channels and don't have enough users (6 users)", func(t *testing.T) {
    31  		require.Error(t, th.RunCommand(t, "sampledata", "--group-channels", "1", "--users", "5"))
    32  	})
    33  
    34  	t.Run("should not fail with less than 6 users and no group channels", func(t *testing.T) {
    35  		f, err := ioutil.TempFile("", "*")
    36  		require.NoError(t, err)
    37  		f.Close()
    38  		defer os.Remove(f.Name())
    39  		require.NoError(t, th.RunCommand(t, "sampledata", "--group-channels", "0", "--users", "5", "--bulk", f.Name()))
    40  	})
    41  
    42  	t.Run("should not fail with less than 6 users and no group channels", func(t *testing.T) {
    43  		f, err := ioutil.TempFile("", "*")
    44  		require.NoError(t, err)
    45  		f.Close()
    46  		defer os.Remove(f.Name())
    47  		require.NoError(t, th.RunCommand(t, "sampledata", "--group-channels", "0", "--users", "5", "--bulk", f.Name()))
    48  	})
    49  }