2021-06-30 01:14:11 +03:00
|
|
|
package cnireconciler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
testutils "github.com/Azure/azure-container-networking/test/utils"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"k8s.io/utils/exec"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newCNIVersionFakeExec(ver string) exec.Interface {
|
|
|
|
calls := []testutils.TestCmd{
|
2021-07-14 22:53:45 +03:00
|
|
|
{Cmd: []string{"/opt/cni/bin/azure-vnet", "-v"}, Stdout: ver},
|
2021-06-30 01:14:11 +03:00
|
|
|
}
|
|
|
|
|
2021-07-14 22:53:45 +03:00
|
|
|
fake := testutils.GetFakeExecWithScripts(calls)
|
2021-06-30 01:14:11 +03:00
|
|
|
return fake
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsDumpStateVer(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
exec exec.Interface
|
|
|
|
want bool
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "bad ver",
|
|
|
|
exec: newCNIVersionFakeExec(`Azure CNI Version v1.4.1`),
|
|
|
|
want: false,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "bad dirty ver",
|
|
|
|
exec: newCNIVersionFakeExec(`Azure CNI Version v1.4.0-2-g984c5a5e-dirty`),
|
|
|
|
want: false,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "good ver",
|
2021-07-21 02:06:35 +03:00
|
|
|
exec: newCNIVersionFakeExec(`Azure CNI Version v1.4.7`),
|
2021-06-30 01:14:11 +03:00
|
|
|
want: true,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "good dirty ver",
|
2021-07-21 02:06:35 +03:00
|
|
|
exec: newCNIVersionFakeExec(`Azure CNI Version v1.4.7-7-g7b97e1eb`),
|
2021-06-30 01:14:11 +03:00
|
|
|
want: true,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
2023-07-26 19:52:27 +03:00
|
|
|
{
|
|
|
|
name: "non-semver",
|
|
|
|
exec: newCNIVersionFakeExec(`Azure CNI Version v1.4.35_Win2019OverlayFix`),
|
|
|
|
want: true,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "non-semver hotfix ver",
|
|
|
|
exec: newCNIVersionFakeExec(`Azure CNI Version v1.4.44.4`),
|
|
|
|
want: true,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
2021-06-30 01:14:11 +03:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
got, err := isDumpStateVer(tt.exec)
|
|
|
|
if tt.wantErr {
|
|
|
|
assert.Error(t, err)
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, tt.want, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|