github.com/msales/pkg/v3@v3.24.0/mocks/mocks.go (about) 1 package mocks 2 3 import ( 4 "fmt" 5 6 "github.com/msales/pkg/v3/clix" 7 "github.com/stretchr/testify/mock" 8 "gopkg.in/urfave/cli.v1" 9 ) 10 11 type Logger struct { 12 mock.Mock 13 } 14 15 func (m *Logger) Debug(msg string, ctx ...interface{}) { 16 args := []interface{}{msg} 17 args = append(args, ctx...) 18 m.Called(args...) 19 } 20 21 func (m *Logger) Info(msg string, ctx ...interface{}) { 22 args := []interface{}{msg} 23 args = append(args, ctx...) 24 m.Called(args...) 25 } 26 27 func (m *Logger) Error(msg string, ctx ...interface{}) { 28 args := []interface{}{msg} 29 args = append(args, ctx...) 30 m.Called(args...) 31 } 32 33 // InitContext initializes clix context to be passed to existing application factories. 34 func InitContext(args map[string]string, flags []cli.Flag) *clix.Context { 35 cCtx := InitCliContext(args, flags) 36 37 ctx, err := clix.NewContext(cCtx) 38 if err != nil { 39 panic(err) 40 } 41 42 return ctx 43 } 44 45 func InitCliContext(args map[string]string, flags []cli.Flag) *cli.Context { 46 cliArgs := []string{"test"} 47 for k, v := range args { 48 cliArgs = append(cliArgs, fmt.Sprintf("-%s=%s", k, v)) 49 } 50 51 var cCtx *cli.Context 52 app := cli.NewApp() 53 app.Flags = flags 54 app.Action = func(c *cli.Context) { cCtx = c } 55 err := app.Run(cliArgs) 56 if err != nil { 57 panic(err) 58 } 59 60 return cCtx 61 }