Set defaults to 0

This commit is contained in:
Nils Hanke 2022-05-04 18:41:24 +02:00 committed by Thomas Tendyck
parent bbfd84729d
commit 4459766b58
2 changed files with 85 additions and 61 deletions

View File

@ -31,9 +31,9 @@ func newCreateCmd() *cobra.Command {
}
cmd.Flags().String("name", "constell", "create the cluster with the specified name")
cmd.Flags().BoolP("yes", "y", false, "create the cluster without further confirmation")
cmd.Flags().IntP("control-plane-nodes", "c", 1, "number of control-plane nodes (required)")
cmd.Flags().IntP("control-plane-nodes", "c", 0, "number of control-plane nodes (required)")
must(cobra.MarkFlagRequired(cmd.Flags(), "control-plane-nodes"))
cmd.Flags().IntP("worker-nodes", "w", 1, "number of worker nodes (required)")
cmd.Flags().IntP("worker-nodes", "w", 0, "number of worker nodes (required)")
must(cobra.MarkFlagRequired(cmd.Flags(), "worker-nodes"))
cmd.Flags().StringP("instance-type", "t", "", "instance type of cluster nodes")
must(cmd.RegisterFlagCompletionFunc("instance-type", instanceTypeCompletion))

View File

@ -3,7 +3,7 @@ package cmd
import (
"bytes"
"errors"
"fmt"
"strconv"
"strings"
"testing"
@ -67,18 +67,24 @@ func TestCreate(t *testing.T) {
setupFs: func(require *require.Assertions) afero.Fs { return afero.NewMemMapFs() },
creator: &stubCloudCreator{state: testState},
provider: cloudprovider.GCP,
controllerCountFlag: intPtr(1),
workerCountFlag: intPtr(2),
yesFlag: true,
},
"interactive": {
setupFs: func(require *require.Assertions) afero.Fs { return afero.NewMemMapFs() },
creator: &stubCloudCreator{state: testState},
provider: cloudprovider.Azure,
controllerCountFlag: intPtr(2),
workerCountFlag: intPtr(1),
stdin: "yes\n",
},
"interactive abort": {
setupFs: func(require *require.Assertions) afero.Fs { return afero.NewMemMapFs() },
creator: &stubCloudCreator{},
provider: cloudprovider.GCP,
controllerCountFlag: intPtr(1),
workerCountFlag: intPtr(1),
stdin: "no\n",
wantAbbort: true,
},
@ -86,6 +92,8 @@ func TestCreate(t *testing.T) {
setupFs: func(require *require.Assertions) afero.Fs { return afero.NewMemMapFs() },
creator: &stubCloudCreator{},
provider: cloudprovider.GCP,
controllerCountFlag: intPtr(1),
workerCountFlag: intPtr(1),
stdin: "foo\nfoo\nfoo\n",
wantErr: true,
},
@ -93,6 +101,8 @@ func TestCreate(t *testing.T) {
setupFs: func(require *require.Assertions) afero.Fs { return afero.NewMemMapFs() },
creator: &stubCloudCreator{},
provider: cloudprovider.GCP,
controllerCountFlag: intPtr(1),
workerCountFlag: intPtr(1),
nameFlag: strings.Repeat("a", constellationNameLength+1),
wantErr: true,
},
@ -109,7 +119,7 @@ func TestCreate(t *testing.T) {
creator: &stubCloudCreator{},
provider: cloudprovider.GCP,
controllerCountFlag: intPtr(3),
workerCountFlag: intPtr(-1),
workerCountFlag: intPtr(0),
wantErr: true,
},
"flag control-plane-count missing": {
@ -130,6 +140,8 @@ func TestCreate(t *testing.T) {
setupFs: func(require *require.Assertions) afero.Fs { return afero.NewMemMapFs() },
creator: &stubCloudCreator{},
provider: cloudprovider.GCP,
controllerCountFlag: intPtr(1),
workerCountFlag: intPtr(1),
insTypeFlag: "invalid",
wantErr: true,
},
@ -142,6 +154,8 @@ func TestCreate(t *testing.T) {
},
creator: &stubCloudCreator{},
provider: cloudprovider.GCP,
controllerCountFlag: intPtr(1),
workerCountFlag: intPtr(1),
yesFlag: true,
wantErr: true,
},
@ -154,6 +168,8 @@ func TestCreate(t *testing.T) {
},
creator: &stubCloudCreator{},
provider: cloudprovider.GCP,
controllerCountFlag: intPtr(1),
workerCountFlag: intPtr(1),
yesFlag: true,
wantErr: true,
},
@ -166,6 +182,8 @@ func TestCreate(t *testing.T) {
},
creator: &stubCloudCreator{},
provider: cloudprovider.GCP,
controllerCountFlag: intPtr(1),
workerCountFlag: intPtr(1),
yesFlag: true,
wantErr: true,
},
@ -173,6 +191,8 @@ func TestCreate(t *testing.T) {
setupFs: func(require *require.Assertions) afero.Fs { return afero.NewMemMapFs() },
creator: &stubCloudCreator{},
provider: cloudprovider.GCP,
controllerCountFlag: intPtr(1),
workerCountFlag: intPtr(1),
yesFlag: true,
devConfigFlag: "dev-config.json",
wantErr: true,
@ -181,6 +201,8 @@ func TestCreate(t *testing.T) {
setupFs: func(require *require.Assertions) afero.Fs { return afero.NewMemMapFs() },
creator: &stubCloudCreator{createErr: someErr},
provider: cloudprovider.GCP,
controllerCountFlag: intPtr(1),
workerCountFlag: intPtr(1),
yesFlag: true,
wantErr: true,
},
@ -191,6 +213,8 @@ func TestCreate(t *testing.T) {
},
creator: &stubCloudCreator{},
provider: cloudprovider.GCP,
controllerCountFlag: intPtr(1),
workerCountFlag: intPtr(1),
yesFlag: true,
wantErr: true,
},
@ -216,10 +240,10 @@ func TestCreate(t *testing.T) {
require.NoError(cmd.Flags().Set("dev-config", tc.devConfigFlag))
}
if tc.controllerCountFlag != nil {
require.NoError(cmd.Flags().Set("control-plane-nodes", fmt.Sprint(*tc.controllerCountFlag)))
require.NoError(cmd.Flags().Set("control-plane-nodes", strconv.Itoa(*tc.controllerCountFlag)))
}
if tc.workerCountFlag != nil {
require.NoError(cmd.Flags().Set("worker-nodes", fmt.Sprint(*tc.workerCountFlag)))
require.NoError(cmd.Flags().Set("worker-nodes", strconv.Itoa(*tc.workerCountFlag)))
}
if tc.insTypeFlag != "" {
require.NoError(cmd.Flags().Set("instance-type", tc.insTypeFlag))