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

🌱 Add unit test on features.go #1579

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
94 changes: 94 additions & 0 deletions pkg/provisioner/ironic/clients/features_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}