Skip to content

Commit

Permalink
test: fix testable examples
Browse files Browse the repository at this point in the history
  • Loading branch information
alespour committed Dec 28, 2022
1 parent b209672 commit 9629ff6
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions influxclient/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package influxclient_test
import (
"context"
"fmt"
"os"

"github.com/influxdata/influxdb-client-go/influxclient"
"github.com/influxdata/influxdb-client-go/influxclient/model"
Expand All @@ -15,8 +16,8 @@ import (
func ExampleClient_newClient() {
// Create a new client using an InfluxDB server base URL and an authentication token
client, err := influxclient.New(influxclient.Params{
ServerURL: "http://localhost:8086",
AuthToken: "my-token"})
ServerURL: serverURL,
AuthToken: authToken})

_ = err
_ = client
Expand All @@ -28,8 +29,8 @@ func ExampleClient_newClientWithOptions() {
// Create a new client using an InfluxDB server base URL and an authentication token
// Create client and set batch size to 20
client, err := influxclient.New(influxclient.Params{
ServerURL: "http://localhost:8086",
AuthToken: "my-token",
ServerURL: serverURL,
AuthToken: authToken,
BatchSize: 20})

_ = err
Expand All @@ -44,20 +45,20 @@ func ExampleClient_customServerAPICall() {

// Create client. You need an admin token for creating DBRP mapping
client, err := influxclient.New(influxclient.Params{
ServerURL: "http://localhost:8086",
AuthToken: "my-token"})
ServerURL: serverURL,
AuthToken: authToken})

// Get generated client for server API calls
apiClient := client.APIClient()
ctx := context.Background()

// Get a bucket we would like to query using InfluxQL
b, err := client.BucketsAPI().FindOne(ctx, &influxclient.Filter{Name: "my-bucket"})
b, err := client.BucketsAPI().FindOne(ctx, &influxclient.Filter{Name: bucketName})
if err != nil {
panic(err)
}
// Get an organization that will own the mapping
o, err := client.OrganizationAPI().FindOne(ctx, &influxclient.Filter{Name: "my-org"})
o, err := client.OrganizationAPI().FindOne(ctx, &influxclient.Filter{Name: orgName})
if err != nil {
panic(err)
}
Expand All @@ -66,7 +67,7 @@ func ExampleClient_customServerAPICall() {
// Fill required fields of the DBRP struct
dbrp := model.DBRPCreate{
BucketID: *b.Id,
Database: "my-bucket",
Database: b.Name,
Default: &yes,
OrgID: o.Id,
RetentionPolicy: "autogen",
Expand All @@ -81,8 +82,8 @@ func ExampleClient_customServerAPICall() {
panic(err)
}

// Check generated response errors
fmt.Printf("Created DBRP: %#v\n", newDbrp)
// Check generated response
fmt.Fprintf(os.Stderr, "Created DBRP: %#v\n", newDbrp)

// Output:
}

0 comments on commit 9629ff6

Please sign in to comment.