I would like to find a better way to mock my constructor. The constructor itself already returns an interface, thanks to which I can mock its functions in tests.

//main.go
var createSSMClient = ssm.CreateClient // my constructor

func main() {
    _, _, _ = getSecrets(context.Background())
}

func getParams(ctx context.Context) (string, string, error) {
    ssmClient, err := createSSMClient(ctx)
    if err != nil {
        return "", "", err
    }

    param1, param2 := ssmClient.GetParams()
    ...
}


//constructor.go
func CreateClient(ctx context.Context) (SSMInterface, error) {
    ...
}

However, when testing main functions, I have to do something like this in each test:

//main_test.go
func TestMain() {
    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            newSSMClient = MyMockConstructor()
            ...
        }
    }
}

It does not look good.

Is there a way to mock the constructor via an interface?

(I create a mock using mockery.)