Remove server dependencies as Drone does not support services
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Tyler 2019-10-02 20:36:45 -04:00
parent b396128a23
commit 4af5b3af83
5 changed files with 20 additions and 39 deletions

View File

@ -3,10 +3,6 @@ type: docker
name: default
steps:
- name: redis
image: redis:latest
- name: memcache
image: memcached:latest
- name: test
image: golang
commands:

View File

@ -3,6 +3,7 @@ package cache
import (
"errors"
"github.com/vmihailenco/msgpack/v4"
"net"
"net/url"
"strconv"
"strings"
@ -37,8 +38,14 @@ func New(uri string) (CacheInterface, error) {
switch u.Scheme {
case Redis:
port := u.Port()
if port == "" {
port = "6379"
}
return NewRedisCache(RedisSettings{
Address: u.Host,
Address: net.JoinHostPort(u.Hostname(), port),
Password: query.Get("password"),
})
case Memcache:

View File

@ -10,6 +10,7 @@ type MemcacheSettings struct {
}
type MemcacheCache struct {
servers []string
backend *memcache.Client
}
@ -17,6 +18,7 @@ func NewMemcacheCache(s MemcacheSettings) (CacheInterface, error) {
c := memcache.New(s.Servers...)
return &MemcacheCache{
servers: s.Servers,
backend: c,
}, nil
}

View File

@ -2,11 +2,10 @@ package cache
import (
"testing"
"time"
)
func Test_MemcacheURI(t *testing.T) {
cache, err := New("memcache://memcache")
cache, err := New("memcache://localhost")
if err != nil {
t.Fatal("Error creating cache:", err)
@ -17,22 +16,20 @@ func Test_MemcacheURI(t *testing.T) {
}
}
func Test_MemcacheStoreGet(t *testing.T) {
cache, err := New("memcache://memcache")
func Test_MemcacheURIMultipleServers(t *testing.T) {
cache, err := New("memcache://localhost,localhost2")
if err != nil {
t.Fatal("Error creating cache:", err)
}
obj := "test"
c, ok := cache.(*MemcacheCache)
cache.Set("test", obj, time.Minute)
if !ok {
t.Fatal("Cache is not instance of MemcacheCache")
}
var new string
cache.Get("test", &new)
if obj != new {
t.Fatal("Expected", obj, "got", new)
if len(c.servers) != 2 {
t.Fatal("Number of servers does not match!")
}
}

View File

@ -2,11 +2,10 @@ package cache
import (
"testing"
"time"
)
func Test_RedisURI(t *testing.T) {
cache, err := New("redis://redis")
cache, err := New("redis://127.0.0.1:6389")
if err != nil {
t.Fatal("Error creating cache:", err)
@ -16,23 +15,3 @@ func Test_RedisURI(t *testing.T) {
t.Fatal("Cache is not instance of RedisCache")
}
}
func Test_RedisStoreGet(t *testing.T) {
cache, err := New("redis://redis")
if err != nil {
t.Fatal("Error creating cache:", err)
}
obj := "test"
cache.Set("test", obj, time.Minute)
var new string
cache.Get("test", &new)
if obj != new {
t.Fatal("Expected", obj, "got", new)
}
}