diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-06-22 14:23:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-22 14:23:42 +0200 |
commit | 86354a29a40fb97e334f951428239ab8e171e2dd (patch) | |
tree | 2f0d8cc2680aa4ccbaf865b427976b3f810b6920 /integration_test.go | |
parent | ef9dc2464e10510bdcc4be9eae431e3dcf7f7999 (diff) |
Delete go implementation (#276)
The go prototype will remain at https://github.com/ry/deno/tree/golang
Diffstat (limited to 'integration_test.go')
-rw-r--r-- | integration_test.go | 139 |
1 files changed, 0 insertions, 139 deletions
diff --git a/integration_test.go b/integration_test.go deleted file mode 100644 index 2d1cbdbea..000000000 --- a/integration_test.go +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright 2018 Ryan Dahl <ry@tinyclouds.org> -// All rights reserved. MIT License. -package deno - -import ( - "bytes" - "io/ioutil" - "net" - "net/http" - "os" - "os/exec" - "path" - "strings" - "testing" -) - -var denoFn string - -// Some tests require an HTTP server. We start one here. -// Note that "localhost:4545" is hardcoded into the tests at the moment, -// so if the server runs on a different port, it will fail. -func startServer() { - l, err := net.Listen("tcp", ":4545") - check(err) - rootHandler := http.FileServer(http.Dir(".")) - go func() { - err := http.Serve(l, rootHandler) - check(err) - }() -} - -func listTestFiles() []string { - files, err := ioutil.ReadDir("testdata") - check(err) - out := make([]string, 0) - for _, file := range files { - fn := file.Name() - if strings.HasSuffix(fn, ".out") { - out = append(out, fn) - } - } - return out -} - -func checkOutput(t *testing.T, outFile string, shouldSucceed bool) { - outFile = path.Join("testdata", outFile) - jsFile := strings.TrimSuffix(outFile, ".out") - - expected, err := ioutil.ReadFile(outFile) - if err != nil { - t.Fatal(err.Error()) - } - - actual, _, err := deno(jsFile) - if shouldSucceed && err != nil { - t.Fatalf("Expected success %s", err.Error()) - } else if !shouldSucceed && err == nil { - t.Fatalf("Expected failure but got success") - } - if !patternMatch(string(expected), string(actual)) { - t.Fatalf(`Actual output does not match expected. ------Actual------------------- -%s-----Expected----------------- -%s------------------------------`, string(actual), string(expected)) - } -} - -func deno(inputFn string) (actual []byte, cachedir string, err error) { - cachedir, err = ioutil.TempDir("", "TestIntegration") - check(err) - - cmd := exec.Command(denoFn, "--cachedir="+cachedir, inputFn) - var out bytes.Buffer - cmd.Stdout = &out - cmd.Stderr = &out - err = cmd.Run() - actual = out.Bytes() - return -} - -func integrationTestSetup() { - if denoFn == "" { - startServer() - cwd, err := os.Getwd() - check(err) - denoFn = path.Join(cwd, "deno") - } -} - -func TestIntegrationFiles(t *testing.T) { - integrationTestSetup() - outFiles := listTestFiles() - for _, outFile := range outFiles { - t.Run(outFile, func(t *testing.T) { - shouldSucceed := strings.Index(outFile, "error") < 0 - checkOutput(t, outFile, shouldSucceed) - }) - } -} - -func TestIntegrationUrlArgs(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 empty. - 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) - } -} - -func TestTestsTs(t *testing.T) { - integrationTestSetup() - // TODO Need unit test for each of the permissions. - cmd := exec.Command(denoFn, "--allow-net", "--allow-write", "tests.ts") - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - err := cmd.Run() - if err != nil { - t.Fatal(err.Error()) - } -} |