namespace_test.go 888 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2014 Google Inc. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package appengine
  5. import (
  6. "testing"
  7. "golang.org/x/net/context"
  8. )
  9. func TestNamespaceValidity(t *testing.T) {
  10. testCases := []struct {
  11. namespace string
  12. ok bool
  13. }{
  14. // data from Python's namespace_manager_test.py
  15. {"", true},
  16. {"__a.namespace.123__", true},
  17. {"-_A....NAMESPACE-_", true},
  18. {"-", true},
  19. {".", true},
  20. {".-", true},
  21. {"?", false},
  22. {"+", false},
  23. {"!", false},
  24. {" ", false},
  25. }
  26. for _, tc := range testCases {
  27. _, err := Namespace(context.Background(), tc.namespace)
  28. if err == nil && !tc.ok {
  29. t.Errorf("Namespace %q should be rejected, but wasn't", tc.namespace)
  30. } else if err != nil && tc.ok {
  31. t.Errorf("Namespace %q should be accepted, but wasn't", tc.namespace)
  32. }
  33. }
  34. }