Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
Signed-off-by: Jesse Haka <haka.jesse@gmail.com>
  • Loading branch information
zetaab committed May 6, 2024
1 parent c42ec1e commit 97160ae
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions internal/xds/translator/proxy_protocol_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright Envoy Gateway Authors
// SPDX-License-Identifier: Apache-2.0
// The full text of the Apache license is available in the LICENSE file at
// the root of the repo.

package translator

import (
"testing"

listenerv3 "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
"github.com/envoyproxy/go-control-plane/pkg/wellknown"
"github.com/stretchr/testify/require"

"github.com/envoyproxy/gateway/internal/ir"
)

func TestPatchProxyProtocolFilter(t *testing.T) {
type testCase struct {
name string
listener *listenerv3.Listener
}

irListener := &ir.HTTPListener{
EnableProxyProtocol: true,
}

testCases := []testCase{
{
name: "listener with proxy proto available already",
listener: &listenerv3.Listener{
ListenerFilters: []*listenerv3.ListenerFilter{
{
Name: wellknown.ProxyProtocol,
},
},
},
},
{
name: "listener with tls, append proxy proto",
listener: &listenerv3.Listener{
ListenerFilters: []*listenerv3.ListenerFilter{
{
Name: wellknown.TLSInspector,
},
},
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
patchProxyProtocolFilter(tc.listener, irListener)
// proxy proto filter should be added always as first
require.Equal(t, wellknown.ProxyProtocol, tc.listener.ListenerFilters[0].Name)
})
}
}

0 comments on commit 97160ae

Please sign in to comment.