Skip to content

Commit

Permalink
feat: add meeting_pool and user_pool optional flags on `init tena…
Browse files Browse the repository at this point in the history
…nt` command #72
  • Loading branch information
SLedunois committed Dec 27, 2022
1 parent 2f288ec commit a46a359
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/cmd/init/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func NewInitInstancesFlags() *InstancesFlags {
type TenantFlags struct {
Hostname string
Destination string
UserPool int64
MeetingPool int64
}

// NewInitTenantFlags initialize a new TenantFlags struct
Expand Down
10 changes: 10 additions & 0 deletions pkg/cmd/init/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func NewInitTenantCmd() *cobra.Command {
func (cmd *TenantCmd) ApplyFlags() {
cmd.Command.Flags().StringVarP(&cmd.Flags.Destination, "dest", "d", bbsconfig.DefaultConfigFolder, "File folder destination")
cmd.Command.Flags().StringVarP(&cmd.Flags.Hostname, "host", "", "", "Tenant hostname")
cmd.Command.Flags().Int64VarP(&cmd.Flags.MeetingPool, "meeting_pool", "", -1, "Tenant meeting pool. This means the tenant can't create more meetings than the configured meeting pool. -1 is ignored.")
cmd.Command.Flags().Int64VarP(&cmd.Flags.UserPool, "user_pool", "", -1, "Tenant user pool. This means the tenant can't have more users than the configured user pool. -1 is ignored.")
cmd.Command.MarkFlagRequired("host")
}

Expand All @@ -66,6 +68,14 @@ func (cmd *TenantCmd) init(command *cobra.Command, args []string) error {
Instances: []string{},
}

if cmd.Flags.MeetingPool != -1 {
tenant.Spec.MeetingsPool = &cmd.Flags.MeetingPool
}

if cmd.Flags.UserPool != -1 {
tenant.Spec.UserPool = &cmd.Flags.UserPool
}

if err := os.MkdirAll(cmd.Flags.Destination, fsRights); err != nil {
return fmt.Errorf("unable to create destination folder: %s", err.Error())
}
Expand Down
86 changes: 85 additions & 1 deletion pkg/cmd/init/tenant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,91 @@ func TestInitTenantCmd(t *testing.T) {

tests := []test.CmdTest{
{
Name: "a valid comment should init a new tenant file",
Name: "a valid command should init a new tenant file",
Args: []string{"--host", "localhost"},
Validator: func(t *testing.T, output *bytes.Buffer, err error) {
file := fmt.Sprintf("%s/.bigblueswarm/localhost.tenant.yml", homedir)
defer os.Remove(file)

b, err := os.ReadFile(file)
if err != nil {
t.Fatal(err)
return
}

var tenant bbsadmin.Tenant
if err := yaml.Unmarshal(b, &tenant); err != nil {
t.Fatal(err)
return
}

assert.Equal(t, "Tenant", tenant.Kind)
assert.Equal(t, "localhost", tenant.Spec.Host)
assert.Nil(t, tenant.Spec.MeetingsPool)
assert.Nil(t, tenant.Spec.UserPool)
assert.Equal(t, 0, len(tenant.Instances))
assert.Nil(t, err)
assert.Equal(t, fmt.Sprintf("tenant file successfully initialized. Please check %s/.bigblueswarm/localhost.tenant.yml file\n", homedir), string(output.Bytes()))
},
},
{
Name: "adding a meeting_pool flag should configure the tenant spec meeting pool configuration",
Args: []string{"--host", "localhost", "--meeting_pool", "10"},
Validator: func(t *testing.T, output *bytes.Buffer, err error) {
file := fmt.Sprintf("%s/.bigblueswarm/localhost.tenant.yml", homedir)
defer os.Remove(file)

b, err := os.ReadFile(file)
if err != nil {
t.Fatal(err)
return
}

var tenant bbsadmin.Tenant
if err := yaml.Unmarshal(b, &tenant); err != nil {
t.Fatal(err)
return
}

assert.Equal(t, "Tenant", tenant.Kind)
assert.Equal(t, "localhost", tenant.Spec.Host)
assert.Equal(t, int64(10), *tenant.Spec.MeetingsPool)
assert.Nil(t, tenant.Spec.UserPool)
assert.Equal(t, 0, len(tenant.Instances))
assert.Nil(t, err)
assert.Equal(t, fmt.Sprintf("tenant file successfully initialized. Please check %s/.bigblueswarm/localhost.tenant.yml file\n", homedir), string(output.Bytes()))
},
},
{
Name: "adding a user_pool flag should configure the tenant spec user pool configuration",
Args: []string{"--host", "localhost", "--user_pool", "100"},
Validator: func(t *testing.T, output *bytes.Buffer, err error) {
file := fmt.Sprintf("%s/.bigblueswarm/localhost.tenant.yml", homedir)
defer os.Remove(file)

b, err := os.ReadFile(file)
if err != nil {
t.Fatal(err)
return
}

var tenant bbsadmin.Tenant
if err := yaml.Unmarshal(b, &tenant); err != nil {
t.Fatal(err)
return
}

assert.Equal(t, "Tenant", tenant.Kind)
assert.Equal(t, "localhost", tenant.Spec.Host)
assert.Equal(t, int64(100), *tenant.Spec.UserPool)
assert.Nil(t, tenant.Spec.MeetingsPool)
assert.Equal(t, 0, len(tenant.Instances))
assert.Nil(t, err)
assert.Equal(t, fmt.Sprintf("tenant file successfully initialized. Please check %s/.bigblueswarm/localhost.tenant.yml file\n", homedir), string(output.Bytes()))
},
},
{
Name: "a valid command should init a new tenant file",
Args: []string{"--host", "localhost"},
Validator: func(t *testing.T, output *bytes.Buffer, err error) {
file := fmt.Sprintf("%s/.bigblueswarm/localhost.tenant.yml", homedir)
Expand Down

0 comments on commit a46a359

Please sign in to comment.