-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…918) Signed-off-by: Radim Hrazdil <[email protected]>
- Loading branch information
Showing
4 changed files
with
118 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package node | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/onsi/ginkgo/reporters" | ||
) | ||
|
||
func TestUnit(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
junitReporter := reporters.NewJUnitReporter("junit.controller-nodenetworkconfigurationpolicy-node-node_suite_test.xml") | ||
RunSpecsWithDefaultAndCustomReporters(t, "Node Test Suite", []Reporter{junitReporter}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package node | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/ginkgo/extensions/table" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/onsi/gomega/types" | ||
"k8s.io/apimachinery/pkg/util/intstr" | ||
) | ||
|
||
var _ = Describe("MaxUnavailable nodes", func() { | ||
type maxUnavailableCase struct { | ||
nmstateEnabledNodes int | ||
maxUnavailable intstr.IntOrString | ||
expectedScaledMaxUnavailable int | ||
expectedError types.GomegaMatcher | ||
} | ||
DescribeTable("testing ScaledMaxUnavailableNodeCount", | ||
func(c maxUnavailableCase) { | ||
maxUnavailable, err := ScaledMaxUnavailableNodeCount(c.nmstateEnabledNodes, c.maxUnavailable) | ||
Expect(err).To(c.expectedError) | ||
Expect(maxUnavailable).To(Equal(c.expectedScaledMaxUnavailable)) | ||
}, | ||
Entry("Default maxUnavailable with odd number of nodes", | ||
maxUnavailableCase{ | ||
nmstateEnabledNodes: 5, | ||
maxUnavailable: intstr.FromString(DEFAULT_MAXUNAVAILABLE), | ||
expectedScaledMaxUnavailable: 3, | ||
expectedError: Not(HaveOccurred()), | ||
}), | ||
Entry("Default maxUnavailable with even number of nodes", | ||
maxUnavailableCase{ | ||
nmstateEnabledNodes: 6, | ||
maxUnavailable: intstr.FromString(DEFAULT_MAXUNAVAILABLE), | ||
expectedScaledMaxUnavailable: 3, | ||
expectedError: Not(HaveOccurred()), | ||
}), | ||
Entry("Absolute maxUnavailable with odd number of nodes", | ||
maxUnavailableCase{ | ||
nmstateEnabledNodes: 5, | ||
maxUnavailable: intstr.FromInt(3), | ||
expectedScaledMaxUnavailable: 3, | ||
expectedError: Not(HaveOccurred()), | ||
}), | ||
Entry("Absolute maxUnavailable with even number of nodes", | ||
maxUnavailableCase{ | ||
nmstateEnabledNodes: 6, | ||
maxUnavailable: intstr.FromInt(3), | ||
expectedScaledMaxUnavailable: 3, | ||
expectedError: Not(HaveOccurred()), | ||
}), | ||
Entry("Wrong string value", | ||
maxUnavailableCase{ | ||
nmstateEnabledNodes: 5, | ||
maxUnavailable: intstr.FromString("asdf"), | ||
expectedScaledMaxUnavailable: 3, | ||
expectedError: HaveOccurred(), | ||
}), | ||
Entry("Absolute value in string", | ||
maxUnavailableCase{ | ||
nmstateEnabledNodes: 5, | ||
maxUnavailable: intstr.FromString("42"), | ||
expectedScaledMaxUnavailable: 3, | ||
expectedError: HaveOccurred(), | ||
}), | ||
Entry("Zero percent", | ||
maxUnavailableCase{ | ||
nmstateEnabledNodes: 5, | ||
maxUnavailable: intstr.FromString("0%"), | ||
expectedScaledMaxUnavailable: 1, | ||
expectedError: Not(HaveOccurred()), | ||
}), | ||
Entry("Zero value", | ||
maxUnavailableCase{ | ||
nmstateEnabledNodes: 5, | ||
maxUnavailable: intstr.FromInt(0), | ||
expectedScaledMaxUnavailable: 1, | ||
expectedError: Not(HaveOccurred()), | ||
})) | ||
}) |