-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(kuma-cp): validate the bandwidth strictly (#10371)
* fix(kuma-cp): validate the bandwidth strictly Signed-off-by: spacewander <[email protected]> * Update UPGRADE.md Signed-off-by: Krzysztof Słonka <[email protected]> --------- Signed-off-by: spacewander <[email protected]> Signed-off-by: Krzysztof Słonka <[email protected]> Co-authored-by: Krzysztof Słonka <[email protected]>
- Loading branch information
1 parent
d0fd4e0
commit ba31b94
Showing
5 changed files
with
76 additions
and
4 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
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,68 @@ | ||
package validators | ||
|
||
import "testing" | ||
|
||
func TestValidateBandwidth(t *testing.T) { | ||
path := []string{"path"} | ||
|
||
tests := []struct { | ||
name string | ||
input string | ||
err string | ||
}{ | ||
{ | ||
name: "sanity", | ||
input: "1kbps", | ||
}, | ||
{ | ||
name: "without number", | ||
input: "Mbps", | ||
}, | ||
{ | ||
name: "not exact match", | ||
input: "1bpsp", | ||
err: func() string { | ||
e := &ValidationError{} | ||
e.AddViolationAt(path, MustHaveBPSUnit) | ||
return e.Error() | ||
}(), | ||
}, | ||
{ | ||
name: "bps is not allowed", | ||
input: "1bps", | ||
err: func() string { | ||
e := &ValidationError{} | ||
e.AddViolationAt(path, MustHaveBPSUnit) | ||
return e.Error() | ||
}(), | ||
}, | ||
{ | ||
name: "float point number is not supported", | ||
input: "0.1kbps", | ||
err: func() string { | ||
e := &ValidationError{} | ||
e.AddViolationAt(path, MustHaveBPSUnit) | ||
return e.Error() | ||
}(), | ||
}, | ||
{ | ||
name: "not defined", | ||
input: "", | ||
err: func() string { | ||
e := &ValidationError{} | ||
e.AddViolationAt(path, MustBeDefined) | ||
return e.Error() | ||
}(), | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
actual := ValidateBandwidth(path, tt.input) | ||
if actual.Error() != tt.err { | ||
t.Errorf("ValidateBandwidth(%s): expected %s, actual %s", tt.input, tt.err, 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
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