Skip to content

Commit c8513da

Browse files
committed
support tinygo in 'extension init' command
Signed-off-by: mathetake <[email protected]>
1 parent ef34965 commit c8513da

File tree

9 files changed

+150
-18
lines changed

9 files changed

+150
-18
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module envoy.filters.http
2+
3+
go 1.14
4+
5+
require (
6+
github.com/stretchr/testify v1.6.1
7+
github.com/tetratelabs/proxy-wasm-go-sdk v0.0.1
8+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
6+
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
7+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
8+
github.com/tetratelabs/proxy-wasm-go-sdk v0.0.1 h1:HMaVuxBYaqqPF324hbxg10OB8feQQwFU6EWlzh6LW8M=
9+
github.com/tetratelabs/proxy-wasm-go-sdk v0.0.1/go.mod h1:oriMCq3KvyEkgWVKr5B9DauvzpQ4Qy5eb32hxPa83Dw=
10+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
11+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
12+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
13+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package main
2+
3+
import (
4+
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
5+
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types"
6+
)
7+
8+
func main() {
9+
proxywasm.SetNewHttpContext(newContext)
10+
}
11+
12+
type httpFilterContext struct {
13+
id uint32
14+
proxywasm.DefaultContext
15+
}
16+
17+
func newContext(contextID uint32) proxywasm.HttpContext {
18+
return &httpFilterContext{id: contextID}
19+
}
20+
21+
func (ctx *httpFilterContext) OnHttpRequestHeaders(int, bool) types.Action {
22+
// TODO:
23+
return types.ActionContinue
24+
}
25+
26+
func (ctx *httpFilterContext) OnHttpResponseHeaders(int, bool) types.Action {
27+
// TODO:
28+
return types.ActionContinue
29+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
"github.com/stretchr/testify/require"
8+
9+
"github.com/tetratelabs/proxy-wasm-go-sdk/proxytest"
10+
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types"
11+
)
12+
13+
func TestHttpHeaders_OnHttpRequestHeaders(t *testing.T) {
14+
host, done := proxytest.NewHttpFilterHost(newContext)
15+
defer done()
16+
id := host.InitContext()
17+
18+
hs := [][2]string{
19+
{"key1", "value1"},
20+
{"key2", "value2"},
21+
}
22+
host.PutRequestHeaders(id, hs) // call OnHttpRequestHeaders
23+
24+
logs := host.GetLogs(types.LogLevelInfo)
25+
require.Greater(t, len(logs), 1)
26+
27+
assert.Equal(t, "request header: key2: value2", logs[len(logs)-1])
28+
assert.Equal(t, "request header: key1: value1", logs[len(logs)-2])
29+
}
30+
31+
func TestHttpHeaders_OnHttpResponseHeaders(t *testing.T) {
32+
host, done := proxytest.NewHttpFilterHost(newContext)
33+
defer done()
34+
id := host.InitContext()
35+
36+
hs := [][2]string{
37+
{"key1", "value1"},
38+
{"key2", "value2"},
39+
}
40+
host.PutResponseHeaders(id, hs) // call OnHttpResponseHeaders
41+
42+
logs := host.GetLogs(types.LogLevelInfo)
43+
require.Greater(t, len(logs), 1)
44+
45+
assert.Equal(t, "response header: key2: value2", logs[len(logs)-1])
46+
assert.Equal(t, "response header: key1: value1", logs[len(logs)-2])
47+
}

go.mod

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ go 1.13
55
require (
66
bitbucket.org/creachadair/shell v0.0.6
77
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
8+
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a
89
github.com/docker/distribution v2.7.1+incompatible
910
github.com/envoyproxy/go-control-plane v0.9.5
1011
github.com/ghodss/yaml v1.0.0
11-
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a
1212
github.com/go-ole/go-ole v1.2.4 // indirect
13-
github.com/gogo/protobuf v1.3.0
1413
github.com/golang/protobuf v1.3.5
15-
github.com/hashicorp/go-multierror v1.0.0
1614
github.com/manifoldco/promptui v0.0.0-00010101000000-000000000000
1715
github.com/mattn/go-isatty v0.0.12
1816
github.com/mattn/go-shellwords v1.0.10
@@ -27,7 +25,7 @@ require (
2725
github.com/shirou/gopsutil v0.0.0-20190731134726-d80c43f9c984
2826
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
2927
github.com/spf13/cobra v0.0.5
30-
github.com/stretchr/testify v1.4.0
28+
github.com/stretchr/testify v1.6.1
3129
github.com/tetratelabs/getenvoy-package v0.0.0-20190730071641-da31aed4333e
3230
github.com/tetratelabs/log v0.0.0-20190710134534-eb04d1e84fb8
3331
github.com/tetratelabs/multierror v1.1.0

0 commit comments

Comments
 (0)