Skip to content

Commit d67ae08

Browse files
khenidakliggitt
andauthored
minor update to api_changes to highlight gate on/off scenario (#5521)
* minor update to api_changes to highlight gate on/off scenario * Update contributors/devel/sig-architecture/api_changes.md Co-authored-by: Jordan Liggitt <[email protected]> * Update contributors/devel/sig-architecture/api_changes.md Co-authored-by: Jordan Liggitt <[email protected]> * Update contributors/devel/sig-architecture/api_changes.md Co-authored-by: Jordan Liggitt <[email protected]> * Update contributors/devel/sig-architecture/api_changes.md Co-authored-by: Jordan Liggitt <[email protected]> * Update contributors/devel/sig-architecture/api_changes.md Co-authored-by: Jordan Liggitt <[email protected]> Co-authored-by: Jordan Liggitt <[email protected]>
1 parent 27d2698 commit d67ae08

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

contributors/devel/sig-architecture/api_changes.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,38 @@ The recommended place to do this is in the REST storage strategy's PrepareForCre
955955
}
956956
```
957957
958-
4. In validation, validate the field if present:
958+
4. To future-proof your API testing, when testing with feature gate on and off, ensure that the gate is deliberately set as desired. Don't assume that gate is off or on. As your feature
959+
progresses from `alpha` to `beta` and then `stable` the feature might be turned on or off by default across the entire code base. The below example
960+
provides some details
961+
962+
```go
963+
func TestAPI(t *testing.T){
964+
testCases:= []struct{
965+
// ... test definition ...
966+
}{
967+
{
968+
// .. test case ..
969+
},
970+
{
971+
// ... test case ..
972+
},
973+
}
974+
975+
for _, testCase := range testCases{
976+
t.Run("..name...", func(t *testing.T){
977+
// run with gate on
978+
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features. Frobber2D, true)()
979+
// ... test logic ...
980+
})
981+
t.Run("..name...", func(t *testing.T){
982+
// run with gate off, *do not assume it is off by default*
983+
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features. Frobber2D, false)()
984+
// ... test gate-off testing logic logic ...
985+
})
986+
}
987+
```
988+
989+
5. In validation, validate the field if present:
959990

960991
```go
961992
func ValidateFrobber(f *api.Frobber, fldPath *field.Path) field.ErrorList {

0 commit comments

Comments
 (0)