github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/core/service/stub_service_test.go (about)

     1  /*
     2   * Copyright (C) 2018 The "MysteriumNetwork/node" Authors.
     3   *
     4   * This program is free software: you can redistribute it and/or modify
     5   * it under the terms of the GNU General Public License as published by
     6   * the Free Software Foundation, either version 3 of the License, or
     7   * (at your option) any later version.
     8   *
     9   * This program is distributed in the hope that it will be useful,
    10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12   * GNU General Public License for more details.
    13   *
    14   * You should have received a copy of the GNU General Public License
    15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16   */
    17  
    18  package service
    19  
    20  import (
    21  	"encoding/json"
    22  	"net"
    23  	"sync"
    24  
    25  	"github.com/mysteriumnetwork/node/identity"
    26  	"github.com/mysteriumnetwork/node/market"
    27  )
    28  
    29  var _ Service = &serviceFake{}
    30  
    31  type serviceFake struct {
    32  	mockProcess        chan struct{}
    33  	onStartReturnError error
    34  }
    35  
    36  func (service *serviceFake) Serve(instance *Instance) error {
    37  	if service.mockProcess != nil {
    38  		for range service.mockProcess {
    39  		}
    40  	}
    41  	return service.onStartReturnError
    42  }
    43  
    44  func (service *serviceFake) Stop() error {
    45  	if service.mockProcess != nil {
    46  		close(service.mockProcess)
    47  	}
    48  	return nil
    49  }
    50  
    51  func (service *serviceFake) GetType() string {
    52  	return "fake"
    53  }
    54  
    55  func (service *serviceFake) ProvideConfig(_ string, _ json.RawMessage, _ *net.UDPConn) (*ConfigParams, error) {
    56  	return &ConfigParams{}, nil
    57  }
    58  
    59  type mockDiscovery struct {
    60  	wg sync.WaitGroup
    61  }
    62  
    63  func (mds *mockDiscovery) Start(ownIdentity identity.Identity, proposal func() market.ServiceProposal) {
    64  	mds.wg.Add(1)
    65  }
    66  
    67  func (mds *mockDiscovery) Stop() {
    68  	mds.wg.Done()
    69  }
    70  
    71  func (mds *mockDiscovery) Wait() {
    72  	mds.wg.Wait()
    73  }
    74  
    75  // MockDiscoveryFactoryFunc returns a discovery factory which in turn returns the discovery service.
    76  func MockDiscoveryFactoryFunc(ds Discovery) DiscoveryFactory {
    77  	return func() Discovery {
    78  		return ds
    79  	}
    80  }