Skip to content

Commit

Permalink
provide fail test for status
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeZappa87 committed Nov 24, 2024
1 parent 733a0f5 commit 8a5cf10
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cni

import (
"context"
"errors"
"net"
"testing"

Expand Down Expand Up @@ -380,6 +381,30 @@ func TestLibCNIType120(t *testing.T) {
assert.NoError(t, err)
}

func TestLibCNIType120FailStatus(t *testing.T) {
// Get the default CNI config
l := defaultCNIConfig()
// Create a fake cni config directory and file
cniDir, confDir := buildFakeConfig(t)
defer tearDownCNIConfig(t, cniDir)
l.pluginConfDir = confDir
// Set the minimum network count as 2 for this test
l.networkCount = 2
err := l.Load(WithLoNetwork, WithDefaultConf)
assert.NoError(t, err)

mockCNI := &MockCNI{}
l.cniConfig = mockCNI
l.networks[0].cni = mockCNI
l.networks[1].cni = mockCNI

mockCNI.On("GetStatusNetworkList", l.networks[0].config).Return(nil)
mockCNI.On("GetStatusNetworkList", l.networks[1].config).Return(errors.New("no ip addresses."))

Check failure on line 402 in cni_test.go

View workflow job for this annotation

GitHub Actions / Linters (1.21.8, ubuntu-22.04)

error-strings: error strings should not be capitalized or end with punctuation or a newline (revive)

Check failure on line 402 in cni_test.go

View workflow job for this annotation

GitHub Actions / Linters (1.22.1, ubuntu-22.04)

error-strings: error strings should not be capitalized or end with punctuation or a newline (revive)
l.cniConfig = mockCNI
err = l.Status()
assert.Error(t, err)
}

type MockCNI struct {
mock.Mock
}
Expand Down

0 comments on commit 8a5cf10

Please sign in to comment.