Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
71
pkg/cache/vins_test.go
vendored
Normal file
71
pkg/cache/vins_test.go
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
package cache_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"fiskerinc.com/modules/cache"
|
||||
"fiskerinc.com/modules/redis"
|
||||
"fiskerinc.com/modules/testhelper"
|
||||
)
|
||||
|
||||
type mockRedisCacheVINs struct {
|
||||
redis.Connection
|
||||
}
|
||||
|
||||
func (c *mockRedisCacheVINs) GetCache(id string, data interface{}, expire int) error {
|
||||
vins := []string{"TESTVIN123", "TESTVIN456"}
|
||||
|
||||
dataBytes, err := json.Marshal(vins)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(dataBytes, data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type mockRedisEmptyCacheVINs struct {
|
||||
redis.Connection
|
||||
}
|
||||
|
||||
func (c *mockRedisEmptyCacheVINs) GetCache(id string, data interface{}, expire int) error {
|
||||
vins := []string{}
|
||||
|
||||
dataBytes, err := json.Marshal(vins)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(dataBytes, data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *mockRedisEmptyCacheVINs) SetCache(id string, data interface{}, expire int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestRetrieveAndCacheVINs(t *testing.T) {
|
||||
setupRedisMock()
|
||||
setupDBMock()
|
||||
|
||||
mockRedis = &mockRedisCacheVINs{}
|
||||
_, err := cache.RetrieveVINs(mockRedis, mockDB, "VALID_ID")
|
||||
if err != nil {
|
||||
t.Errorf(testhelper.TestErrorTemplate, "TestRetrieveAndCacheDriverIDs", nil, err)
|
||||
}
|
||||
|
||||
mockRedis = &mockRedisEmptyCacheVINs{}
|
||||
_, err = cache.RetrieveVINs(mockRedis, mockDB, "VALID_ID")
|
||||
if err != nil {
|
||||
t.Errorf(testhelper.TestErrorTemplate, "TestRetrieveAndCacheDriverIDs", nil, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user