Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/fix golden file #29

Merged
merged 5 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func runBinaryWithFileInput(args []string, bytesToWrite []byte) ([]byte, error)
return nil, err
}

fmt.Println("Starting command...")
if err = cmd.Start(); err != nil {
return nil, err
}
Expand All @@ -73,11 +74,13 @@ func runBinaryWithFileInput(args []string, bytesToWrite []byte) ([]byte, error)

_, err = stdin.Write(bytesToWrite)

fmt.Println("Wrote to stdin", bytesToWrite)

if err != nil {
fmt.Println("Error writing to stdin", err)
}

time.Sleep(15 * time.Second)
time.Sleep(14 * time.Second)

if err = cmd.Process.Signal(os.Interrupt); err != nil {
fmt.Println("signal")
Expand All @@ -94,7 +97,7 @@ func runBinaryWithFileInput(args []string, bytesToWrite []byte) ([]byte, error)
}
}

return nil, err
return out, err
}

func TestStaticCliArgs(t *testing.T) {
Expand Down Expand Up @@ -133,34 +136,26 @@ func TestSearch(t *testing.T) {
tests := []struct {
name string
args []string
fixture string
bytesToWrite []byte
}{
{"search test", []string{"search", "Eloquent JavaScript"}, "eloquent.golden", []byte{14, 14, 10}},
{"search test", []string{"search", "Eloquent JavaScript"}, []byte{14, 14, 10}},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
output, err := runBinaryWithFileInput(tt.args, tt.bytesToWrite)

fmt.Println(string(output))
if _, err := os.Stat("eloquent-javascript-a-modern-introduction-to-programming.epub"); err == nil {
fmt.Printf("File exists\n");
} else {
t.Fatal("File wasn't found")
}

if err != nil {
fmt.Println("error", err.Error())
t.Fatal(err)
}

if *update {
writeFixture(t, tt.fixture, output)
}

actual := removeLastLine(string(output), 1)
expected := strings.TrimSpace(loadFixture(t, tt.fixture))

fmt.Println("\nactual:\n", actual)
fmt.Println("\nexpected:\n", expected)

if !reflect.DeepEqual(actual, expected) {
t.Fatalf("actual: \n'%s'\n, expected: \n'%s'\n", actual, expected)
}
})
}
}
Expand Down
Empty file removed testdata/eloquent.golden
Empty file.