Skip to content

Commit

Permalink
Add missing getter tests (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
Widcket authored Apr 3, 2023
1 parent 7dce9c9 commit 23bab3c
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 0 deletions.
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)
})
}

0 comments on commit 23bab3c

Please sign in to comment.