Skip to content

Commit 9d27ec5

Browse files
add memcache test
Signed-off-by: Achille Roussel <[email protected]>
1 parent d2a5393 commit 9d27ec5

File tree

7 files changed

+60
-0
lines changed

7 files changed

+60
-0
lines changed

docker-compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ services:
77
- '6379:6379'
88
command: redis-server --loglevel debug
99

10+
memcached:
11+
image: memcached:1.6.20-alpine
12+
ports:
13+
- '11211:11211'
14+
1015
mysql:
1116
image: mysql:8.0.33
1217
cap_add:

go.work

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ go 1.20
33
use (
44
.
55
./grpc
6+
./memcache
67
./mysql
78
./postgres
89
./redis

memcache/go.mod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/stealthrocket/net/memcache
2+
3+
go 1.20
4+
5+
require (
6+
github.com/bradfitz/gomemcache v0.0.0-20230124162541-5f7a7d875746
7+
github.com/stealthrocket/net v0.1.2
8+
)
9+
10+
replace github.com/bradfitz/gomemcache => github.com/mar4uk/gomemcache v0.0.0-20221107102512-3adaeb8afff3

memcache/go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
github.com/mar4uk/gomemcache v0.0.0-20221107102512-3adaeb8afff3 h1:fODuxBhkSmNhMOD8faRXsUvoYG5rAijY4YYoOEdsXeY=
2+
github.com/mar4uk/gomemcache v0.0.0-20221107102512-3adaeb8afff3/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
3+
github.com/stealthrocket/net v0.1.2 h1:fxglKhsGrBKMQHiEZuiP2jKyg2WaledYi/G7ijaoAOQ=
4+
github.com/stealthrocket/net v0.1.2/go.mod h1:9a0HqAOSQobNQt/QNqbIFMZzxOOwOrXU+XxXyeiu98o=
5+
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=

memcache/memcache.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Package memcache provides an example of a memcache client compiled to
2+
// GOOS=wasip1.
3+
//
4+
// The test uses https://pkg.go.dev/github.com/bradfitz/gomemcache/memcache and
5+
// interacts with a memcache server on localhost:11211. The docker-compose.yml
6+
// file in the parent directory may be used to start a memcache server to run
7+
// the test against.
8+
//
9+
// Note that at this time, the dependency is changed to https://github.com/mar4uk/gomemcache
10+
// in order to get the changes from https://github.com/bradfitz/gomemcache/pull/158,
11+
// which is required to customize the dial function.
12+
//
13+
// When compiling to other targets than GOOS=wasip1, importing this package has
14+
// no effect.
15+
package memcache

memcache/memcache_wasip1.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//go:build wasip1
2+
3+
package memcache

memcache/memcache_wasip1_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//go:build wasip1
2+
3+
package memcache_test
4+
5+
import (
6+
"testing"
7+
8+
"github.com/bradfitz/gomemcache/memcache"
9+
"github.com/stealthrocket/net/wasip1"
10+
)
11+
12+
func TestMemcache(t *testing.T) {
13+
client := memcache.New("localhost:11211")
14+
// Change the dial function so the client uses the WASI socket extensions
15+
// missing from Go 1.21.
16+
client.DialContext = wasip1.DialContext
17+
18+
if err := client.Ping(); err != nil {
19+
t.Fatal(err)
20+
}
21+
}

0 commit comments

Comments
 (0)