plugins_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package factory
  15. import (
  16. "testing"
  17. )
  18. func TestAlgorithmNameValidation(t *testing.T) {
  19. namesShouldValidate := []string{
  20. "1SomeAlgo1rithm",
  21. "someAlgor-ithm1",
  22. }
  23. namesShouldNotValidate := []string{
  24. "-SomeAlgorithm",
  25. "SomeAlgorithm-",
  26. "Some,Alg:orithm",
  27. }
  28. for _, name := range namesShouldValidate {
  29. if !validName.MatchString(name) {
  30. t.Errorf("%v should be a valid algorithm name but is not valid.", name)
  31. }
  32. }
  33. for _, name := range namesShouldNotValidate {
  34. if validName.MatchString(name) {
  35. t.Errorf("%v should be an invalid algorithm name but is valid", name)
  36. }
  37. }
  38. }