Moving error handlers to the cache implementations.

This commit is contained in:
Burcu Dogan
2014-05-21 15:56:44 +02:00
parent ef33919251
commit 0476447419
4 changed files with 46 additions and 14 deletions

27
cache_test.go Normal file
View File

@@ -0,0 +1,27 @@
// Copyright 2014 The oauth2 Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package oauth2
import (
"os"
"testing"
)
func TestFileCacheErrorHandling(t *testing.T) {
var lastErr error
fileCache := NewFileCache("/path/that/doesnt/exist")
fileCache.ErrorHandlerFunc = func(err error) {
lastErr = err
}
fileCache.Read()
if !os.IsNotExist(lastErr) {
t.Fatalf("Read should have invoked the error handling func with os.ErrNotExist, but read err is %v", lastErr)
}
lastErr = nil
fileCache.Write(&Token{})
if !os.IsNotExist(lastErr) {
t.Fatalf("Write should have invoked the error handling func with os.ErrNotExist, but read err is %v", lastErr)
}
}