25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

64 satır
1.4 KiB

  1. /*
  2. *
  3. * Copyright 2018 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
  19. import (
  20. "reflect"
  21. "testing"
  22. )
  23. type tRunST struct {
  24. setup, test, teardown bool
  25. }
  26. func (t *tRunST) Setup(*testing.T) {
  27. t.setup = true
  28. }
  29. func (t *tRunST) TestSubTest(*testing.T) {
  30. t.test = true
  31. }
  32. func (t *tRunST) Teardown(*testing.T) {
  33. t.teardown = true
  34. }
  35. func TestRunSubTests(t *testing.T) {
  36. x := &tRunST{}
  37. RunSubTests(t, x)
  38. if want := (&tRunST{setup: true, test: true, teardown: true}); !reflect.DeepEqual(x, want) {
  39. t.Fatalf("x = %v; want all fields true", x)
  40. }
  41. }
  42. type tNoST struct {
  43. test bool
  44. }
  45. func (t *tNoST) TestSubTest(*testing.T) {
  46. t.test = true
  47. }
  48. func TestNoSetupOrTeardown(t *testing.T) {
  49. // Ensures nothing panics or fails if Setup/Teardown are omitted.
  50. x := &tNoST{}
  51. RunSubTests(t, x)
  52. if want := (&tNoST{test: true}); !reflect.DeepEqual(x, want) {
  53. t.Fatalf("x = %v; want %v", x, want)
  54. }
  55. }