mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-22 16:34:32 +01:00
a58ce74ed0
Primary goals: - Scrollable output ( fixes #245 ) - Sending job signals from status view - Filtering of output by filesystem Implementation: - original TUI framework: github.com/rivo/tview - but: tview is quasi-unmaintained, didn't support some features - => use fork https://gitlab.com/tslocum/cview - however, don't buy into either too much to avoid lock-in - instead: **port over the existing status UI drawing code and adjust it to produce strings instead of directly drawing into the termbox buffer** Co-authored-by: Calistoc <calistoc@protonmail.com> Co-authored-by: InsanePrawn <insane.prawny@gmail.com> fixes #245 fixes #220
51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
package choices_test
|
|
|
|
import (
|
|
"bytes"
|
|
"flag"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/zrepl/zrepl/util/choices"
|
|
)
|
|
|
|
func TestChoices(t *testing.T) {
|
|
|
|
var c choices.Choices
|
|
|
|
fs := flag.NewFlagSet("testset", flag.ContinueOnError)
|
|
c.Init("append", os.O_APPEND, "overwrite", os.O_TRUNC|os.O_CREATE)
|
|
fs.Var(&c, "mode", c.Usage())
|
|
var o bytes.Buffer
|
|
fs.SetOutput(&o)
|
|
|
|
fs.Usage()
|
|
usage := o.String()
|
|
o.Reset()
|
|
|
|
t.Logf("usage:\n%s", usage)
|
|
require.Contains(t, usage, "\"append\"")
|
|
require.Contains(t, usage, "\"overwrite\"")
|
|
|
|
err := fs.Parse([]string{"-mode", "append"})
|
|
require.NoError(t, err)
|
|
o.Reset()
|
|
require.Equal(t, os.O_APPEND, c.Value())
|
|
|
|
c.SetDefaultValue(nil)
|
|
err = fs.Parse([]string{})
|
|
require.NoError(t, err)
|
|
o.Reset()
|
|
require.Nil(t, c.Value())
|
|
|
|
// a little whitebox testing: this is allowed ATM, we don't check that the default value was specified as a choice in init
|
|
c.SetDefaultValue(os.O_RDWR)
|
|
err = fs.Parse([]string{})
|
|
require.NoError(t, err)
|
|
o.Reset()
|
|
require.Equal(t, os.O_RDWR, c.Value())
|
|
|
|
}
|