github.com/supabase/cli@v1.168.1/internal/utils/credentials/input_test.go (about) 1 package credentials 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestPromptMasked(t *testing.T) { 12 t.Run("reads from piped stdin", func(t *testing.T) { 13 // Setup token 14 r, w, err := os.Pipe() 15 require.NoError(t, err) 16 _, err = w.WriteString("token") 17 require.NoError(t, err) 18 require.NoError(t, w.Close()) 19 // Run test 20 input := PromptMasked(r) 21 // Check error 22 assert.Equal(t, "token", input) 23 }) 24 25 t.Run("empty string on closed pipe", func(t *testing.T) { 26 // Setup empty stdin 27 r, _, err := os.Pipe() 28 require.NoError(t, err) 29 require.NoError(t, r.Close()) 30 // Run test 31 input := PromptMasked(r) 32 // Check error 33 assert.Empty(t, input) 34 }) 35 }