From 23bab3c8ed42e01730fe9ac7ca6c64c5c204431b Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Mon, 3 Apr 2023 17:45:23 -0300 Subject: [PATCH] Add missing getter tests (#709) --- internal/cli/arguments_test.go | 41 +++++++++++++++++++++++++ internal/cli/flags_test.go | 49 ++++++++++++++++++++++++++++++ internal/cli/picker_option_test.go | 49 ++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 internal/cli/arguments_test.go create mode 100644 internal/cli/flags_test.go create mode 100644 internal/cli/picker_option_test.go diff --git a/internal/cli/arguments_test.go b/internal/cli/arguments_test.go new file mode 100644 index 000000000..005f39da9 --- /dev/null +++ b/internal/cli/arguments_test.go @@ -0,0 +1,41 @@ +package cli + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestArgumentGetters(t *testing.T) { + t.Run("returns the name", func(t *testing.T) { + argument := Argument{Name: "Foo"} + want := "Foo" + got := argument.GetName() + + assert.Equal(t, want, got) + }) + + t.Run("returns the label", func(t *testing.T) { + argument := Argument{Name: "Foo"} + want := "Foo:" + got := argument.GetLabel() + + assert.Equal(t, want, got) + }) + + t.Run("returns the help", func(t *testing.T) { + argument := Argument{Help: "Foo"} + want := "Foo" + got := argument.GetHelp() + + assert.Equal(t, want, got) + }) + + t.Run("returns that the argument is required", func(t *testing.T) { + argument := Argument{} + want := true + got := argument.GetIsRequired() + + assert.Equal(t, want, got) + }) +} diff --git a/internal/cli/flags_test.go b/internal/cli/flags_test.go new file mode 100644 index 000000000..c6cdeae6b --- /dev/null +++ b/internal/cli/flags_test.go @@ -0,0 +1,49 @@ +package cli + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestFlagGetters(t *testing.T) { + t.Run("returns the name", func(t *testing.T) { + flag := Flag{Name: "Foo"} + want := "Foo" + got := flag.GetName() + + assert.Equal(t, want, got) + }) + + t.Run("returns the label", func(t *testing.T) { + flag := Flag{Name: "Foo"} + want := "Foo:" + got := flag.GetLabel() + + assert.Equal(t, want, got) + }) + + t.Run("returns the help", func(t *testing.T) { + flag := Flag{Help: "Foo"} + want := "Foo" + got := flag.GetHelp() + + assert.Equal(t, want, got) + }) + + t.Run("returns that the flag is required", func(t *testing.T) { + flag := Flag{IsRequired: true} + want := true + got := flag.GetIsRequired() + + assert.Equal(t, want, got) + }) + + t.Run("returns that the flag is not required", func(t *testing.T) { + flag := Flag{IsRequired: false} + want := false + got := flag.GetIsRequired() + + assert.Equal(t, want, got) + }) +} diff --git a/internal/cli/picker_option_test.go b/internal/cli/picker_option_test.go new file mode 100644 index 000000000..93b0e0068 --- /dev/null +++ b/internal/cli/picker_option_test.go @@ -0,0 +1,49 @@ +package cli + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestPickerOptions(t *testing.T) { + t.Run("returns the labels", func(t *testing.T) { + options := pickerOptions{pickerOption{label: "Foo"}, pickerOption{label: "Bar"}} + want := []string{"Foo", "Bar"} + got := options.labels() + + assert.Equal(t, want, got) + }) + + t.Run("returns the default label", func(t *testing.T) { + options := pickerOptions{pickerOption{label: "Foo"}, pickerOption{label: "Bar"}} + want := "Foo" + got := options.defaultLabel() + + assert.Equal(t, want, got) + }) + + t.Run("returns an empty label when there are no options", func(t *testing.T) { + options := pickerOptions{} + want := "" + got := options.defaultLabel() + + assert.Equal(t, want, got) + }) + + t.Run("returns the value for a given label", func(t *testing.T) { + options := pickerOptions{pickerOption{label: "Foo", value: "0"}, pickerOption{label: "Bar", value: "1"}} + want := "1" + got := options.getValue("Bar") + + assert.Equal(t, want, got) + }) + + t.Run("returns an empty value given a non-existent label", func(t *testing.T) { + options := pickerOptions{pickerOption{label: "Foo"}} + want := "" + got := options.getValue("Bar") + + assert.Equal(t, want, got) + }) +}