-
-
Save xNok/e12f901ef8161e32c946afff1bc70e78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func init_testDB(t *testing.T) influxdb2.Client { | |
t.Helper() // Tells `go test` that this is an helper | |
godotenv.Load("./test_influxdb.env") //load environement variable | |
client, err := drivers.ConnectToInfluxDB() // create the client | |
if err != nil { | |
t.Errorf("impossible to connect to DB") | |
} | |
// Clean the database by deleting the bucket | |
ctx := context.Background() | |
bucketsAPI := client.BucketsAPI() | |
dBucket, err := bucketsAPI.FindBucketByName(ctx, bucket) | |
if err == nil { | |
client.BucketsAPI().DeleteBucketWithID(context.Background(), *dBucket.Id) | |
} | |
// create new empty bucket | |
dOrg, _ := client.OrganizationsAPI().FindOrganizationByName(ctx, org) | |
_, err = client.BucketsAPI().CreateBucketWithNameWithID(ctx, *dOrg.Id, bucket) | |
if err != nil { | |
t.Errorf("impossible to new create bucket") | |
} | |
return client | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment