-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b44fd78
commit 354295f
Showing
23 changed files
with
542 additions
and
547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/vmware-tanzu/antrea/pkg/features" | ||
) | ||
|
||
func TestOptions_validateFlowExporterConfig(t *testing.T) { | ||
// Enable flow exporter | ||
enableFlowExporter := map[string]bool{ | ||
"FlowExporter": true, | ||
} | ||
features.DefaultMutableFeatureGate.SetFromMap(enableFlowExporter) | ||
testcases := []struct { | ||
// input | ||
collector string | ||
pollInterval string | ||
// expectations | ||
expCollectorNet string | ||
expCollectorStr string | ||
expPollIntervalStr string | ||
expError error | ||
}{ | ||
{collector: "192.168.1.100:2002:tcp", pollInterval: "5s", expCollectorNet: "tcp", expCollectorStr: "192.168.1.100:2002", expPollIntervalStr: "5s", expError: nil}, | ||
{collector: "192.168.1.100:2002:udp", pollInterval: "5s", expCollectorNet: "udp", expCollectorStr: "192.168.1.100:2002", expPollIntervalStr: "5s", expError: nil}, | ||
{collector: "192.168.1.100:2002", pollInterval: "5s", expCollectorNet: "tcp", expCollectorStr: "192.168.1.100:2002", expPollIntervalStr: "5s", expError: nil}, | ||
{collector: "192.168.1.100:2002:sctp", pollInterval: "5s", expCollectorNet: "", expCollectorStr: "", expPollIntervalStr: "", expError: fmt.Errorf("IPFIX flow collector over %s proto is not supported", "sctp")}, | ||
{collector: "192.168.1.100:2002", pollInterval: "5ss", expCollectorNet: "tcp", expCollectorStr: "192.168.1.100:2002", expPollIntervalStr: "", expError: fmt.Errorf("FlowPollInterval is not provided in right format: ")}, | ||
{collector: "192.168.1.100:2002", pollInterval: "1ms", expCollectorNet: "tcp", expCollectorStr: "192.168.1.100:2002", expPollIntervalStr: "", expError: fmt.Errorf("FlowPollInterval should be greater than or equal to one second")}, | ||
} | ||
assert.Equal(t, features.DefaultFeatureGate.Enabled(features.FlowExporter), true) | ||
for _, tc := range testcases { | ||
testOptions := &Options{ | ||
config: new(AgentConfig), | ||
} | ||
testOptions.config.FlowCollectorAddr = tc.collector | ||
testOptions.config.FlowPollInterval = tc.pollInterval | ||
err := testOptions.validateFlowExporterConfig() | ||
|
||
if tc.expError != nil { | ||
assert.NotNil(t, err) | ||
} else { | ||
assert.Equal(t, tc.expCollectorNet, testOptions.flowCollector.Network()) | ||
assert.Equal(t, tc.expCollectorStr, testOptions.flowCollector.String()) | ||
assert.Equal(t, tc.expPollIntervalStr, testOptions.pollInterval.String()) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.