Skip to content

Commit

Permalink
Test multiple combinations of table filtering flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Eckert committed Aug 3, 2022
1 parent 87c191f commit fbe5f8f
Showing 1 changed file with 66 additions and 48 deletions.
114 changes: 66 additions & 48 deletions cli/cmd/proxy/read/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,47 +59,57 @@ func TestReadCommandOutput(t *testing.T) {
podName := "fakePod"

// These regular expressions must be present in the output.
expected := []string{
fmt.Sprintf("Envoy configuration for %s in namespace default:", podName),

"==> Clusters \\(6\\)",
"Name.*FQDN.*Endpoints.*Type.*Last Updated",
"local_agent.*local_agent.*192\\.168\\.79\\.187:8502.*STATIC.*2022-05-13T04:22:39\\.553Z",
"local_app.*local_app.*127\\.0\\.0\\.1:8080.*STATIC.*2022-05-13T04:22:39\\.655Z",
"client.*client\\.default\\.dc1\\.internal\\.bc3815c2-1a0f-f3ff-a2e9-20d791f08d00\\.consul.*EDS.*2022-06-09T00:39:12\\.948Z",
"frontend.*frontend\\.default\\.dc1\\.internal\\.bc3815c2-1a0f-f3ff-a2e9-20d791f08d00\\.consul.*EDS.*2022-06-09T00:39:12\\.855Z",
"original-destination.*original-destination.*ORIGINAL_DST.*2022-05-13T04:22:39.743Z",
"server.*server.default.dc1.internal.bc3815c2-1a0f-f3ff-a2e9-20d791f08d00.consul.*EDS.*2022-06-09T00:39:12\\.754Z",

"==> Endpoints \\(9\\)",
"Address:Port.*Cluster.*Weight.*Status",
"192.168.79.187:8502.*local_agent.*1.00.*HEALTHY",
"127.0.0.1:8080.*local_app.*1.00.*HEALTHY",
"192.168.31.201:20000.*1.00.*HEALTHY",
"192.168.47.235:20000.*1.00.*HEALTHY",
"192.168.71.254:20000.*1.00.*HEALTHY",
"192.168.63.120:20000.*1.00.*HEALTHY",
"192.168.18.110:20000.*1.00.*HEALTHY",
"192.168.52.101:20000.*1.00.*HEALTHY",
"192.168.65.131:20000.*1.00.*HEALTHY",

"==> Listeners \\(2\\)",
"Name.*Address:Port.*Direction.*Filter Chain Match.*Filters.*Last Updated",
"public_listener.*192\\.168\\.69\\.179:20000.*INBOUND.*Any.*\\* to local_app/.*2022-06-09T00:39:27\\.668Z",
"outbound_listener.*127.0.0.1:15001.*OUTBOUND.*10\\.100\\.134\\.173/32, 240\\.0\\.0\\.3/32.*to client.default.dc1.internal.bc3815c2-1a0f-f3ff-a2e9-20d791f08d00.consul.*2022-05-24T17:41:59\\.079Z",
"10\\.100\\.254\\.176/32, 240\\.0\\.0\\.4/32.*\\* to server\\.default\\.dc1\\.internal\\.bc3815c2-1a0f-f3ff-a2e9-20d791f08d00\\.consul/",
"10\\.100\\.31\\.2/32, 240\\.0\\.0\\.2/32.*to frontend\\.default\\.dc1\\.internal\\.bc3815c2-1a0f-f3ff-a2e9-20d791f08d00\\.consul",
"Any.*to original-destination",

"==> Routes \\(2\\)",
"Name.*Destination Cluster.*Last Updated",
"public_listener.*local_app/.*2022-06-09T00:39:27.667Z",
"server.*server\\.default\\.dc1\\.internal\\.bc3815c2-1a0f-f3ff-a2e9-20d791f08d00\\.consul/.*2022-05-24T17:41:59\\.078Z",

"==> Secrets \\(2\\)",
"Name.*Type.*Last Updated",
"default.*Dynamic Active.*2022-05-24T17:41:59.078Z",
"ROOTCA.*Dynamic Warming.*2022-03-15T05:14:22.868Z",
expectedHeader := fmt.Sprintf("Envoy configuration for %s in namespace default:", podName)
expected := map[string][]string{
"-clusters": {"==> Clusters \\(6\\)",
"Name.*FQDN.*Endpoints.*Type.*Last Updated",
"local_agent.*local_agent.*192\\.168\\.79\\.187:8502.*STATIC.*2022-05-13T04:22:39\\.553Z",
"local_app.*local_app.*127\\.0\\.0\\.1:8080.*STATIC.*2022-05-13T04:22:39\\.655Z",
"client.*client\\.default\\.dc1\\.internal\\.bc3815c2-1a0f-f3ff-a2e9-20d791f08d00\\.consul.*EDS.*2022-06-09T00:39:12\\.948Z",
"frontend.*frontend\\.default\\.dc1\\.internal\\.bc3815c2-1a0f-f3ff-a2e9-20d791f08d00\\.consul.*EDS.*2022-06-09T00:39:12\\.855Z",
"original-destination.*original-destination.*ORIGINAL_DST.*2022-05-13T04:22:39.743Z",
"server.*server.default.dc1.internal.bc3815c2-1a0f-f3ff-a2e9-20d791f08d00.consul.*EDS.*2022-06-09T00:39:12\\.754Z"},

"-endpoints": {"==> Endpoints \\(9\\)",
"Address:Port.*Cluster.*Weight.*Status",
"192.168.79.187:8502.*local_agent.*1.00.*HEALTHY",
"127.0.0.1:8080.*local_app.*1.00.*HEALTHY",
"192.168.31.201:20000.*1.00.*HEALTHY",
"192.168.47.235:20000.*1.00.*HEALTHY",
"192.168.71.254:20000.*1.00.*HEALTHY",
"192.168.63.120:20000.*1.00.*HEALTHY",
"192.168.18.110:20000.*1.00.*HEALTHY",
"192.168.52.101:20000.*1.00.*HEALTHY",
"192.168.65.131:20000.*1.00.*HEALTHY"},

"-listeners": {"==> Listeners \\(2\\)",
"Name.*Address:Port.*Direction.*Filter Chain Match.*Filters.*Last Updated",
"public_listener.*192\\.168\\.69\\.179:20000.*INBOUND.*Any.*\\* to local_app/.*2022-06-09T00:39:27\\.668Z",
"outbound_listener.*127.0.0.1:15001.*OUTBOUND.*10\\.100\\.134\\.173/32, 240\\.0\\.0\\.3/32.*to client.default.dc1.internal.bc3815c2-1a0f-f3ff-a2e9-20d791f08d00.consul.*2022-05-24T17:41:59\\.079Z",
"10\\.100\\.254\\.176/32, 240\\.0\\.0\\.4/32.*\\* to server\\.default\\.dc1\\.internal\\.bc3815c2-1a0f-f3ff-a2e9-20d791f08d00\\.consul/",
"10\\.100\\.31\\.2/32, 240\\.0\\.0\\.2/32.*to frontend\\.default\\.dc1\\.internal\\.bc3815c2-1a0f-f3ff-a2e9-20d791f08d00\\.consul",
"Any.*to original-destination"},

"-routes": {"==> Routes \\(2\\)",
"Name.*Destination Cluster.*Last Updated",
"public_listener.*local_app/.*2022-06-09T00:39:27.667Z",
"server.*server\\.default\\.dc1\\.internal\\.bc3815c2-1a0f-f3ff-a2e9-20d791f08d00\\.consul/.*2022-05-24T17:41:59\\.078Z"},

"-secrets": {"==> Secrets \\(2\\)",
"Name.*Type.*Last Updated",
"default.*Dynamic Active.*2022-05-24T17:41:59.078Z",
"ROOTCA.*Dynamic Warming.*2022-03-15T05:14:22.868Z"},
}

cases := map[string][]string{
"No filters": {},
"Clusters": {"-clusters"},
"Endpoints": {"-endpoints"},
"Listeners": {"-listeners"},
"Routes": {"-routes"},
"Secrets": {"-secrets"},
"Clusters and routes": {"-clusters", "-routes"},
"Secrets then listeners": {"-secrets", "-listeners"},
}

fakePod := v1.Pod{
Expand All @@ -118,13 +128,21 @@ func TestReadCommandOutput(t *testing.T) {
return testEnvoyConfig, nil
}

out := c.Run([]string{podName})
require.Equal(t, 0, out)

actual := buf.String()

for _, expression := range expected {
require.Regexp(t, expression, actual)
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
args := append([]string{podName}, tc...)
out := c.Run(args)
require.Equal(t, 0, out)

actual := buf.String()

require.Regexp(t, expectedHeader, actual)
for _, table := range tc {
for _, expression := range expected[table] {
require.Regexp(t, expression, actual)
}
}
})
}
}

Expand Down

0 comments on commit fbe5f8f

Please sign in to comment.