hcloud-upload-image/hcloudimages/doc_test.go
Julian Tölle 420dcf94c9
Some checks are pending
ci / lint (push) Waiting to run
ci / test (push) Waiting to run
ci / go-mod-tidy (push) Waiting to run
ci / cli-help-pages (push) Waiting to run
docs / deploy (push) Waiting to run
release-please / release-please (push) Waiting to run
fix: upload from local image generates broken command (#98)
While adding support for qcow2 images in #69 I broke support for local
images. Building a shell pipeline through string concatenation is not a
good idea...

The specific issue was fixed and I also moved building the shell
pipeline to a separate function and added unit tests for all cases, so
it should be easier to spot these issues in the future.

Closes #97
2025-05-09 21:22:24 +00:00

34 lines
680 B
Go

package hcloudimages_test
import (
"context"
"fmt"
"net/url"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/apricote/hcloud-upload-image/hcloudimages"
)
func ExampleClient_Upload() {
client := hcloudimages.NewClient(
hcloud.NewClient(hcloud.WithToken("<your token>")),
)
imageURL, err := url.Parse("https://example.com/disk-image.raw.bz2")
if err != nil {
panic(err)
}
image, err := client.Upload(context.TODO(), hcloudimages.UploadOptions{
ImageURL: imageURL,
ImageCompression: hcloudimages.CompressionBZ2,
Architecture: hcloud.ArchitectureX86,
})
if err != nil {
panic(err)
}
fmt.Printf("Uploaded Image: %d", image.ID)
}