File tree 7 files changed +93
-41
lines changed
7 files changed +93
-41
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,12 @@ jobs:
100
100
env :
101
101
HOST : " :8080"
102
102
103
+ memcached :
104
+ image : memcached:1.6.9-alpine
105
+ ports :
106
+ - " 11211"
107
+
108
+
103
109
steps :
104
110
- name : Set up Go
105
111
uses : actions/setup-go@v2
@@ -117,6 +123,7 @@ jobs:
117
123
HEALTH_GO_MG_DSN : mongodb://localhost:${{ job.services.mongo.ports[27017] }}/
118
124
HEALTH_GO_MS_DSN : test:test@tcp(localhost:${{ job.services.mysql.ports[3306] }})/test?charset=utf8
119
125
HEALTH_GO_HTTP_URL : http://localhost:${{ job.services.http.ports[8080] }}/status
126
+ HEALTH_GO_MD_DSN : memcached://localhost:${{ job.services.memcached.ports[11211] }}/
120
127
121
128
- name : Upload coverage to Codecov
122
129
uses : codecov/codecov-action@v1
Original file line number Diff line number Diff line change 13
13
HEALTH_GO_MG_DSN=" mongodb://` docker-compose port mongo 27017` /" \
14
14
HEALTH_GO_MS_DSN=" test:test@tcp(` docker-compose port mysql 3306` )/test?charset=utf8" \
15
15
HEALTH_GO_HTTP_URL=" http://` docker-compose port http 8080` /status" \
16
+ HEALTH_GO_MD_DSN=" memcached://localhost:${{ job.services.memcached.ports[11211] } }/" \
16
17
go test -cover ./... -coverprofile=coverage.txt -covermode=atomic
17
18
18
19
lint :
Original file line number Diff line number Diff line change
1
+ package memcached
2
+
3
+ import (
4
+ "context"
5
+ "fmt"
6
+ "strings"
7
+
8
+ "github.com/bradfitz/gomemcache/memcache"
9
+ )
10
+
11
+ // Config is the Memcached checker configuration settings container.
12
+ type Config struct {
13
+ // DSN is the Memcached instance connection DSN. Required.
14
+ DSN string
15
+ }
16
+
17
+ // New creates new Memcached health check that verifies the following:
18
+ // - connection establishing
19
+ // - doing the PING command and verifying the response
20
+ func New (config Config ) func (ctx context.Context ) error {
21
+ // support all DSN formats (for backward compatibility) - with and w/out schema and path part:
22
+ // - memcached://localhost:11211/
23
+ // - localhost:11211
24
+ memcachedDSN := strings .TrimPrefix (config .DSN , "memcached://" )
25
+ memcachedDSN = strings .TrimSuffix (memcachedDSN , "/" )
26
+
27
+ return func (ctx context.Context ) error {
28
+ mdb := memcache .New (memcachedDSN )
29
+
30
+ err := mdb .Ping ()
31
+
32
+ if err != nil {
33
+ return fmt .Errorf ("memcached ping failed: %w" , err )
34
+ }
35
+
36
+ return nil
37
+ }
38
+ }
Original file line number Diff line number Diff line change
1
+ package memcached
2
+
3
+ import (
4
+ "context"
5
+ "os"
6
+ "testing"
7
+
8
+ "github.com/stretchr/testify/require"
9
+ )
10
+
11
+ const rdDSNEnv = "HEALTH_GO_MD_DSN"
12
+
13
+ func TestNew (t * testing.T ) {
14
+ check := New (Config {
15
+ DSN : getDSN (t ),
16
+ })
17
+
18
+ err := check (context .Background ())
19
+ require .NoError (t , err )
20
+ }
21
+
22
+ func TestNewError (t * testing.T ) {
23
+ check := New (Config {
24
+ DSN : "" ,
25
+ })
26
+
27
+ err := check (context .Background ())
28
+ require .Error (t , err )
29
+ }
30
+
31
+ func getDSN (t * testing.T ) string {
32
+ t .Helper ()
33
+
34
+ redisDSN , ok := os .LookupEnv (rdDSNEnv )
35
+ require .True (t , ok )
36
+
37
+ return redisDSN
38
+ }
Original file line number Diff line number Diff line change @@ -45,6 +45,11 @@ services:
45
45
MYSQL_USER : test
46
46
MYSQL_PASSWORD : test
47
47
48
+ memcached :
49
+ image : memcached:1.6.9-alpine
50
+ ports :
51
+ - " 11211"
52
+
48
53
http :
49
54
image : pierreprinetti/apimock:latest
50
55
ports :
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ module github.com/hellofresh/health-go/v4
3
3
go 1.15
4
4
5
5
require (
6
+ github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b
6
7
github.com/go-redis/redis/v8 v8.4.2
7
8
github.com/go-sql-driver/mysql v1.5.0
8
9
github.com/jackc/pgx/v4 v4.10.0
Load Diff Large diffs are not rendered by default.
You can’t perform that action at this time.
0 commit comments