From 4be9f2f26489f8943df60fda20c03bb510cadfd2 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 11 Jan 2013 10:52:22 -0800 Subject: [PATCH] serverconfig: fix test on OS X Change-Id: Ic5a8f820abe3cad920a18991cc21b5386fdf9553 --- pkg/serverconfig/export_test.go | 4 ++++ pkg/serverconfig/genconfig.go | 6 ++++-- pkg/serverconfig/serverconfig_test.go | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/serverconfig/export_test.go b/pkg/serverconfig/export_test.go index 932457122..6add85319 100644 --- a/pkg/serverconfig/export_test.go +++ b/pkg/serverconfig/export_test.go @@ -17,3 +17,7 @@ limitations under the License. package serverconfig var GenLowLevelConfig = genLowLevelConfig + +func SetTempDirFunc(f func() string) { + tempDir = f +} diff --git a/pkg/serverconfig/genconfig.go b/pkg/serverconfig/genconfig.go index a520b1341..bfdefe5e2 100644 --- a/pkg/serverconfig/genconfig.go +++ b/pkg/serverconfig/genconfig.go @@ -38,6 +38,8 @@ type configPrefixesParams struct { searchOwner *blobref.BlobRef } +var tempDir = os.TempDir + func addPublishedConfig(prefixes jsonconfig.Obj, published jsonconfig.Obj) ([]interface{}, error) { pubPrefixes := []interface{}{} for k, v := range published { @@ -214,7 +216,7 @@ func addS3Config(prefixes jsonconfig.Obj, s3 string) error { prefixes["/cache/"] = map[string]interface{}{ "handler": "storage-filesystem", "handlerArgs": map[string]interface{}{ - "path": filepath.Join(os.TempDir(), "camli-cache"), + "path": filepath.Join(tempDir(), "camli-cache"), }, } } else { @@ -436,7 +438,7 @@ func genLowLevelConfig(conf *Config) (lowLevelConf *Config, err error) { // a temp dir as the cache when primary storage is S3. // TODO(mpl): s3CacheBucket // See http://code.google.com/p/camlistore/issues/detail?id=85 - cacheDir = filepath.Join(os.TempDir(), "camli-cache") + cacheDir = filepath.Join(tempDir(), "camli-cache") } else { cacheDir = filepath.Join(blobPath, "/cache") } diff --git a/pkg/serverconfig/serverconfig_test.go b/pkg/serverconfig/serverconfig_test.go index 588c5336d..435641a5f 100644 --- a/pkg/serverconfig/serverconfig_test.go +++ b/pkg/serverconfig/serverconfig_test.go @@ -33,6 +33,11 @@ import ( "camlistore.org/pkg/serverconfig" ) +func init() { + // Avoid Linux vs. OS X differences in tests. + serverconfig.SetTempDirFunc(func() string { return "/tmp" }) +} + func sortedKeys(m map[string]interface{}) (keys []string) { for k := range m { keys = append(keys, k)