github.com/webdestroya/awsmocker@v0.2.6/mocktest_test.go (about)

     1  package awsmocker_test
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/webdestroya/awsmocker"
     7  )
     8  
     9  // A fake testing.T object used for testing the test
    10  type TestingMock struct {
    11  	og awsmocker.TestingT
    12  
    13  	failed bool
    14  
    15  	errored      bool
    16  	logged       bool
    17  	helperCalled bool
    18  
    19  	errorMessages []string
    20  	logMessages   []string
    21  
    22  	envvars map[string]string
    23  }
    24  
    25  func NewTestingMock(og awsmocker.TestingT) *TestingMock {
    26  	return &TestingMock{
    27  		og:            og,
    28  		envvars:       make(map[string]string),
    29  		logMessages:   make([]string, 0),
    30  		errorMessages: make([]string, 0),
    31  	}
    32  }
    33  
    34  func (tm *TestingMock) Cleanup(f func()) {
    35  	tm.og.Cleanup(f)
    36  }
    37  
    38  func (tm *TestingMock) Errorf(f string, args ...any) {
    39  	tm.errored = true
    40  	tm.errorMessages = append(tm.errorMessages, fmt.Sprintf(f, args...))
    41  }
    42  
    43  func (tm *TestingMock) Logf(f string, args ...any) {
    44  	tm.logged = true
    45  	tm.logMessages = append(tm.logMessages, fmt.Sprintf(f, args...))
    46  }
    47  
    48  func (tm *TestingMock) Fail() {
    49  	tm.failed = true
    50  }
    51  
    52  func (tm *TestingMock) Setenv(k, v string) {
    53  	tm.envvars[k] = v
    54  	tm.og.Setenv(k, v)
    55  }
    56  
    57  func (tm *TestingMock) TempDir() string {
    58  	return tm.og.TempDir()
    59  }
    60  
    61  func (tm *TestingMock) Helper() {
    62  	tm.helperCalled = true
    63  	if h, ok := tm.og.(awsmocker.THelper); ok {
    64  		h.Helper()
    65  	}
    66  }
    67  
    68  // interface adherence
    69  var _ = (awsmocker.TestingT)(&TestingMock{})
    70  var _ = (awsmocker.THelper)(&TestingMock{})