Skip to content

Change example_gh_test.go to package gh_test #87

Closed

Description

@mntlty

Being in the same package, the example test file can refer to functions such as RESTClient and Exec as local, as opposed to gh.RESTClient and gh.Exec. This presents some challenges:

  • the examples cannot be copied as is
  • it can be confusing to Go newcomers, who may not be familiar with how to solve the issue

I would like to suggest changing the package of the example file and updating the functions in it.

Activity

  1. mntlty commented on Nov 4, 2022

    @mntlty
    ContributorAuthor

    A concrete implementation is in 114787b in case this makes sense to others

  2. mislav commented on Nov 5, 2022

    @mislav
    Contributor

    Thanks for bringing this up. Will the examples still get rendered of on the main page of generated docs? If so, I'm in favor of this 👍

  3. mntlty commented on Nov 7, 2022

    @mntlty
    ContributorAuthor

    @mislav I ran godoc -http=:6060 on the example branch, and it renders the examples while adding the gh package. Comparing local output for http://localhost:6060/pkg/github.com/cli/go-gh/#example_RESTClient_advanced

    From trunk:

    opts := api.ClientOptions{
        Host:      "github.com",
        AuthToken: "xxxxxxxxxx", // Replace with valid auth token.
        Headers:   map[string]string{"Time-Zone": "America/Los_Angeles"},
        Log:       os.Stdout,
    }
    client, err := RESTClient(&opts)
    if err != nil {
        log.Fatal(err)
    }
    response := []struct{ Name string }{}
    err = client.Get("repos/cli/cli/tags", &response)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(response)

    From the example branch:

    opts := api.ClientOptions{
        Host:      "github.com",
        AuthToken: "xxxxxxxxxx", // Replace with valid auth token.
        Headers:   map[string]string{"Time-Zone": "America/Los_Angeles"},
        Log:       os.Stdout,
    }
    client, err := gh.RESTClient(&opts)
    if err != nil {
        log.Fatal(err)
    }
    response := []struct{ Name string }{}
    err = client.Get("repos/cli/cli/tags", &response)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(response)

    is there something else I should check for?

  4. mislav commented on Nov 7, 2022

    @mislav
    Contributor

    Nice, thanks for checking! Please send a PR for this 🙇

  5. mntlty commented on Nov 7, 2022

    @mntlty
    ContributorAuthor

    done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions