cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

cat/module-path
012 / e2e / stream_test.go
stream_test.go 1.7K
1package e2e23import (4 "os"5 "path/filepath"6 "strings"7 "testing"8 "time"9)1011// A cell run as a stream with the real nu follows a log as it's12// written: its rows reach the output and the sheet it was sent to as13// lines are appended, and Stop ends it, keeping them.14func TestNotebookStreamWithNu(t *testing.T) {15 t.Parallel()16 needNu(t)17 dir := t.TempDir()18 logFile := filepath.Join(dir, "app.log")19 if err := os.WriteFile(logFile, []byte("info started\n"), 0o644); err != nil {20 t.Fatal(err)21 }22 s := startWith(t, options{dir: dir, startsOn: "EDIT"}, "nu")23 s.keys("log = tail -n +1 -f app.log | lines | parse '{level} {msg}'", "<esc>", "f")24 s.waitFor("● live, 1 row")25 s.waitFor("started")2627 s.keys("G", "<enter>")28 s.waitFor("Sent log to")29 appendFile(t, logFile, "warn slow-query\nerror disk-full\n")30 s.waitFor("● live, 3 rows")31 s.waitFor("disk-full")3233 s.keys("<ctrl+pgdown>", "<ctrl+home>", "<right>", "<right>", "<right>", "=ROWS(nu.log)", "<enter>")34 s.waitFor(" 4")35 appendFile(t, logFile, "info recovered\n")36 s.waitFor(" 5")3738 s.keys("<ctrl+pgup>", "i", "i")39 s.waitFor("✓")40 s.eventually("the stream stopped", func() bool { return !strings.Contains(s.screen(), "● live") })41 appendFile(t, logFile, "info after-stop\n")42 s.keys("<ctrl+pgdown>")43 s.waitFor(" 5")44 time.Sleep(time.Second)45 if strings.Contains(s.screen(), " 6") {46 t.Errorf("rows arrived after Stop:\n%s", s.screen())47 }48 s.keys("<ctrl+q>", "d")49 s.waitExit()50}5152func appendFile(t *testing.T, name, text string) {53 t.Helper()54 f, err := os.OpenFile(name, os.O_APPEND|os.O_WRONLY, 0)55 if err != nil {56 t.Fatal(err)57 }58 defer f.Close()59 if _, err := f.WriteString(text); err != nil {60 t.Fatal(err)61 }62}