example_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. *
  3. * Copyright 2019 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package grpctest_test
  19. import (
  20. "testing"
  21. "google.golang.org/grpc/internal/grpctest"
  22. )
  23. type s struct {
  24. i int
  25. }
  26. func (s *s) Setup(t *testing.T) {
  27. t.Log("Per-test setup code")
  28. s.i = 5
  29. }
  30. func (s *s) TestSomething(t *testing.T) {
  31. t.Log("TestSomething")
  32. if s.i != 5 {
  33. t.Errorf("s.i = %v; want 5", s.i)
  34. }
  35. s.i = 3
  36. }
  37. func (s *s) TestSomethingElse(t *testing.T) {
  38. t.Log("TestSomethingElse")
  39. if got, want := s.i%4, 1; got != want {
  40. t.Errorf("s.i %% 4 = %v; want %v", got, want)
  41. }
  42. s.i = 3
  43. }
  44. func (s *s) Teardown(t *testing.T) {
  45. t.Log("Per-test teardown code")
  46. if s.i != 3 {
  47. t.Fatalf("s.i = %v; want 3", s.i)
  48. }
  49. }
  50. func TestExample(t *testing.T) {
  51. grpctest.RunSubTests(t, &s{})
  52. }