<commit_before>package api

import (
	. "github.com/onsi/ginkgo/v2"
	. "github.com/onsi/gomega"
	"k8s.io/utils/pointer"

	v1 "kubevirt.io/api/core/v1"
)

var _ = Describe("Defaults", func() {

	It("should leave the scheduler name unset by default", func() {
		vmi := &v1.VirtualMachineInstance{}
		v1.SetObjectDefaults_VirtualMachineInstance(vmi)
		Expect(vmi.Spec.SchedulerName).To(BeEmpty())
	})

	It("should take a custom scheduler if specified", func() {
		vmi := &v1.VirtualMachineInstance{Spec: v1.VirtualMachineInstanceSpec{SchedulerName: "custom-one"}}
		v1.SetObjectDefaults_VirtualMachineInstance(vmi)
		Expect(vmi.Spec.SchedulerName).To(Equal("custom-one"))
	})

	It("should add ACPI feature if it is unspecified", func() {
		vmi := &v1.VirtualMachineInstance{}
		v1.SetObjectDefaults_VirtualMachineInstance(vmi)
		Expect(*vmi.Spec.Domain.Features.ACPI.Enabled).To(BeTrue())
	})

	It("should not add non-ACPI feature by default", func() {
		vmi := &v1.VirtualMachineInstance{}
		v1.SetObjectDefaults_VirtualMachineInstance(vmi)
		Expect(vmi.Spec.Domain.Features.APIC).To(BeNil())
		Expect(vmi.Spec.Domain.Features.Hyperv).To(BeNil())
	})

	It("should not add SMM feature if it is unspecified", func() {
		vmi := &v1.VirtualMachineInstance{}
		v1.SetObjectDefaults_VirtualMachineInstance(vmi)
		Expect(vmi.Spec.Domain.Features.SMM).To(BeNil())
	})

	It("should add interface and pod network by default", func() {
		vmi := &v1.VirtualMachineInstance{}
		v1.SetDefaults_NetworkInterface(vmi)
		Expect(len(vmi.Spec.Domain.Devices.Interfaces)).NotTo(BeZero())
		Expect(len(vmi.Spec.Networks)).NotTo(BeZero())
	})

	It("should default to true to all defined features", func() {
		vmi := &v1.VirtualMachineInstance{
			Spec: v1.VirtualMachineInstanceSpec{
				Domain: v1.DomainSpec{},
			},
		}
		vmi.Spec.Domain.Features = &v1.Features{
			ACPI: v1.FeatureState{},
			SMM:  &v1.FeatureState{},
			APIC: &v1.FeatureAPIC{},
			Hyperv: &v1.FeatureHyperv{
				Relaxed:         &v1.FeatureState{},
				VAPIC:           &v1.FeatureState{},
				Spinlocks:       &v1.FeatureSpinlocks{},
				VPIndex:         &v1.FeatureState{},
				Runtime:         &v1.FeatureState{},
				SyNIC:           &v1.FeatureState{},
				SyNICTimer:      &v1.SyNICTimer{},
				Reset:           &v1.FeatureState{},
				VendorID:        &v1.FeatureVendorID{},
				Frequencies:     &v1.FeatureState{},
				Reenlightenment: &v1.FeatureState{},
				TLBFlush:        &v1.FeatureState{},
			},<commit_msg>fix new linter warnings in defaults_test.go<commit_after>package api

import (
	. "github.com/onsi/ginkgo/v2"
	. "github.com/onsi/gomega"
	"k8s.io/utils/pointer"

	v1 "kubevirt.io/api/core/v1"
)

var _ = Describe("Defaults", func() {

	It("should leave the scheduler name unset by default", func() {
		vmi := &v1.VirtualMachineInstance{}
		v1.SetObjectDefaults_VirtualMachineInstance(vmi)
		Expect(vmi.Spec.SchedulerName).To(BeEmpty())
	})

	It("should take a custom scheduler if specified", func() {
		vmi := &v1.VirtualMachineInstance{Spec: v1.VirtualMachineInstanceSpec{SchedulerName: "custom-one"}}
		v1.SetObjectDefaults_VirtualMachineInstance(vmi)
		Expect(vmi.Spec.SchedulerName).To(Equal("custom-one"))
	})

	It("should add ACPI feature if it is unspecified", func() {
		vmi := &v1.VirtualMachineInstance{}
		v1.SetObjectDefaults_VirtualMachineInstance(vmi)
		Expect(*vmi.Spec.Domain.Features.ACPI.Enabled).To(BeTrue())
	})

	It("should not add non-ACPI feature by default", func() {
		vmi := &v1.VirtualMachineInstance{}
		v1.SetObjectDefaults_VirtualMachineInstance(vmi)
		Expect(vmi.Spec.Domain.Features.APIC).To(BeNil())
		Expect(vmi.Spec.Domain.Features.Hyperv).To(BeNil())
	})

	It("should not add SMM feature if it is unspecified", func() {
		vmi := &v1.VirtualMachineInstance{}
		v1.SetObjectDefaults_VirtualMachineInstance(vmi)
		Expect(vmi.Spec.Domain.Features.SMM).To(BeNil())
	})

	It("should add interface and pod network by default", func() {
		vmi := &v1.VirtualMachineInstance{}
		v1.SetDefaults_NetworkInterface(vmi)
		Expect(vmi.Spec.Domain.Devices.Interfaces).NotTo(BeEmpty())
		Expect(vmi.Spec.Networks).NotTo(BeEmpty())
	})

	It("should default to true to all defined features", func() {
		vmi := &v1.VirtualMachineInstance{
			Spec: v1.VirtualMachineInstanceSpec{
				Domain: v1.DomainSpec{},
			},
		}
		vmi.Spec.Domain.Features = &v1.Features{
			ACPI: v1.FeatureState{},
			SMM:  &v1.FeatureState{},
			APIC: &v1.FeatureAPIC{},
			Hyperv: &v1.FeatureHyperv{
				Relaxed:         &v1.FeatureState{},
				VAPIC:           &v1.FeatureState{},
				Spinlocks:       &v1.FeatureSpinlocks{},
				VPIndex:         &v1.FeatureState{},
				Runtime:         &v1.FeatureState{},
				SyNIC:           &v1.FeatureState{},
				SyNICTimer:      &v1.SyNICTimer{},
				Reset:           &v1.FeatureState{},
				VendorID:        &v1.FeatureVendorID{},
				Frequencies:     &v1.FeatureState{},
				Reenlightenment: &v1.FeatureState{},
				TLBFlush:        &v1.FeatureState{},
			},
{'fraction_non_alphanumeric': 0.1484689766317486, 'fraction_numerical': 0.014907332796132152, 'mean_word_length': 4.020222446916077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2271372', 'n_tokens_mistral': 1953, 'n_tokens_neox': 1748, 'n_words': 287}