Skip to content

Commit

Permalink
kinda working but not
Browse files Browse the repository at this point in the history
  • Loading branch information
laureanray committed Jun 29, 2023
1 parent 08dcccf commit fbee267
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
70 changes: 70 additions & 0 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"io/ioutil"
"os"
"os/exec"
"os/signal"
"path/filepath"
"reflect"
"syscall"
"testing"
)

Expand Down Expand Up @@ -41,7 +43,35 @@ func TestMain(m *testing.M) {

func runBinary(args []string) ([]byte, error) {
cmd := exec.Command(binaryPath, args...)
// Set the command's output to the standard output of the current process
// cmd.Stdout = os.Stdout
// cmd.Stderr = os.Stderr
cmd.Env = append(os.Environ(), "GOCOVERDIR=.coverdata")

// Start the command
// err := cmd.Start()
// if err != nil {
// fmt.Printf("Failed to start command: %s\n", err)
// return nil, err
// }

// Set up a signal channel to listen for interrupts
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)

go func() {
// Wait for a signal
<-sigChan

// Send the interrupt signal to the command's process
cmd.Process.Signal(os.Interrupt)
}()

// Wait for the command to complete
err := cmd.Wait()
if err != nil {
fmt.Printf("Command failed: %s\n", err)
}
return cmd.CombinedOutput()
}

Expand All @@ -53,6 +83,8 @@ func TestCliArgs(t *testing.T) {
}{
// {"no arguments", []string{}, "no-args.golden"},
{"help args", []string{"--help"}, "help.golden"},
{"search test", []string{"search", "Eloquent JavaScript"}, "eloquent.golden"},

// {"one argument", []string{"ciao"}, "one-argument.golden"},
// {"multiple arguments", []string{"ciao", "hello"}, "multiple-arguments.golden"},
// {"shout arg", []string{"--shout", "ciao"}, "shout-arg.golden"},
Expand Down Expand Up @@ -83,6 +115,44 @@ func TestCliArgs(t *testing.T) {
}
}

// func TestSearch(t *testing.T) {
// tests := []struct {
// name string
// args []string
// fixture string
// }{
// // {"no arguments", []string{}, "no-args.golden"},
// {"search test", []string{"search \"Eloquent JavaScript\""}, "eloquent.golden"},
// // {"one argument", []string{"ciao"}, "one-argument.golden"},
// // {"multiple arguments", []string{"ciao", "hello"}, "multiple-arguments.golden"},
// // {"shout arg", []string{"--shout", "ciao"}, "shout-arg.golden"},
// }
//
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// output, err := runBinary(tt.args)
//
// if err != nil {
// t.Fatal(err)
// }
//
// fmt.Println(string(output))
//
// if *update {
// writeFixture(t, tt.fixture, output)
// }
//
// actual := string(output)
//
// expected := loadFixture(t, tt.fixture)
//
// if !reflect.DeepEqual(actual, expected) {
// t.Fatalf("actual = %s, expected = %s", actual, expected)
// }
// })
// }
// }

func writeFixture(t *testing.T, goldenFile string, actual []byte) {
t.Helper()
goldenPath := "testdata/" + goldenFile
Expand Down
11 changes: 11 additions & 0 deletions testdata/eloquent.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Searching for: Eloquent JavaScript
https://libgen.is/search.php?req=Eloquent+JavaScript&res=25&view=simple&phrase=1&column=title
Search complete, parsing the document...
Use the arrow keys to navigate: ↓ ↑ → ←
? Select Title:
▸ pdf 1 Mb | Eloquent JavaScript Marijn Haverbeke
pdf 7 Mb | Eloquent JavaScript: A Modern ... Marijn Haverbeke
epub 3 Mb | Eloquent JavaScript: A Modern ... Marijn Haverbeke
pdf 2 Mb | Eloquent JavaScript: A Modern ... Marijn Haverbeke
epub 4 Mb | Eloquent JavaScript: A Modern ... Marijn Haverbeke

0 comments on commit fbee267

Please sign in to comment.