github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/pkg/abap/aakaas/aakUtils_mock.go (about)

     1  //go:build !release
     2  // +build !release
     3  
     4  package aakaas
     5  
     6  import (
     7  	"time"
     8  
     9  	abapbuild "github.com/SAP/jenkins-library/pkg/abap/build"
    10  	"github.com/SAP/jenkins-library/pkg/abaputils"
    11  	"github.com/SAP/jenkins-library/pkg/mock"
    12  	"github.com/SAP/jenkins-library/pkg/piperutils"
    13  	"github.com/pkg/errors"
    14  )
    15  
    16  type AakBundleMock struct {
    17  	*mock.ExecMockRunner
    18  	*abaputils.ClientMock
    19  	*mock.FilesMock
    20  	maxRuntime time.Duration
    21  }
    22  
    23  func NewAakBundleMock() *AakBundleMock {
    24  	utils := AakBundleMock{
    25  		ExecMockRunner: &mock.ExecMockRunner{},
    26  		ClientMock:     &abaputils.ClientMock{},
    27  		maxRuntime:     1 * time.Second,
    28  		FilesMock:      &mock.FilesMock{},
    29  	}
    30  	return &utils
    31  }
    32  
    33  func (bundle *AakBundleMock) GetUtils() AakUtils {
    34  	return bundle
    35  }
    36  
    37  func (bundle *AakBundleMock) GetMaxRuntime() time.Duration {
    38  	return bundle.maxRuntime
    39  }
    40  
    41  func (bundle *AakBundleMock) SetMaxRuntime(maxRuntime time.Duration) {
    42  	bundle.maxRuntime = maxRuntime
    43  }
    44  
    45  func (bundle *AakBundleMock) GetPollingInterval() time.Duration {
    46  	return 1 * time.Microsecond
    47  }
    48  
    49  func (bundle *AakBundleMock) SetBodyList(bodyList []string) {
    50  	bundle.ClientMock.Body = ""
    51  	bundle.ClientMock.BodyList = bodyList
    52  }
    53  
    54  func (bundle *AakBundleMock) SetBody(body string) {
    55  	bundle.ClientMock.Body = body
    56  	bundle.ClientMock.BodyList = []string{}
    57  }
    58  
    59  func (bundle *AakBundleMock) SetErrorInsteadOfDumpToTrue() {
    60  	bundle.ClientMock.ErrorInsteadOfDump = true
    61  }
    62  
    63  func (bundle *AakBundleMock) SetError(errorText string) {
    64  	bundle.ClientMock.Error = errors.New(errorText)
    65  }
    66  
    67  func (bundle *AakBundleMock) ReadAddonDescriptor(FileName string) (abaputils.AddonDescriptor, error) {
    68  	var addonDescriptor abaputils.AddonDescriptor
    69  	var err error
    70  	switch FileName {
    71  	case "success":
    72  		{
    73  			addonDescriptor = abaputils.AddonDescriptor{
    74  				AddonProduct:     "/DRNMSPC/PRD01",
    75  				AddonVersionYAML: "3.2.1",
    76  				Repositories: []abaputils.Repository{
    77  					{
    78  						Name:        "/DRNMSPC/COMP01",
    79  						VersionYAML: "1.2.3",
    80  						CommitID:    "HUGO1234",
    81  					},
    82  				},
    83  			}
    84  		}
    85  	case "noCommitID":
    86  		{
    87  			addonDescriptor = abaputils.AddonDescriptor{
    88  				AddonProduct:     "/DRNMSPC/PRD01",
    89  				AddonVersionYAML: "3.2.1",
    90  				Repositories: []abaputils.Repository{
    91  					{
    92  						Name:        "/DRNMSPC/COMP01",
    93  						VersionYAML: "1.2.3",
    94  					},
    95  				},
    96  			}
    97  		}
    98  	case "failing":
    99  		{
   100  			err = errors.New("error in ReadAddonDescriptor")
   101  		}
   102  	}
   103  	return addonDescriptor, err
   104  }
   105  
   106  // *****************************other client mock *******************************
   107  type AakBundleMockNewMC struct {
   108  	*mock.ExecMockRunner
   109  	*abapbuild.MockClient
   110  	*piperutils.Files
   111  	maxRuntime time.Duration
   112  }
   113  
   114  func NewAakBundleMockNewMC(mC *abapbuild.MockClient) *AakBundleMockNewMC {
   115  	utils := AakBundleMockNewMC{
   116  		ExecMockRunner: &mock.ExecMockRunner{},
   117  		MockClient:     mC,
   118  		maxRuntime:     1 * time.Second,
   119  	}
   120  	return &utils
   121  }
   122  
   123  func (bundle *AakBundleMockNewMC) GetUtils() AakUtils {
   124  	return bundle
   125  }
   126  
   127  func (bundle *AakBundleMockNewMC) GetMaxRuntime() time.Duration {
   128  	return bundle.maxRuntime
   129  }
   130  
   131  func (bundle *AakBundleMockNewMC) GetPollingInterval() time.Duration {
   132  	return 1 * time.Microsecond
   133  }
   134  
   135  func (bundle *AakBundleMockNewMC) ReadAddonDescriptor(FileName string) (abaputils.AddonDescriptor, error) {
   136  	var addonDescriptor abaputils.AddonDescriptor
   137  	err := errors.New("don't use this")
   138  	return addonDescriptor, err
   139  }