Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add ut to ensure store unaffected during add external interface #3385

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions network/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,40 @@ import (
"github.com/Azure/azure-container-networking/testutils"
)

var errStore = errors.New("store error")

const ifName = "eth0"

func TestManager(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Manager Suite")
}

var _ = Describe("Test Manager", func() {
Describe("Test AddExternalInterface", func() {
Context("When adding the external interface", func() {
It("Should not write to the store", func() {
// accessing the store should result in an error
dataStore := &testutils.KeyValueStoreMock{
WriteError: errStore,
ReadError: errStore,
}
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
store: dataStore,
}
nm.ExternalInterfaces[ifName] = &externalInterface{
Name: ifName,
}
err := nm.AddExternalInterface(ifName, "10.10.10.0/24")
Expect(err).NotTo(HaveOccurred())
})
})
})

Describe("Test deleteExternalInterface", func() {
Context("When external interface not found", func() {
It("Should return nil", func() {
ifName := "eth0"
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
}
Expand All @@ -32,7 +56,6 @@ var _ = Describe("Test Manager", func() {

Context("When external interface found", func() {
It("Should delete external interface", func() {
ifName := "eth0"
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
}
Expand Down Expand Up @@ -78,7 +101,7 @@ var _ = Describe("Test Manager", func() {

Context("When GetModificationTime error and not rebooted", func() {
It("Should populate pointers", func() {
extIfName := "eth0"
extIfName := ifName
nwId := "nwId"
nm := &networkManager{
store: &testutils.KeyValueStoreMock{
Expand Down Expand Up @@ -135,14 +158,13 @@ var _ = Describe("Test Manager", func() {
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
}
num := nm.GetNumberOfEndpoints("eth0", "")
num := nm.GetNumberOfEndpoints(ifName, "")
Expect(num).To(Equal(0))
})
})

Context("When Networks is nil", func() {
It("Should return 0", func() {
ifName := "eth0"
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
}
Expand All @@ -154,7 +176,6 @@ var _ = Describe("Test Manager", func() {

Context("When network not found", func() {
It("Should return 0", func() {
ifName := "eth0"
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
}
Expand All @@ -168,7 +189,6 @@ var _ = Describe("Test Manager", func() {

Context("When endpoints is nil", func() {
It("Should return 0", func() {
ifName := "eth0"
nwId := "nwId"
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
Expand All @@ -184,7 +204,6 @@ var _ = Describe("Test Manager", func() {

Context("When endpoints is found", func() {
It("Should return the length of endpoints", func() {
ifName := "eth0"
nwId := "nwId"
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
Expand Down
Loading