github.com/hazelops/ize@v1.1.12-0.20230915191306-97d7c0e48f11/pkg/terminal/ui_test.go (about)

     1  //go:build !e2e
     2  // +build !e2e
     3  
     4  package terminal
     5  
     6  import (
     7  	"bytes"
     8  	"strings"
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func TestNamedValues(t *testing.T) {
    15  	require := require.New(t)
    16  
    17  	var buf bytes.Buffer
    18  	var ui basicUI
    19  	ui.NamedValues([]NamedValue{
    20  		{"hello", "a"},
    21  		{"this", "is"},
    22  		{"a", "test"},
    23  		{"of", "foo"},
    24  		{"the_key_value", "style"},
    25  	},
    26  		WithWriter(&buf),
    27  	)
    28  
    29  	expected := `
    30            hello: a
    31             this: is
    32                a: test
    33               of: foo
    34    the_key_value: style
    35  
    36  `
    37  
    38  	require.Equal(strings.TrimLeft(expected, "\n"), buf.String())
    39  }
    40  
    41  func TestNamedValues_server(t *testing.T) {
    42  	require := require.New(t)
    43  
    44  	var buf bytes.Buffer
    45  	var ui basicUI
    46  	ui.Output("Server configuration:", WithHeaderStyle(), WithWriter(&buf))
    47  	ui.NamedValues([]NamedValue{
    48  		{"DB Path", "data.db"},
    49  		{"gRPC Address", "127.0.0.1:1234"},
    50  		{"HTTP Address", "127.0.0.1:1235"},
    51  		{"URL Service", "api.alpha.waypoint.run:443 (account: token)"},
    52  	},
    53  		WithWriter(&buf),
    54  	)
    55  
    56  	expected := `
    57  ==> Server configuration:
    58         DB Path: data.db
    59    gRPC Address: 127.0.0.1:1234
    60    HTTP Address: 127.0.0.1:1235
    61     URL Service: api.alpha.waypoint.run:443 (account: token)
    62  
    63  `
    64  
    65  	require.Equal(expected, buf.String())
    66  }
    67  
    68  func TestStatusStyle(t *testing.T) {
    69  	require := require.New(t)
    70  
    71  	var buf bytes.Buffer
    72  	var ui basicUI
    73  	ui.Output(strings.TrimSpace(`
    74  one
    75  two
    76    three`),
    77  		WithWriter(&buf),
    78  		WithInfoStyle(),
    79  	)
    80  
    81  	expected := `    one
    82      two
    83        three
    84  `
    85  
    86  	require.Equal(expected, buf.String())
    87  }