github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/grpc/internal/grpctest/example_test.go (about)

     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  
    19  package grpctest_test
    20  
    21  import (
    22  	"testing"
    23  
    24  	"github.com/hxx258456/ccgo/grpc/internal/grpctest"
    25  )
    26  
    27  type s struct {
    28  	i int
    29  }
    30  
    31  func (s *s) Setup(t *testing.T) {
    32  	t.Log("Per-test setup code")
    33  	s.i = 5
    34  }
    35  
    36  func (s *s) TestSomething(t *testing.T) {
    37  	t.Log("TestSomething")
    38  	if s.i != 5 {
    39  		t.Errorf("s.i = %v; want 5", s.i)
    40  	}
    41  	s.i = 3
    42  }
    43  
    44  func (s *s) TestSomethingElse(t *testing.T) {
    45  	t.Log("TestSomethingElse")
    46  	if got, want := s.i%4, 1; got != want {
    47  		t.Errorf("s.i %% 4 = %v; want %v", got, want)
    48  	}
    49  	s.i = 3
    50  }
    51  
    52  func (s *s) Teardown(t *testing.T) {
    53  	t.Log("Per-test teardown code")
    54  	if s.i != 3 {
    55  		t.Fatalf("s.i = %v; want 3", s.i)
    56  	}
    57  }
    58  
    59  func TestExample(t *testing.T) {
    60  	grpctest.RunSubTests(t, &s{})
    61  }