github.com/freiheit-com/kuberpult@v1.24.2-0.20240328135542-315d5630abe6/services/cd-service/pkg/repository/testrepository/testrepository.go (about)

     1  /*This file is part of kuberpult.
     2  
     3  Kuberpult is free software: you can redistribute it and/or modify
     4  it under the terms of the Expat(MIT) License as published by
     5  the Free Software Foundation.
     6  
     7  Kuberpult is distributed in the hope that it will be useful,
     8  but WITHOUT ANY WARRANTY; without even the implied warranty of
     9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    10  MIT License for more details.
    11  
    12  You should have received a copy of the MIT License
    13  along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>.
    14  
    15  Copyright 2023 freiheit.com*/
    16  
    17  package testrepository
    18  
    19  import (
    20  	"context"
    21  
    22  	"github.com/freiheit-com/kuberpult/services/cd-service/pkg/notify"
    23  	"github.com/freiheit-com/kuberpult/services/cd-service/pkg/repository"
    24  	git "github.com/libgit2/git2go/v34"
    25  )
    26  
    27  func Failing(err error) repository.Repository {
    28  	//exhaustruct:ignore
    29  	return &failingRepository{err: err}
    30  }
    31  
    32  type failingRepository struct {
    33  	err    error
    34  	notify notify.Notify
    35  }
    36  
    37  func (fr *failingRepository) Apply(ctx context.Context, transformers ...repository.Transformer) error {
    38  	return fr.err
    39  }
    40  
    41  func (fr *failingRepository) Push(ctx context.Context, pushAction func() error) error {
    42  	return fr.err
    43  }
    44  
    45  func (fr *failingRepository) ApplyTransformersInternal(ctx context.Context, transformers ...repository.Transformer) ([]string, *repository.State, []*repository.TransformerResult, *repository.TransformerBatchApplyError) {
    46  	return nil, nil, nil, &repository.TransformerBatchApplyError{TransformerError: fr.err, Index: 0}
    47  }
    48  
    49  func (fr *failingRepository) State() *repository.State {
    50  	//exhaustruct:ignore
    51  	return &repository.State{}
    52  }
    53  
    54  func (fr *failingRepository) StateAt(oid *git.Oid) (*repository.State, error) {
    55  	//exhaustruct:ignore
    56  	return &repository.State{}, nil
    57  }
    58  
    59  func (fr *failingRepository) Notify() *notify.Notify {
    60  	return &fr.notify
    61  }