1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00
denoland-deno/deno_dir_test.go

49 lines
1 KiB
Go
Raw Normal View History

2018-05-28 21:50:44 -04:00
// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
// All rights reserved. MIT License.
2018-05-29 04:28:32 -04:00
package deno
2018-05-22 12:43:20 -04:00
import (
"io/ioutil"
"testing"
)
2018-05-24 10:25:38 -04:00
func SetCacheDirForTest(prefix string) {
2018-05-22 12:43:20 -04:00
dir, err := ioutil.TempDir("", prefix)
if err != nil {
panic(err)
}
2018-05-24 10:25:38 -04:00
CacheDir = dir
2018-05-22 12:43:20 -04:00
}
func TestLoadOutputCodeCache(t *testing.T) {
2018-05-24 10:25:38 -04:00
SetCacheDirForTest("TestLoadOutputCodeCache")
2018-05-22 12:43:20 -04:00
filename := "Hello.ts"
sourceCodeBuf := []byte("1+2")
cacheFn := CacheFileName(filename, sourceCodeBuf)
outputCode, err := LoadOutputCodeCache(filename, sourceCodeBuf)
if err != nil {
t.Fatalf(err.Error())
}
if outputCode != "" {
t.Fatalf("Expected empty outputCode but got <<%s>>", outputCode)
}
// Now let's write to the cache file
err = ioutil.WriteFile(cacheFn, []byte("blah"), 0700)
if err != nil {
t.Fatalf(err.Error())
}
// Try it again.
outputCode, err = LoadOutputCodeCache(filename, sourceCodeBuf)
if err != nil {
t.Fatalf(err.Error())
}
if outputCode != "blah" {
t.Fatalf("Bad outputCode but got <<%s>>", outputCode)
}
}