I am developing a simple unit test for this scenario:
When I authenticate a user in my application, I add him to Revel's cache, using: cache.Set("someKey", username, time.Hour).
When I request a PUT or DELETE I remove the same user from the cache, using: cache.Delete("someKey")
I tested that manually and it works like a charm.
However, I want to unit test this to make sure that the user has actually been removed from the cache whenever a PUT or DELETE happened:
1 - Pre-insert some key/user to the Cache
2 - Run the requests above for the same key/user
3 - Try to get the key/user from the Cache and assert that the result nil or empty
I am using Ginkgo with Gomega as the testing framework and Napping to make requests, and inside the my test description I wrote:
JustBeforeEach(func() {
// some other Structs setup...
cache.Set("test", 123, cache.DEFAULT)
}
Then I get a nasty invalid memory address or nil pointer dereference
Test Panicked runtime error: invalid memory address or nil pointer dereference /usr/local/go/src/pkg/runtime/panic.c:482
Full Stack Trace /home/vagrant/go/src/http://ift.tt/15MyrBW (0x73f2e4) com/revel/revel/cache.Set: return Instance.Set(key, value, expires)
cache.go:133 is exactly the call to the cache.Set method.
One thing that I observed, is that my PUT and DELETE requests WILL call the cache.Delete method successfully if I am not trying to use Revel's Cache in the test context.
So to my question: Why is the Revel's cache nil during a test context?
Aucun commentaire:
Enregistrer un commentaire