onsi / ginkgo

A Modern Testing Framework for Go
http://onsi.github.io/ginkgo/
MIT License
8.33k stars 659 forks source link

"Weird Things" happen if the actual/expected values look like format strings #10

Closed xoebus closed 11 years ago

xoebus commented 11 years ago

I'm writing a test to make sure that one of my methods makes the correct request to a web server. It uses a lot of query parameters to do this which unfortunately look an awful lot like format strings.

A snippet of the code is below:

BeforeEach(func() {
    request = AddBookmarkRequest{
        URL: "http://google.com",
        Title: "Google Search",
        Description: "Seems like a cool underground site!",
        Tags: []string{"search", "mail", "maps"},
        CreatedAt: time.Now(),
        Replace: true,
        Shared: false,
    }
})

It("makes a request to add a bookmark", func() {
    client.AddBookmark(request)

    urlParams := url.Values{}
    urlParams.Set("format", "json")
    urlParams.Set("auth_token", "user:token")

    urlParams.Set("url", request.URL)
    urlParams.Set("description", request.Title)
    urlParams.Set("extended", request.Description)
    urlParams.Set("tags", strings.Join(request.Tags, ","))
    urlParams.Set("dt", request.CreatedAt.Format(time.RFC3339))
    urlParams.Set("replace", "yes")
    urlParams.Set("shared", "no")

    lastAddUrl := fmt.Sprintf("https://api.pinboard.in/v1/posts/add?%s", urlParams.Encode())
    Expect(httpClient.LastURLRequested).To(Equal(lastAddUrl))
})

lastAddUrl looks something like this at the end of this:

auth_token=user%3Atoken&description=Google+Search&dt=2013-10-20T22%3A13%3A13%2B01%3A00&extended=Seems+like+a+cool+underground+site%21&format=json&replace=yes&shared=no&tags=search%2Cmail%2Cmaps&url=http%3A%2F%2Fgoogle.com

Ginkgo reports the failure like so:

screenshot 2013-10-20 22 23 33

Looks (MISSING) funky.

onsi commented 11 years ago

:) nice... i'll take a look!

On Sun, Oct 20, 2013 at 2:25 PM, Chris Brown notifications@github.comwrote:

I'm writing a test to make sure that one of my methods makes the correct request to a web server. It uses a lot of query parameters to do this which unfortunately look an awful lot like format strings.

A snippet of the code is below:

Context("with a valid bookmark request", func() {var request AddBookmarkRequest BeforeEach(func() { request = AddBookmarkRequest{ URL: "http://google.com", Title: "Google Search", Description: "Seems like a cool underground site!", Tags: []string{"search", "mail", "maps"}, CreatedAt: time.Now(), Replace: true, Shared: false, }}) It("makes a request to add a bookmark", func() { client.AddBookmark(request)

urlParams := url.Values{}
urlParams.Set("format", "json")
urlParams.Set("auth_token", "user:token")

urlParams.Set("url", request.URL)
urlParams.Set("description", request.Title)
urlParams.Set("extended", request.Description)
urlParams.Set("tags", strings.Join(request.Tags, ","))
urlParams.Set("dt", request.CreatedAt.Format(time.RFC3339))
urlParams.Set("replace", "yes")
urlParams.Set("shared", "no")

lastAddUrl := fmt.Sprintf("https://api.pinboard.in/v1/posts/add?%s", urlParams.Encode())
Expect(httpClient.LastURLRequested).To(Equal(lastAddUrl))})

lastAddUrl looks something like this at the end of this:

auth_token=user%3Atoken&description=Google+Search&dt=2013-10-20T22%3A13%3A13%2B01%3A00&extended=Seems+like+a+cool+underground+site%21&format=json&replace=yes&shared=no&tags=search%2Cmail%2Cmaps&url=http%3A%2F%2Fgoogle.com

Ginkgo reports the failure like so:

[image: screenshot 2013-10-20 22 23 33]https://f.cloud.github.com/assets/38814/1368985/f70cdeb8-39cd-11e3-8f65-ae4320bb0b8e.png

Looks (MISSING) funky.

— Reply to this email directly or view it on GitHubhttps://github.com/onsi/ginkgo/issues/10 .

onsi commented 11 years ago

Should be fixed now Chris. Pull the latest and lemme know if you still have issues.

xoebus commented 11 years ago

Still seeing the problem here on master.

screenshot 2013-10-22 15 24 39

Reproducible by checking out xoebus/kingpin@a3ae4400dc8fd0b91f1b8aaa616083391158d3da and changing line 56 of add_bookmark_test.go so that it will fail.

onsi commented 11 years ago

actually, looks good on master for me... odd -- can you try again? screen shot 2013-10-23 at 1 24 05 pm

xoebus commented 11 years ago

Apologies, I'd updated the code but not the ginkgo executable. The issue is indeed fixed - thank you!

onsi commented 11 years ago

Hooray! :)

On Oct 24, 2013, at 7:35 AM, Chris Brown notifications@github.com wrote:

Apologies, I'd updated the code but not the ginkgo executable. The issue is indeed fixed - thank you!

— Reply to this email directly or view it on GitHub.