mirror of
https://github.com/apricote/hcloud-upload-image.git
synced 2026-02-07 18:27:04 +00:00
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
This commit is contained in:
parent
28bf5380f3
commit
420dcf94c9
3 changed files with 173 additions and 49 deletions
33
hcloudimages/doc_test.go
Normal file
33
hcloudimages/doc_test.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue