FAQ
Hi guys!

I'm pretty new to go, and I have a problem with testing a simple file that
implements a command using cli.go package.

For readability, my app is like this:

//in main
app := cli.NewApp()
app.Action = initiateCommand(sdk, &loggerSrv)
[...]
app.Run(os.Args)

and my function:

func initiateCommand(sdk SDK, logger LoggerInterface) func(c *cli.Context) {
return func(c *cli.Context) {
               ID := c.String("id")
               [...]
         }
}

So, my question is... how can I test this inner function?

my (very simple test class) for the moment is:

func TestInitiateCommandReturnsErrorOnIDNotProvided(t *testing.T) {
mockSDK := MockSDK{}

loggerSrv := &MockLoggerService{}

args := []string{"id", "2"}
os.Args = append(os.Args, args...)

resp := initiateSend(mockSDK, loggerSrv)
[...]
}

  but it seems that the test is going just on the outer function, without
testing code inside the inner one...

Thanks for reading me for now!

Marco



--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Tamás Gulácsi at Feb 12, 2016 at 9:08 pm
    app.Run does call the returned function, so do as, too: resp(ctx)

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedFeb 12, '16 at 4:07p
activeFeb 12, '16 at 9:08p
posts2
users2
websitegolang.org

2 users in discussion

Marco: 1 post Tamás Gulácsi: 1 post

People

Translate

site design / logo © 2021 Grokbase