MCPcopy Create free account
hub / github.com/algolia/cli / TestResolveName

Function TestResolveName

pkg/cmd/application/create/create_test.go:520–566  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

518}
519
520func TestResolveName(t *testing.T) {
521 t.Run("explicit flag wins", func(t *testing.T) {
522 f, _ := test.NewFactory(true, nil, nil, "")
523 opts := &CreateOptions{IO: f.IOStreams, Name: "Explicit", nameProvided: true}
524 name, err := resolveName(opts)
525 require.NoError(t, err)
526 assert.Equal(t, "Explicit", name)
527 })
528
529 t.Run("interactive prompt returns entered value", func(t *testing.T) {
530 f, _ := test.NewFactory(true, nil, nil, "")
531 origAsk := prompt.SurveyAskOne
532 prompt.SurveyAskOne = func(_ survey.Prompt, response interface{}, _ ...survey.AskOpt) error {
533 *(response.(*string)) = "Typed Name"
534 return nil
535 }
536 t.Cleanup(func() { prompt.SurveyAskOne = origAsk })
537
538 opts := &CreateOptions{IO: f.IOStreams, Name: "My First Application"}
539 name, err := resolveName(opts)
540 require.NoError(t, err)
541 assert.Equal(t, "Typed Name", name)
542 })
543
544 t.Run("empty interactive input falls back to default", func(t *testing.T) {
545 f, _ := test.NewFactory(true, nil, nil, "")
546 origAsk := prompt.SurveyAskOne
547 prompt.SurveyAskOne = func(_ survey.Prompt, response interface{}, _ ...survey.AskOpt) error {
548 *(response.(*string)) = ""
549 return nil
550 }
551 t.Cleanup(func() { prompt.SurveyAskOne = origAsk })
552
553 opts := &CreateOptions{IO: f.IOStreams, Name: "My First Application"}
554 name, err := resolveName(opts)
555 require.NoError(t, err)
556 assert.Equal(t, "My First Application", name)
557 })
558
559 t.Run("non-interactive falls back to default", func(t *testing.T) {
560 f, _ := test.NewFactory(false, nil, nil, "")
561 opts := &CreateOptions{IO: f.IOStreams, Name: "My First Application"}
562 name, err := resolveName(opts)
563 require.NoError(t, err)
564 assert.Equal(t, "My First Application", name)
565 })
566}

Callers

nothing calls this directly

Calls 3

NewFactoryFunction · 0.92
resolveNameFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected