add test for getFileAccessLog()
@@ -4,6 +4,8 @@ import (
"testing"
core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
+ xds_core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
+ xds_accesslog "github.com/envoyproxy/go-control-plane/envoy/extensions/access_loggers/file/v3"
auth "github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/tls/v3"
structpb "github.com/golang/protobuf/ptypes/struct"
"github.com/golang/protobuf/ptypes/wrappers"
@@ -30,6 +32,46 @@ func TestGetAccessLog(t *testing.T) {
assert.NotNil(res)
}
+func TestGetFileAccessLog(t *testing.T) {
+ assert := tassert.New(t)
+
+ expAccessLogger := &xds_accesslog.FileAccessLog{
+ Path: accessLogPath,
+ AccessLogFormat: &xds_accesslog.FileAccessLog_LogFormat{
+ LogFormat: &xds_core.SubstitutionFormatString{
+ Format: &xds_core.SubstitutionFormatString_JsonFormat{
+ JsonFormat: &structpb.Struct{
+ Fields: map[string]*structpb.Value{
+ "start_time": pbStringValue(`%START_TIME%`),
+ "method": pbStringValue(`%REQ(:METHOD)%`),
+ "path": pbStringValue(`%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%`),
+ "protocol": pbStringValue(`%PROTOCOL%`),
+ "response_code": pbStringValue(`%RESPONSE_CODE%`),
+ "response_code_details": pbStringValue(`%RESPONSE_CODE_DETAILS%`),
+ "time_to_first_byte": pbStringValue(`%RESPONSE_DURATION%`),
+ "upstream_cluster": pbStringValue(`%UPSTREAM_CLUSTER%`),
+ "response_flags": pbStringValue(`%RESPONSE_FLAGS%`),
+ "bytes_received": pbStringValue(`%BYTES_RECEIVED%`),
+ "bytes_sent": pbStringValue(`%BYTES_SENT%`),
+ "duration": pbStringValue(`%DURATION%`),
+ "upstream_service_time": pbStringValue(`%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%`),
+ "x_forwarded_for": pbStringValue(`%REQ(X-FORWARDED-FOR)%`),
+ "user_agent": pbStringValue(`%REQ(USER-AGENT)%`),
+ "request_id": pbStringValue(`%REQ(X-REQUEST-ID)%`),
+ "requested_server_name": pbStringValue("%REQUESTED_SERVER_NAME%"),
+ "authority": pbStringValue(`%REQ(:AUTHORITY)%`),
+ "upstream_host": pbStringValue(`%UPSTREAM_HOST%`),
+ },
+ },
+ },
+ },
+ },
+ }
+ resAccessLogger := getFileAccessLog()
+
+ assert.Equal(resAccessLogger, expAccessLogger)
+}
+
var _ = Describe("Test Envoy tools", func() {
Context("Test GetLocalClusterNameForServiceCluster", func() {
It("", func() {
