github.com/Kong/go-pdk@v0.11.0/ip/ip_test.go (about) 1 package ip 2 3 import ( 4 "testing" 5 6 "github.com/Kong/go-pdk/bridge" 7 "github.com/Kong/go-pdk/bridge/bridgetest" 8 "github.com/Kong/go-pdk/server/kong_plugin_protocol" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestIsTrusted(t *testing.T) { 13 ip := Ip{bridge.New(bridgetest.Mock(t, []bridgetest.MockStep{ 14 { 15 Method: "kong.ip.is_trusted", 16 Args: bridge.WrapString("1.1.1.1"), 17 Ret: &kong_plugin_protocol.Bool{V: true}, 18 }, 19 { 20 Method: "kong.ip.is_trusted", 21 Args: bridge.WrapString("1.0.0.1"), 22 Ret: &kong_plugin_protocol.Bool{V: false}, 23 }, 24 }))} 25 26 ret, err := ip.IsTrusted("1.1.1.1") 27 assert.NoError(t, err) 28 assert.True(t, ret) 29 30 ret, err = ip.IsTrusted("1.0.0.1") 31 assert.NoError(t, err) 32 assert.False(t, ret) 33 }