-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
929b956
commit a36ad87
Showing
6 changed files
with
131 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
Copyright (c) Microsoft Corporation. | ||
Licensed under the MIT license. | ||
*/ | ||
|
||
package defaulter | ||
|
||
import ( | ||
"k8s.io/utils/ptr" | ||
|
||
fleetnetv1beta1 "go.goms.io/fleet-networking/api/v1beta1" | ||
) | ||
|
||
// SetDefaultsTrafficManagerBackend sets the default values for TrafficManagerBackend. | ||
func SetDefaultsTrafficManagerBackend(obj *fleetnetv1beta1.TrafficManagerBackend) { | ||
if obj.Spec.Weight == nil { | ||
obj.Spec.Weight = ptr.To(int64(1)) | ||
} | ||
} |
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,57 @@ | ||
/* | ||
Copyright (c) Microsoft Corporation. | ||
Licensed under the MIT license. | ||
*/ | ||
|
||
package defaulter | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"k8s.io/utils/ptr" | ||
|
||
fleetnetv1beta1 "go.goms.io/fleet-networking/api/v1beta1" | ||
) | ||
|
||
func TestSetDefaultsTrafficManagerBackend(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
obj *fleetnetv1beta1.TrafficManagerBackend | ||
want *fleetnetv1beta1.TrafficManagerBackend | ||
}{ | ||
{ | ||
name: "TrafficManagerBackend with nil weight", | ||
obj: &fleetnetv1beta1.TrafficManagerBackend{ | ||
Spec: fleetnetv1beta1.TrafficManagerBackendSpec{}, | ||
}, | ||
want: &fleetnetv1beta1.TrafficManagerBackend{ | ||
Spec: fleetnetv1beta1.TrafficManagerBackendSpec{ | ||
Weight: ptr.To(int64(1)), | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "TrafficManagerBackend with values", | ||
obj: &fleetnetv1beta1.TrafficManagerBackend{ | ||
Spec: fleetnetv1beta1.TrafficManagerBackendSpec{ | ||
Weight: ptr.To(int64(100)), | ||
}, | ||
}, | ||
want: &fleetnetv1beta1.TrafficManagerBackend{ | ||
Spec: fleetnetv1beta1.TrafficManagerBackendSpec{ | ||
Weight: ptr.To(int64(100)), | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
SetDefaultsTrafficManagerBackend(tc.obj) | ||
if diff := cmp.Diff(tc.want, tc.obj); diff != "" { | ||
t.Errorf("SetDefaultsTrafficManagerBackend() mismatch (-want +got):\n%s", diff) | ||
} | ||
}) | ||
} | ||
} |
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
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