Skip to content

Commit

Permalink
Add unit test for pkg/ipfix
Browse files Browse the repository at this point in the history
Signed-off-by: Naman Agarwal <naman.agarwal75@gmail.com>
  • Loading branch information
NamanAg30 committed Jan 13, 2023
1 parent c4506c0 commit b6a25ee
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions pkg/ipfix/ipfix_registry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2023 Antrea Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package ipfix

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestGetInfoElement(t *testing.T) {
tc := []struct {
testname string
name string
enterpriseID uint32
expectedElementID uint16
expectedError string
}{
{
testname: "Invalid enterpriseID",
name: "sourcePodNamespace",
enterpriseID: 1,
expectedError: "Registry with EnterpriseID 1 is not supported.",
},
{
testname: "Information element with given enterpriseID and name exists in registry",
name: "sourcePodNamespace",
enterpriseID: 56506,
expectedElementID: 100,
expectedError: "",
},
{
testname: "Information element with given name does not exist in registry",
name: "sourcePod",
enterpriseID: 0,
expectedError: "Information element with name sourcePod in registry with enterpriseID 0 cannot be found.",
},
}
for _, tt := range tc {
t.Run(tt.testname, func(t *testing.T) {
reg := NewIPFIXRegistry()
reg.LoadRegistry()
element, err := reg.GetInfoElement(tt.name, tt.enterpriseID)
if tt.expectedError != "" {
assert.EqualError(t, err, tt.expectedError)
} else {
require.NoError(t, err)
assert.Equal(t, tt.expectedElementID, element.ElementId)
}
})
}
}

0 comments on commit b6a25ee

Please sign in to comment.