diff options
Diffstat (limited to 'integration_test.go')
-rw-r--r-- | integration_test.go | 69 |
1 files changed, 55 insertions, 14 deletions
diff --git a/integration_test.go b/integration_test.go index f1a60f499..90aad560b 100644 --- a/integration_test.go +++ b/integration_test.go @@ -12,6 +12,8 @@ import ( "testing" ) +var denoFn string + // Some tests require an HTTP server. We start one here. // Because we process tests synchronously in this program we must run // the server as a subprocess. @@ -45,7 +47,7 @@ func listTestFiles() []string { return out } -func checkOutput(t *testing.T, outFile string, denoFn string) { +func checkOutput(t *testing.T, outFile string) { outFile = path.Join("testdata", outFile) jsFile := strings.TrimSuffix(outFile, ".out") @@ -54,19 +56,10 @@ func checkOutput(t *testing.T, outFile string, denoFn string) { t.Fatal(err.Error()) } - dir, err := ioutil.TempDir("", "TestIntegration") - if err != nil { - panic(err) - } - - cmd := exec.Command(denoFn, "--cachedir="+dir, jsFile) - var out bytes.Buffer - cmd.Stdout = &out - err = cmd.Run() + actual, _, err := deno(jsFile) if err != nil { t.Fatal(err.Error()) } - actual := out.Bytes() if bytes.Compare(actual, expected) != 0 { t.Fatalf(`Actual output does not match expected. -----Actual------------------- @@ -75,17 +68,65 @@ func checkOutput(t *testing.T, outFile string, denoFn string) { } } -func TestIntegration(t *testing.T) { +func deno(inputFn string) (actual []byte, cachedir string, err error) { + cachedir, err = ioutil.TempDir("", "TestIntegration") + if err != nil { + panic(err) + } + + cmd := exec.Command(denoFn, "--cachedir="+cachedir, inputFn) + var out bytes.Buffer + cmd.Stdout = &out + err = cmd.Run() + if err == nil { + actual = out.Bytes() + } + return +} + +func integrationTestSetup() { startServer() cwd, err := os.Getwd() if err != nil { panic(err) } - denoFn := path.Join(cwd, "deno") + denoFn = path.Join(cwd, "deno") +} + +func TestIntegration(t *testing.T) { + integrationTestSetup() outFiles := listTestFiles() for _, outFile := range outFiles { t.Run(outFile, func(t *testing.T) { - checkOutput(t, outFile, denoFn) + checkOutput(t, outFile) }) } } + +func TestUrlArgs(t *testing.T) { + integrationTestSetup() + + // Using good port 4545 + _, cachedir, err := deno("http://localhost:4545/testdata/001_hello.js") + if err != nil { + t.Fatalf("Expected success. %s", err.Error()) + } + cacheFn := path.Join(cachedir, "src/localhost:4545/testdata/001_hello.js") + println("good cacheFn", cacheFn) + if !exists(cacheFn) { + t.Fatalf("Expected 200 at '%s'", cacheFn) + } + // TODO check output + + // Using bad port 4546 instead of 4545. + _, cachedir, err = deno("http://localhost:4546/testdata/001_hello.js") + if err == nil { + t.Fatalf("Expected 404. %s", err.Error()) + } + // Check that cache dir is emtpy. + cacheFn = path.Join(cachedir, "src/localhost:4546/testdata/001_hello.js") + println("bad cacheFn", cacheFn) + if exists(cacheFn) { + t.Fatalf("Expected 404 at '%s'", cacheFn) + } +} |