...

Source file src/github.com/chaos-mesh/chaos-mesh/controllers/test/types.go

Documentation: github.com/chaos-mesh/chaos-mesh/controllers/test

     1  // Copyright 2021 Chaos Mesh Authors.
     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  //
    15  
    16  package test
    17  
    18  import (
    19  	"context"
    20  	"fmt"
    21  
    22  	"github.com/golang/protobuf/ptypes/empty"
    23  	"google.golang.org/grpc"
    24  
    25  	"github.com/chaos-mesh/chaos-mesh/pkg/chaosdaemon/client"
    26  	chaosdaemon "github.com/chaos-mesh/chaos-mesh/pkg/chaosdaemon/pb"
    27  	"github.com/chaos-mesh/chaos-mesh/pkg/mock"
    28  )
    29  
    30  // Assert *MockChaosDaemonClient implements chaosdaemon.ChaosDaemonClientInterface.
    31  var _ client.ChaosDaemonClientInterface = (*MockChaosDaemonClient)(nil)
    32  
    33  // MockChaosDaemonClient implements ChaosDaemonClientInterface for unit testing
    34  type MockChaosDaemonClient struct{}
    35  
    36  // ExecStressors mocks executing pod stressors on chaos-daemon
    37  func (c *MockChaosDaemonClient) ExecStressors(ctx context.Context, in *chaosdaemon.ExecStressRequest, opts ...grpc.CallOption) (*chaosdaemon.ExecStressResponse, error) {
    38  	return nil, mockError("ExecStressors")
    39  }
    40  
    41  // CancelStressors mocks canceling pod stressors on chaos-daemon
    42  func (c *MockChaosDaemonClient) CancelStressors(ctx context.Context, in *chaosdaemon.CancelStressRequest, opts ...grpc.CallOption) (*empty.Empty, error) {
    43  	return nil, mockError("CancelStressors")
    44  }
    45  
    46  func (c *MockChaosDaemonClient) ContainerGetPid(ctx context.Context, in *chaosdaemon.ContainerRequest, opts ...grpc.CallOption) (*chaosdaemon.ContainerResponse, error) {
    47  	if resp := mock.On("MockContainerGetPidResponse"); resp != nil {
    48  		return resp.(*chaosdaemon.ContainerResponse), nil
    49  	}
    50  	return nil, mockError("ContainerGetPid")
    51  }
    52  
    53  func mockError(name string) error {
    54  	if err := mock.On(fmt.Sprintf("Mock%sError", name)); err != nil {
    55  		return err.(error)
    56  	}
    57  	return nil
    58  }
    59  
    60  func (c *MockChaosDaemonClient) FlushIPSets(ctx context.Context, in *chaosdaemon.IPSetsRequest, opts ...grpc.CallOption) (*empty.Empty, error) {
    61  	return nil, mockError("FlushIPSets")
    62  }
    63  
    64  func (c *MockChaosDaemonClient) SetIptablesChains(ctx context.Context, in *chaosdaemon.IptablesChainsRequest, opts ...grpc.CallOption) (*empty.Empty, error) {
    65  	return nil, mockError("SetIptablesChains")
    66  }
    67  
    68  func (c *MockChaosDaemonClient) SetTimeOffset(ctx context.Context, in *chaosdaemon.TimeRequest, opts ...grpc.CallOption) (*empty.Empty, error) {
    69  	return nil, mockError("SetTimeOffset")
    70  }
    71  
    72  func (c *MockChaosDaemonClient) RecoverTimeOffset(ctx context.Context, in *chaosdaemon.TimeRequest, opts ...grpc.CallOption) (*empty.Empty, error) {
    73  	return nil, mockError("RecoverTimeOffset")
    74  }
    75  
    76  func (c *MockChaosDaemonClient) ContainerKill(ctx context.Context, in *chaosdaemon.ContainerRequest, opts ...grpc.CallOption) (*empty.Empty, error) {
    77  	return nil, mockError("ContainerKill")
    78  }
    79  
    80  func (c *MockChaosDaemonClient) ApplyIOChaos(ctx context.Context, in *chaosdaemon.ApplyIOChaosRequest, opts ...grpc.CallOption) (*chaosdaemon.ApplyIOChaosResponse, error) {
    81  	return nil, mockError("ApplyIOChaos")
    82  }
    83  
    84  func (c *MockChaosDaemonClient) ApplyHttpChaos(ctx context.Context, in *chaosdaemon.ApplyHttpChaosRequest, opts ...grpc.CallOption) (*chaosdaemon.ApplyHttpChaosResponse, error) {
    85  	return nil, mockError("ApplyHttpChaos")
    86  }
    87  
    88  func (c *MockChaosDaemonClient) SetDNSServer(ctx context.Context, in *chaosdaemon.SetDNSServerRequest, opts ...grpc.CallOption) (*empty.Empty, error) {
    89  	return nil, mockError("SetDNSServer")
    90  }
    91  
    92  func (c *MockChaosDaemonClient) SetTcs(ctx context.Context, in *chaosdaemon.TcsRequest, opts ...grpc.CallOption) (*empty.Empty, error) {
    93  	return nil, mockError("SetTcs")
    94  }
    95  
    96  func (c *MockChaosDaemonClient) Close() error {
    97  	return mockError("CloseChaosDaemonClient")
    98  }
    99  
   100  func (c *MockChaosDaemonClient) InstallJVMRules(ctx context.Context, in *chaosdaemon.InstallJVMRulesRequest, opts ...grpc.CallOption) (*empty.Empty, error) {
   101  	return nil, mockError("InstallJVMRules")
   102  }
   103  
   104  func (c *MockChaosDaemonClient) UninstallJVMRules(ctx context.Context, in *chaosdaemon.UninstallJVMRulesRequest, opts ...grpc.CallOption) (*empty.Empty, error) {
   105  	return nil, mockError("UninstallJVMRules")
   106  }
   107  
   108  func (c *MockChaosDaemonClient) ApplyBlockChaos(ctx context.Context, req *chaosdaemon.ApplyBlockChaosRequest, opts ...grpc.CallOption) (*chaosdaemon.ApplyBlockChaosResponse, error) {
   109  	return nil, mockError("ApplyBlockChaosRequest")
   110  }
   111  
   112  func (c *MockChaosDaemonClient) RecoverBlockChaos(ctx context.Context, req *chaosdaemon.RecoverBlockChaosRequest, opts ...grpc.CallOption) (*empty.Empty, error) {
   113  	return &empty.Empty{}, nil
   114  }
   115