2023-04-18 15:13:49 +00:00
|
|
|
package cmdio
|
|
|
|
|
|
|
|
import (
|
2023-09-08 12:07:22 +00:00
|
|
|
"context"
|
2023-04-18 15:13:49 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/libs/flags"
|
2023-04-18 15:13:49 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAskFailedInJsonMode(t *testing.T) {
|
|
|
|
l := NewLogger(flags.ModeJson)
|
2023-08-15 14:50:20 +00:00
|
|
|
_, err := l.Ask("What is your spirit animal?", "")
|
2023-04-18 15:13:49 +00:00
|
|
|
assert.ErrorContains(t, err, "question prompts are not supported in json mode")
|
|
|
|
}
|
2023-09-08 12:07:22 +00:00
|
|
|
|
|
|
|
func TestAskChoiceFailsInJsonMode(t *testing.T) {
|
|
|
|
l := NewLogger(flags.ModeJson)
|
|
|
|
ctx := NewContext(context.Background(), l)
|
|
|
|
|
|
|
|
_, err := AskSelect(ctx, "what is a question?", []string{"b", "c", "a"})
|
|
|
|
assert.EqualError(t, err, "question prompts are not supported in json mode")
|
|
|
|
}
|
2023-10-25 09:37:25 +00:00
|
|
|
|
|
|
|
func TestSplitAtLastNewLine(t *testing.T) {
|
|
|
|
first, last := splitAtLastNewLine("hello\nworld")
|
|
|
|
assert.Equal(t, "hello\n", first)
|
|
|
|
assert.Equal(t, "world", last)
|
|
|
|
|
|
|
|
first, last = splitAtLastNewLine("hello\r\nworld")
|
|
|
|
assert.Equal(t, "hello\r\n", first)
|
|
|
|
assert.Equal(t, "world", last)
|
|
|
|
|
|
|
|
first, last = splitAtLastNewLine("hello world")
|
|
|
|
assert.Equal(t, "", first)
|
|
|
|
assert.Equal(t, "hello world", last)
|
|
|
|
|
|
|
|
first, last = splitAtLastNewLine("hello\nworld\n")
|
|
|
|
assert.Equal(t, "hello\nworld\n", first)
|
|
|
|
assert.Equal(t, "", last)
|
|
|
|
|
|
|
|
first, last = splitAtLastNewLine("\nhello world")
|
|
|
|
assert.Equal(t, "\n", first)
|
|
|
|
assert.Equal(t, "hello world", last)
|
|
|
|
}
|