kelveny / mockcompose

mockcompose generates mocking implementation for Go classes, interfaces and functions
MIT License
15 stars 2 forks source link

Mocking function from imported package #2

Closed Svampen closed 3 years ago

Svampen commented 3 years ago

Hi

I'm trying to figure out if mockcompose supports my scenario. Here is a cut out of the package my code is using:

package secret

import (
  "regexp"
)

type SecretData struct {
  Data []byte
  Name string
}

func GetSecrets(projectId string, secretsRegexp *regexp.Regexp) ([]SecretData, error) {
  ...
}

Here is a cut out of my code:

package foo

import (
  "github.com/.../secret"
  "regexp"
)

func Bar() error {
  secretsData, err := secret.GetSecrets("projectId", regexp.MustCompile(`-\w{4}$`))
  ...
}

I'm trying to mock secret.GetSecrets by using mockcompose and I tried //go:generate mockcompose -v -n mockSecret -p github.com/.../secret -mock GetSecrets but the generated file will then be missing import for regexp and don't have the SecretData struct so it doesn't compile. I could fixed that after generating the file but I don't think that's the point with mockcompose 😃

Any help in how I should continue (if currently possible) would be very much appreciate as I really like your package, keep up the good work on it!

kelveny commented 3 years ago

I could fixed that after generating the file but I don't think that's the point with mockcompose

Yeah, this will against the point of mockcompose.

Why did you close this issue? I'll check to see if I can fix it

kelveny commented 3 years ago

@Svampen I fixed the issue that you reported in v0.1.9

kelveny commented 3 months ago

@Svampen I fine tuned the implementation this weekend and also updated the README.md. Please find if this is helpful to your use case.