Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

80 righe
1.8 KiB

  1. // Copyright 2016 Google LLC
  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 testutil
  15. import (
  16. "testing"
  17. grpc "google.golang.org/grpc"
  18. "google.golang.org/grpc/codes"
  19. )
  20. func TestNewServer(t *testing.T) {
  21. srv, err := NewServer()
  22. if err != nil {
  23. t.Fatal(err)
  24. }
  25. defer srv.Close()
  26. srv.Start()
  27. conn, err := grpc.Dial(srv.Addr, grpc.WithInsecure())
  28. if err != nil {
  29. t.Fatal(err)
  30. }
  31. defer conn.Close()
  32. }
  33. func TestPageBounds(t *testing.T) {
  34. const length = 10
  35. for _, test := range []struct {
  36. size int
  37. tok string
  38. wantFrom int
  39. wantTo int
  40. wantTok string
  41. }{
  42. {5, "",
  43. 0, 5, "5"},
  44. {11, "",
  45. 0, 10, ""},
  46. {5, "2",
  47. 2, 7, "7"},
  48. {5, "8",
  49. 8, 10, ""},
  50. {11, "8",
  51. 8, 10, ""},
  52. {1, "11",
  53. 10, 10, ""},
  54. } {
  55. gotFrom, gotTo, gotTok, err := PageBounds(test.size, test.tok, length)
  56. if err != nil {
  57. t.Fatal(err)
  58. }
  59. if got, want := gotFrom, test.wantFrom; got != want {
  60. t.Errorf("%+v: from: got %d, want %d", test, got, want)
  61. }
  62. if got, want := gotTo, test.wantTo; got != want {
  63. t.Errorf("%+v: to: got %d, want %d", test, got, want)
  64. }
  65. if got, want := gotTok, test.wantTok; got != want {
  66. t.Errorf("%+v: got %q, want %q", test, got, want)
  67. }
  68. }
  69. _, _, _, err := PageBounds(4, "xyz", 5)
  70. if grpc.Code(err) != codes.InvalidArgument {
  71. t.Errorf("want invalid argument, got <%v>", err)
  72. }
  73. }