From c4d8e2f3c0d432d5dbcf490ccd89f3ff527ee46b Mon Sep 17 00:00:00 2001 From: mevrin Date: Tue, 5 Mar 2024 06:32:20 -0500 Subject: [PATCH] Add unit test on features.go Signed-off-by: mevrin --- .../ironic/clients/features_test.go | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 pkg/provisioner/ironic/clients/features_test.go diff --git a/pkg/provisioner/ironic/clients/features_test.go b/pkg/provisioner/ironic/clients/features_test.go new file mode 100644 index 0000000000..c7665d363f --- /dev/null +++ b/pkg/provisioner/ironic/clients/features_test.go @@ -0,0 +1,94 @@ +package clients + +import ( + "fmt" + "testing" +) + +func TestAvailableFeatures_ChooseMicroversion(t *testing.T) { + microVersion := "1.86" + type fields struct { + MaxVersion int + } + tests := []struct { + name string + feature fields + want string + }{ + { + name: fmt.Sprintf("MaxVersion < %d return microversion %s", 86, baseline), + feature: fields{ + MaxVersion: 50, + }, + want: baseline, + }, + { + name: fmt.Sprintf("MaxVersion = %d return %s", 86, microVersion), + feature: fields{ + MaxVersion: 86, + }, + want: microVersion, + }, + { + name: fmt.Sprintf("MaxVersion > %d return %s", 86, microVersion), + feature: fields{ + MaxVersion: 100, + }, + want: microVersion, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + af := AvailableFeatures{ + MaxVersion: tt.feature.MaxVersion, + } + if got := af.ChooseMicroversion(); got != tt.want { + t.Errorf("ChooseMicroversion() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestAvailableFeatures_HasFirmwareUpdates(t *testing.T) { + maxVersion := 86 + type fields struct { + MaxVersion int + } + tests := []struct { + name string + feature fields + want bool + }{ + { + name: fmt.Sprintf("Firmware < %d", maxVersion), + feature: fields{ + MaxVersion: 50, + }, + want: false, + }, + { + name: fmt.Sprintf("Firmware = %d", maxVersion), + feature: fields{ + MaxVersion: 86, + }, + want: true, + }, + { + name: fmt.Sprintf("Firmware > %d", maxVersion), + feature: fields{ + MaxVersion: 100, + }, + want: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + af := AvailableFeatures{ + MaxVersion: tt.feature.MaxVersion, + } + if got := af.HasFirmwareUpdates(); got != tt.want { + t.Errorf("HasFirmwareUpdates() = %v, want %v", got, tt.want) + } + }) + } +}