|
|
@@ -24,17 +24,17 @@ import (
|
|
|
// fakeConverter returns a fixed book and counts how often it was called, so
|
|
|
// tests can check that nothing is fetched when arguments are rejected.
|
|
|
type fakeConverter struct {
|
|
|
- title string
|
|
|
- err error
|
|
|
- calls int
|
|
|
- kepub bool // the KEPUB option of the last call
|
|
|
- noLocal bool // the NoLocal option of the last call
|
|
|
+ title string
|
|
|
+ err error
|
|
|
+ calls int
|
|
|
+ kepub bool // the KEPUB option of the last call
|
|
|
+ local bool // the Local option of the last call
|
|
|
}
|
|
|
|
|
|
func (f *fakeConverter) convert(ctx context.Context, u *url.URL, opts pipeline.Options) (*pipeline.Book, error) {
|
|
|
f.calls++
|
|
|
f.kepub = opts.KEPUB
|
|
|
- f.noLocal = opts.NoLocal
|
|
|
+ f.local = opts.Local
|
|
|
if f.err != nil {
|
|
|
return nil, f.err
|
|
|
}
|
|
|
@@ -280,25 +280,25 @@ func TestKEPUBOption(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func TestNoLocalOption(t *testing.T) {
|
|
|
- for _, noLocal := range []bool{false, true} {
|
|
|
+func TestLocalOption(t *testing.T) {
|
|
|
+ for _, local := range []bool{false, true} {
|
|
|
conv := &fakeConverter{title: "Title"}
|
|
|
args := []string{"-URL", testURL, "-SAVE", t.TempDir()}
|
|
|
- if noLocal {
|
|
|
- args = append(args, "-NOLOCAL")
|
|
|
+ if local {
|
|
|
+ args = append(args, "-LOCAL")
|
|
|
}
|
|
|
if r := runCLI(t, conv, args...); r.code != exitOK {
|
|
|
- t.Fatalf("noLocal=%v: exit code = %d, stderr = %q", noLocal, r.code, r.stderr)
|
|
|
+ t.Fatalf("local=%v: exit code = %d, stderr = %q", local, r.code, r.stderr)
|
|
|
}
|
|
|
- if conv.noLocal != noLocal {
|
|
|
- t.Errorf("noLocal=%v: pipeline got NoLocal=%v", noLocal, conv.noLocal)
|
|
|
+ if conv.local != local {
|
|
|
+ t.Errorf("local=%v: pipeline got Local=%v", local, conv.local)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// TestNoLocalRefusesLocalPage runs the real pipeline: without -NOLOCAL a
|
|
|
-// page on localhost may be converted, with it the page isn't even fetched.
|
|
|
-func TestNoLocalRefusesLocalPage(t *testing.T) {
|
|
|
+// TestLocalPageNeedsFlag runs the real pipeline: a page on localhost is
|
|
|
+// refused without -LOCAL, before anything is fetched, and converted with it.
|
|
|
+func TestLocalPageNeedsFlag(t *testing.T) {
|
|
|
blog, err := os.ReadFile("../../testdata/pages/blog.html")
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
@@ -313,9 +313,10 @@ func TestNoLocalRefusesLocalPage(t *testing.T) {
|
|
|
|
|
|
dir := t.TempDir()
|
|
|
var stdout, stderr bytes.Buffer
|
|
|
- code := run(context.Background(), []string{"-URL", srv.URL + "/post", "-SAVE", dir, "-NOLOCAL"}, &stdout, &stderr, pipeline.Run)
|
|
|
- if code != exitFetch || !strings.Contains(stderr.String(), "local or private address") {
|
|
|
- t.Errorf("exit code = %d, stderr = %q; want %d and a refused local address", code, stderr.String(), exitFetch)
|
|
|
+ code := run(context.Background(), []string{"-URL", srv.URL + "/post", "-SAVE", dir}, &stdout, &stderr, pipeline.Run)
|
|
|
+ want := "error: -URL 127.0.0.1 is on this computer or a private network; add -LOCAL to convert it\n"
|
|
|
+ if code != exitUsage || stderr.String() != want {
|
|
|
+ t.Errorf("exit code = %d, stderr = %q; want %d and %q", code, stderr.String(), exitUsage, want)
|
|
|
}
|
|
|
if n := requests.Load(); n != 0 {
|
|
|
t.Errorf("server got %d requests, want 0", n)
|
|
|
@@ -324,8 +325,8 @@ func TestNoLocalRefusesLocalPage(t *testing.T) {
|
|
|
|
|
|
stdout.Reset()
|
|
|
stderr.Reset()
|
|
|
- if code := run(context.Background(), []string{"-URL", srv.URL + "/post", "-SAVE", dir}, &stdout, &stderr, pipeline.Run); code != exitOK {
|
|
|
- t.Errorf("without -NOLOCAL: exit code = %d, stderr = %q", code, stderr.String())
|
|
|
+ if code := run(context.Background(), []string{"-URL", srv.URL + "/post", "-SAVE", dir, "-LOCAL"}, &stdout, &stderr, pipeline.Run); code != exitOK {
|
|
|
+ t.Errorf("with -LOCAL: exit code = %d, stderr = %q", code, stderr.String())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -467,7 +468,8 @@ func TestEndToEnd(t *testing.T) {
|
|
|
|
|
|
realRun := func(args ...string) result {
|
|
|
var stdout, stderr bytes.Buffer
|
|
|
- code := run(context.Background(), args, &stdout, &stderr, pipeline.Run)
|
|
|
+ // The test server is on localhost.
|
|
|
+ code := run(context.Background(), append(args, "-LOCAL"), &stdout, &stderr, pipeline.Run)
|
|
|
return result{code, stdout.String(), stderr.String()}
|
|
|
}
|
|
|
|
|
|
@@ -825,7 +827,7 @@ func TestLocalFilesNeverRead(t *testing.T) {
|
|
|
|
|
|
out := filepath.Join(t.TempDir(), "book.epub")
|
|
|
var stdout, stderr bytes.Buffer
|
|
|
- code := run(context.Background(), []string{"-URL", srv.URL + "/posts/eink", "-SAVE", out}, &stdout, &stderr, pipeline.Run)
|
|
|
+ code := run(context.Background(), []string{"-URL", srv.URL + "/posts/eink", "-SAVE", out, "-LOCAL"}, &stdout, &stderr, pipeline.Run)
|
|
|
if code != exitOK {
|
|
|
t.Fatalf("exit %d: %s", code, stderr.String())
|
|
|
}
|