Skip to content

Ability to have a single mock implement multiple interfaces #81

@jpopadak

Description

@jpopadak

For some Go code, a single struct might implement multiple interfaces.

For example:

type IType1 interface {
   Method1() error
}

type IType2 interface {
   Method2() string
}

func DoWork(input IType1) error {
   if err := input.Method1(); err != nil {
      return err
   }
   if i2, ok := input.(IType2); !ok {
      return error.New("does not implement IType2")
   }

   fmt.Println(i2.Method2())
   return nil
}

This helps with plug and play code, where you are accepting outside objects to execute logic on more than one interface.

Suggested generate command can be:
pegomock generate github.com/path/to/pkg IType1 github.com/path/to/other/pkg IType2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions