-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a method to return consistent string representation of the structs and add usit tests for both ToString()'s. Signed-off-by: Shereen Haj <[email protected]>
- Loading branch information
Showing
3 changed files
with
104 additions
and
7 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
96 changes: 96 additions & 0 deletions
96
api/numaresourcesoperator/v1/numaresourcesoperator_types_test.go
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,96 @@ | ||
package v1 | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestNodeGroupConfigToString(t *testing.T) { | ||
defaultConfig := DefaultNodeGroupConfig() | ||
//nilValue := NodeGroup{} | ||
//non default config fields values | ||
d, err := time.ParseDuration("33s") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
period := metav1.Duration{ | ||
Duration: d, | ||
} | ||
pfpMode := PodsFingerprintingDisabled | ||
refMode := InfoRefreshEvents | ||
rteMode := InfoRefreshPauseEnabled | ||
|
||
testcases := []struct { | ||
name string | ||
input NodeGroupConfig | ||
expected string | ||
}{ | ||
{ | ||
name: "empty fields should reflect default values", | ||
input: NodeGroupConfig{}, | ||
expected: defaultConfig.ToString(), | ||
}, | ||
{ | ||
name: "full", | ||
input: NodeGroupConfig{ | ||
PodsFingerprinting: &pfpMode, | ||
InfoRefreshMode: &refMode, | ||
InfoRefreshPeriod: &period, | ||
InfoRefreshPause: &rteMode, | ||
Tolerations: []corev1.Toleration{ | ||
{ | ||
Key: "foo", | ||
Value: "1", | ||
Effect: corev1.TaintEffectNoSchedule, | ||
}, | ||
}, | ||
}, | ||
expected: "PodsFingerprinting mode: Disabled InfoRefreshMode: Events InfoRefreshPeriod: {33s} InfoRefreshPause: Enabled Tolerations: [{Key:foo Operator: Value:1 Effect:NoSchedule TolerationSeconds:<nil>}]", | ||
}, | ||
} | ||
|
||
for _, tc := range testcases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
actual := tc.input.ToString() | ||
if actual != tc.expected { | ||
t.Errorf("expected: %s, actual: %s", tc.expected, actual) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestNodeGroupToString(t *testing.T) { | ||
pfpMode := PodsFingerprintingDisabled | ||
refMode := InfoRefreshEvents | ||
pn := "pn" | ||
|
||
testcases := []struct { | ||
name string | ||
input NodeGroup | ||
expected string | ||
}{ | ||
{ | ||
name: "empty fields should reflect default values", | ||
input: NodeGroup{ | ||
MachineConfigPoolSelector: nil, | ||
Config: &NodeGroupConfig{ | ||
PodsFingerprinting: &pfpMode, | ||
InfoRefreshMode: &refMode, | ||
}, | ||
PoolName: &pn, // although not allowed more than a specifier but we still need to display and here is not the right place to perform validations | ||
}, | ||
expected: "PoolName: pn MachineConfigPoolSelector: nil Config: PodsFingerprinting mode: Disabled InfoRefreshMode: Events InfoRefreshPeriod: {10s} InfoRefreshPause: Disabled Tolerations: []", | ||
}, | ||
} | ||
for _, tc := range testcases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
actual := tc.input.ToString() | ||
if actual != tc.expected { | ||
t.Errorf("expected: %s, actual: %s", tc.expected, actual) | ||
} | ||
}) | ||
} | ||
} |
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