Kong / go-pdk

Write Kong plugins in Go! 🦍
https://pkg.go.dev/github.com/Kong/go-pdk
Apache License 2.0
144 stars 48 forks source link

TestEnv.ClientRes.Status is not behaving as expected when ExitStatus is called. #163

Closed at-silva closed 4 months ago

at-silva commented 8 months ago

Steps to reproduce:

lab.go:

package golab45

import (
    "net/http"

    "github.com/Kong/go-pdk"
)

type (
    Config struct {
    }
)

func (c *Config) Access(kong *pdk.PDK) {
    kong.Response.ExitStatus(http.StatusBadRequest)
}

lab_test.go:

package golab45_test

import (
    "golab45"
    "net/http"
    "testing"

    "github.com/Kong/go-pdk/test"
)

func Test(t *testing.T) {
    env, _ := test.New(t, test.Request{Method: http.MethodGet, Url: "http://example.com"})
    env.DoHttp(&golab45.Config{})
    if env.ClientRes.Status != http.StatusBadRequest {
        t.Errorf("expected %d got %d", http.StatusBadRequest, env.ClientRes.Status)
    }
}

test output:

Running tool: /usr/local/go/bin/go test -timeout 30s -run ^Test$ golab45

--- FAIL: Test (0.00s)
    ./test.go:579: Access
    ./lab_test.go:15: expected 400 got 200
FAIL
FAIL    golab45 0.003s
FAIL
gszr commented 4 months ago

Possibly related to https://github.com/Kong/go-pdk/issues/119

gszr commented 4 months ago

Thank you for the repro sample.

StarlightIbuki commented 4 months ago

Internally tracked: KAG-3813 I agree it should be related to #119

gszr commented 4 months ago

This issue is fixed as of version v0.10.2; please give it a try! Closing the issue for now. Thank you for taking the time to report!