您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

51 行
1.5 KiB

  1. /*
  2. Copyright 2017 Google LLC
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package spanner
  14. import (
  15. "strings"
  16. "testing"
  17. )
  18. // Test validDatabaseName()
  19. func TestValidDatabaseName(t *testing.T) {
  20. validDbURI := "projects/spanner-cloud-test/instances/foo/databases/foodb"
  21. invalidDbUris := []string{
  22. // Completely wrong DB URI.
  23. "foobarDB",
  24. // Project ID contains "/".
  25. "projects/spanner-cloud/test/instances/foo/databases/foodb",
  26. // No instance ID.
  27. "projects/spanner-cloud-test/instances//databases/foodb",
  28. }
  29. if err := validDatabaseName(validDbURI); err != nil {
  30. t.Errorf("validateDatabaseName(%q) = %v, want nil", validDbURI, err)
  31. }
  32. for _, d := range invalidDbUris {
  33. if err, wantErr := validDatabaseName(d), "should conform to pattern"; !strings.Contains(err.Error(), wantErr) {
  34. t.Errorf("validateDatabaseName(%q) = %q, want error pattern %q", validDbURI, err, wantErr)
  35. }
  36. }
  37. }
  38. func TestReadOnlyTransactionClose(t *testing.T) {
  39. // Closing a ReadOnlyTransaction shouldn't panic.
  40. c := &Client{}
  41. tx := c.ReadOnlyTransaction()
  42. tx.Close()
  43. }