Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing getter tests #709

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions internal/cli/arguments_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
49 changes: 49 additions & 0 deletions internal/cli/flags_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
49 changes: 49 additions & 0 deletions internal/cli/picker_option_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}