diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go index 09374c32..f00b6f5d 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go @@ -40,7 +40,7 @@ func (l *accessLogger) OnLog() { return } - proxywasm.LogInfof("OnLog: :path = %s", hdr) + proxywasm.LogInfof(":path = %s", hdr) proxywasm.LogInfof("message = %s", l.logMessage) } diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go index 0804ebeb..71928db6 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go @@ -10,12 +10,20 @@ import ( ) func TestAccessLogger_OnLog(t *testing.T) { + configuration := `this is my log message` opt := proxytest.NewEmulatorOption(). - WithNewRootContext(newAccessLogger) + WithNewRootContext(newAccessLogger). + WithPluginConfiguration([]byte(configuration)) + host := proxytest.NewHostEmulator(opt) // Release the host emulation lock so that other test cases can insert their own host emulation. defer host.Done() + // Call OnPluginStart -> the message field of root context is configured. + status := host.StartPlugin() + // Check the status returned by OnPluginStart is OK. + require.Equal(t, types.OnPluginStartStatusOK, status) + // Call OnLog with the given headers. host.CallOnLogForAccessLogger(types.Headers{ {":path", "/this/is/path"}, @@ -23,5 +31,6 @@ func TestAccessLogger_OnLog(t *testing.T) { // Check the Envoy logs. logs := host.GetLogs(types.LogLevelInfo) - require.Contains(t, logs, "OnLog: :path = /this/is/path") + require.Contains(t, logs, ":path = /this/is/path") + require.Contains(t, logs, "message = this is my log message") } diff --git a/images/extension-builders/tinygo/commands.sh b/images/extension-builders/tinygo/commands.sh index 18abd33b..55b0b480 100755 --- a/images/extension-builders/tinygo/commands.sh +++ b/images/extension-builders/tinygo/commands.sh @@ -18,14 +18,14 @@ extension_build() { tinygo build -o "$1" -scheduler=none -target wasi main.go # This is necessary since the created go caches are with read-only permission, # and without this, the host user cannot delete the build directory with "rm -rf". - chmod -R a+rw build/ + chmod -R u+rw build/ } extension_test() { go test -tags=proxytest -v ./... # This is necessary since the created go caches are with read-only permission, # and without this, the host user cannot delete the build directory with "rm -rf". - chmod -R a+rw build/ + chmod -R u+rw build/ } extension_clean() {