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 name: default
steps: steps:
- name: redis
image: redis:latest
- name: memcache
image: memcached:latest
- name: test - name: test
image: golang image: golang
commands: commands:

View File

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

View File

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

View File

@ -2,11 +2,10 @@ package cache
import ( import (
"testing" "testing"
"time"
) )
func Test_MemcacheURI(t *testing.T) { func Test_MemcacheURI(t *testing.T) {
cache, err := New("memcache://memcache") cache, err := New("memcache://localhost")
if err != nil { if err != nil {
t.Fatal("Error creating cache:", err) t.Fatal("Error creating cache:", err)
@ -17,22 +16,20 @@ func Test_MemcacheURI(t *testing.T) {
} }
} }
func Test_MemcacheStoreGet(t *testing.T) { func Test_MemcacheURIMultipleServers(t *testing.T) {
cache, err := New("memcache://memcache") cache, err := New("memcache://localhost,localhost2")
if err != nil { if err != nil {
t.Fatal("Error creating cache:", err) 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 if len(c.servers) != 2 {
t.Fatal("Number of servers does not match!")
cache.Get("test", &new)
if obj != new {
t.Fatal("Expected", obj, "got", new)
} }
} }

View File

@ -2,11 +2,10 @@ package cache
import ( import (
"testing" "testing"
"time"
) )
func Test_RedisURI(t *testing.T) { func Test_RedisURI(t *testing.T) {
cache, err := New("redis://redis") cache, err := New("redis://127.0.0.1:6389")
if err != nil { if err != nil {
t.Fatal("Error creating cache:", err) t.Fatal("Error creating cache:", err)
@ -16,23 +15,3 @@ func Test_RedisURI(t *testing.T) {
t.Fatal("Cache is not instance of RedisCache") 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)
}
}