test/image: print saner error messages
%#v was my bad understanding of Go's error formatting. Let's use the standard %v that gives saner and human-readable error messages. Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
parent
35d7f0b9a6
commit
9f80c2ac8e
5 changed files with 49 additions and 49 deletions
|
|
@ -89,7 +89,7 @@ func runOsbuild(manifest []byte, store, outputDirectory string) error {
|
|||
func testImageInfo(t *testing.T, imagePath string, rawImageInfoExpected []byte) {
|
||||
var imageInfoExpected interface{}
|
||||
err := json.Unmarshal(rawImageInfoExpected, &imageInfoExpected)
|
||||
require.NoErrorf(t, err, "cannot decode expected image info: %#v", err)
|
||||
require.NoErrorf(t, err, "cannot decode expected image info: %v", err)
|
||||
|
||||
cmd := constants.GetImageInfoCommand(imagePath)
|
||||
cmd.Stderr = os.Stderr
|
||||
|
|
@ -97,14 +97,14 @@ func testImageInfo(t *testing.T, imagePath string, rawImageInfoExpected []byte)
|
|||
cmd.Stdout = writer
|
||||
|
||||
err = cmd.Start()
|
||||
require.NoErrorf(t, err, "image-info cannot start: %#v", err)
|
||||
require.NoErrorf(t, err, "image-info cannot start: %v", err)
|
||||
|
||||
var imageInfoGot interface{}
|
||||
err = json.NewDecoder(reader).Decode(&imageInfoGot)
|
||||
require.NoErrorf(t, err, "decoding image-info output failed: %#v", err)
|
||||
require.NoErrorf(t, err, "decoding image-info output failed: %v", err)
|
||||
|
||||
err = cmd.Wait()
|
||||
require.NoErrorf(t, err, "running image-info failed: %#v", err)
|
||||
require.NoErrorf(t, err, "running image-info failed: %v", err)
|
||||
|
||||
assert.Equal(t, imageInfoExpected, imageInfoGot)
|
||||
}
|
||||
|
|
@ -152,7 +152,7 @@ func trySSHOnce(address string, privateKey string, ns *boot.NetNS) error {
|
|||
return &timeoutError{}
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("ssh command failed from unknown reason: %#v", err)
|
||||
return fmt.Errorf("ssh command failed from unknown reason: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -491,7 +491,7 @@ func runTestcase(t *testing.T, testcase testcaseStruct, store string) {
|
|||
func getAllCases() ([]string, error) {
|
||||
cases, err := ioutil.ReadDir(constants.TestPaths.TestCasesDirectory)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot list test cases: %#v", err)
|
||||
return nil, fmt.Errorf("cannot list test cases: %v", err)
|
||||
}
|
||||
|
||||
casesPaths := []string{}
|
||||
|
|
@ -522,7 +522,7 @@ func runTests(t *testing.T, cases []string) {
|
|||
t.Run(path.Base(p), func(t *testing.T) {
|
||||
f, err := os.Open(p)
|
||||
if err != nil {
|
||||
t.Skipf("%s: cannot open test case: %#v", p, err)
|
||||
t.Skipf("%s: cannot open test case: %v", p, err)
|
||||
}
|
||||
|
||||
var testcase testcaseStruct
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ func encodeBase64(input string) string {
|
|||
func CreateUserData(publicKeyFile string) (string, error) {
|
||||
publicKey, err := ioutil.ReadFile(publicKeyFile)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot read the public key: %#v", err)
|
||||
return "", fmt.Errorf("cannot read the public key: %v", err)
|
||||
}
|
||||
|
||||
userData := fmt.Sprintf(`#cloud-config
|
||||
|
|
@ -91,16 +91,16 @@ func wrapErrorf(innerError error, format string, a ...interface{}) error {
|
|||
func UploadImageToAWS(c *awsCredentials, imagePath string, imageName string) error {
|
||||
uploader, err := awsupload.New(c.Region, c.AccessKeyId, c.SecretAccessKey)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create aws uploader: %#v", err)
|
||||
return fmt.Errorf("cannot create aws uploader: %v", err)
|
||||
}
|
||||
|
||||
_, err = uploader.Upload(imagePath, c.Bucket, imageName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot upload the image: %#v", err)
|
||||
return fmt.Errorf("cannot upload the image: %v", err)
|
||||
}
|
||||
_, err = uploader.Register(imageName, c.Bucket, imageName, nil, common.CurrentArch())
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot register the image: %#v", err)
|
||||
return fmt.Errorf("cannot register the image: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -114,7 +114,7 @@ func NewEC2(c *awsCredentials) (*ec2.EC2, error) {
|
|||
Region: aws.String(c.Region),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot create aws session: %#v", err)
|
||||
return nil, fmt.Errorf("cannot create aws session: %v", err)
|
||||
}
|
||||
|
||||
return ec2.New(sess), nil
|
||||
|
|
@ -141,7 +141,7 @@ func DescribeEC2Image(e *ec2.EC2, imageName string) (*imageDescription, error) {
|
|||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot describe the image: %#v", err)
|
||||
return nil, fmt.Errorf("cannot describe the image: %v", err)
|
||||
}
|
||||
imageId := imageDescriptions.Images[0].ImageId
|
||||
snapshotId := imageDescriptions.Images[0].BlockDeviceMappings[0].Ebs.SnapshotId
|
||||
|
|
@ -162,7 +162,7 @@ func DeleteEC2Image(e *ec2.EC2, imageDesc *imageDescription) error {
|
|||
})
|
||||
|
||||
if err != nil {
|
||||
retErr = wrapErrorf(retErr, "cannot deregister the image: %#v", err)
|
||||
retErr = wrapErrorf(retErr, "cannot deregister the image: %v", err)
|
||||
}
|
||||
|
||||
// now it's possible to delete the snapshot
|
||||
|
|
@ -171,7 +171,7 @@ func DeleteEC2Image(e *ec2.EC2, imageDesc *imageDescription) error {
|
|||
})
|
||||
|
||||
if err != nil {
|
||||
retErr = wrapErrorf(retErr, "cannot delete the snapshot: %#v", err)
|
||||
retErr = wrapErrorf(retErr, "cannot delete the snapshot: %v", err)
|
||||
}
|
||||
|
||||
return retErr
|
||||
|
|
@ -194,7 +194,7 @@ func WithBootedImageInEC2(e *ec2.EC2, securityGroupName string, imageDesc *image
|
|||
Description: aws.String("image-tests-security-group"),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create a new security group: %#v", err)
|
||||
return fmt.Errorf("cannot create a new security group: %v", err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
|
|
@ -203,7 +203,7 @@ func WithBootedImageInEC2(e *ec2.EC2, securityGroupName string, imageDesc *image
|
|||
})
|
||||
|
||||
if err != nil {
|
||||
retErr = wrapErrorf(retErr, "cannot delete the security group: %#v", err)
|
||||
retErr = wrapErrorf(retErr, "cannot delete the security group: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
@ -216,7 +216,7 @@ func WithBootedImageInEC2(e *ec2.EC2, securityGroupName string, imageDesc *image
|
|||
IpProtocol: aws.String("tcp"),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("canot add a rule to the security group: %#v", err)
|
||||
return fmt.Errorf("canot add a rule to the security group: %v", err)
|
||||
}
|
||||
|
||||
// Finally, run the instance from the given image and with the created security group
|
||||
|
|
@ -229,7 +229,7 @@ func WithBootedImageInEC2(e *ec2.EC2, securityGroupName string, imageDesc *image
|
|||
UserData: aws.String(encodeBase64(userData)),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create a new instance: %#v", err)
|
||||
return fmt.Errorf("cannot create a new instance: %v", err)
|
||||
}
|
||||
|
||||
describeInstanceInput := &ec2.DescribeInstancesInput{
|
||||
|
|
@ -247,13 +247,13 @@ func WithBootedImageInEC2(e *ec2.EC2, securityGroupName string, imageDesc *image
|
|||
},
|
||||
})
|
||||
if err != nil {
|
||||
retErr = wrapErrorf(retErr, "cannot terminate the instance: %#v", err)
|
||||
retErr = wrapErrorf(retErr, "cannot terminate the instance: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = e.WaitUntilInstanceTerminated(describeInstanceInput)
|
||||
if err != nil {
|
||||
retErr = wrapErrorf(retErr, "waiting for the instance termination failed: %#v", err)
|
||||
retErr = wrapErrorf(retErr, "waiting for the instance termination failed: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
@ -263,13 +263,13 @@ func WithBootedImageInEC2(e *ec2.EC2, securityGroupName string, imageDesc *image
|
|||
// actually can do something useful for us.
|
||||
err = e.WaitUntilInstanceRunning(describeInstanceInput)
|
||||
if err != nil {
|
||||
return fmt.Errorf("waiting for the instance to be running failed: %#v", err)
|
||||
return fmt.Errorf("waiting for the instance to be running failed: %v", err)
|
||||
}
|
||||
|
||||
// By describing the instance, we can get the ip address.
|
||||
out, err := e.DescribeInstances(describeInstanceInput)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot describe the instance: %#v", err)
|
||||
return fmt.Errorf("cannot describe the instance: %v", err)
|
||||
}
|
||||
|
||||
return f(*out.Reservations[0].Instances[0].PublicIpAddress)
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ func WithNetworkNamespace(f func(ns NetNS) error) error {
|
|||
defer func() {
|
||||
err := ns.Delete()
|
||||
if err != nil {
|
||||
log.Printf("cannot delete network namespace: %#v", err)
|
||||
log.Printf("cannot delete network namespace: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
@ -42,13 +42,13 @@ func WithNetworkNamespace(f func(ns NetNS) error) error {
|
|||
func withTempFile(dir, pattern string, f func(file *os.File) error) error {
|
||||
tempFile, err := ioutil.TempFile(dir, pattern)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create the temporary file: %#v", err)
|
||||
return fmt.Errorf("cannot create the temporary file: %v", err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
err := os.Remove(tempFile.Name())
|
||||
if err != nil {
|
||||
log.Printf("cannot remove the temporary file: %#v", err)
|
||||
log.Printf("cannot remove the temporary file: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
@ -58,13 +58,13 @@ func withTempFile(dir, pattern string, f func(file *os.File) error) error {
|
|||
func withTempDir(dir, pattern string, f func(dir string) error) error {
|
||||
tempDir, err := ioutil.TempDir(dir, pattern)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create the temporary directory %#v", err)
|
||||
return fmt.Errorf("cannot create the temporary directory %v", err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
err := os.RemoveAll(tempDir)
|
||||
if err != nil {
|
||||
log.Printf("cannot remove the temporary directory: %#v", err)
|
||||
log.Printf("cannot remove the temporary directory: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ func writeCloudInitISO(writer io.Writer, userData, metaData string) error {
|
|||
|
||||
err := isoCmd.Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create cloud-init iso: %#v", err)
|
||||
return fmt.Errorf("cannot create cloud-init iso: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -110,7 +110,7 @@ func WithBootedQemuImage(image string, ns NetNS, f func() error) error {
|
|||
|
||||
err = cloudInitFile.Close()
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot close temporary cloudinit file: %#v", err)
|
||||
return fmt.Errorf("cannot close temporary cloudinit file: %v", err)
|
||||
}
|
||||
|
||||
var qemuCmd *exec.Cmd
|
||||
|
|
@ -163,13 +163,13 @@ func WithBootedQemuImage(image string, ns NetNS, f func() error) error {
|
|||
|
||||
err = qemuCmd.Start()
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot start the qemu process: %#v", err)
|
||||
return fmt.Errorf("cannot start the qemu process: %v", err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
err := killProcessCleanly(qemuCmd.Process, time.Second)
|
||||
if err != nil {
|
||||
log.Printf("cannot kill the qemu process: %#v", err)
|
||||
log.Printf("cannot kill the qemu process: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
@ -189,13 +189,13 @@ func WithBootedNspawnImage(image string, ns NetNS, f func() error) error {
|
|||
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot start the systemd-nspawn process: %#v", err)
|
||||
return fmt.Errorf("cannot start the systemd-nspawn process: %v", err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
err := killProcessCleanly(cmd.Process, time.Second)
|
||||
if err != nil {
|
||||
log.Printf("cannot kill the systemd-nspawn process: %#v", err)
|
||||
log.Printf("cannot kill the systemd-nspawn process: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
@ -214,13 +214,13 @@ func WithBootedNspawnDirectory(dir string, ns NetNS, f func() error) error {
|
|||
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot start the systemd-nspawn process: %#v", err)
|
||||
return fmt.Errorf("cannot start the systemd-nspawn process: %v", err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
err := killProcessCleanly(cmd.Process, time.Second)
|
||||
if err != nil {
|
||||
log.Printf("cannot kill the systemd-nspawn process: %#v", err)
|
||||
log.Printf("cannot kill the systemd-nspawn process: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
@ -242,7 +242,7 @@ func WithExtractedTarArchive(archive string, f func(dir string) error) error {
|
|||
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot untar the archive: %#v", err)
|
||||
return fmt.Errorf("cannot untar the archive: %v", err)
|
||||
}
|
||||
|
||||
return f(dir)
|
||||
|
|
@ -263,7 +263,7 @@ func WithSSHKeyPair(f func(privateKey, publicKey string) error) error {
|
|||
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("ssh-keygen failed: %#v", err)
|
||||
return fmt.Errorf("ssh-keygen failed: %v", err)
|
||||
}
|
||||
|
||||
return f(privateKey, publicKey)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ func durationMin(a, b time.Duration) time.Duration {
|
|||
func killProcessCleanly(process *os.Process, timeout time.Duration) error {
|
||||
err := process.Signal(syscall.SIGTERM)
|
||||
if err != nil {
|
||||
log.Printf("cannot send SIGTERM to process, sending SIGKILL instead: %#v", err)
|
||||
log.Printf("cannot send SIGTERM to process, sending SIGKILL instead: %v", err)
|
||||
return process.Kill()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,16 +38,16 @@ func newNetworkNamespace() (NetNS, error) {
|
|||
if os.IsNotExist(err) {
|
||||
err := os.Mkdir(netnsDir, 0755)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot create %s: %#v", netnsDir, err)
|
||||
return "", fmt.Errorf("cannot create %s: %v", netnsDir, err)
|
||||
}
|
||||
} else {
|
||||
return "", fmt.Errorf("cannot stat %s: %#v", netnsDir, err)
|
||||
return "", fmt.Errorf("cannot stat %s: %v", netnsDir, err)
|
||||
}
|
||||
}
|
||||
|
||||
f, err := ioutil.TempFile(netnsDir, "osbuild-composer-namespace")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot create a tempfile: %#v", err)
|
||||
return "", fmt.Errorf("cannot create a tempfile: %v", err)
|
||||
}
|
||||
|
||||
// We want to remove the temporary file if the namespace initialization fails.
|
||||
|
|
@ -59,14 +59,14 @@ func newNetworkNamespace() (NetNS, error) {
|
|||
if !initOK {
|
||||
err := os.Remove(f.Name())
|
||||
if err != nil {
|
||||
log.Printf("cannot remove the temporary namespace: %#v", err)
|
||||
log.Printf("cannot remove the temporary namespace: %v", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
oldNS, err := os.Open("/proc/self/ns/net")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot open the current namespace: %#v", err)
|
||||
return "", fmt.Errorf("cannot open the current namespace: %v", err)
|
||||
}
|
||||
|
||||
err = syscall.Unshare(syscall.CLONE_NEWNET)
|
||||
|
|
@ -79,7 +79,7 @@ func newNetworkNamespace() (NetNS, error) {
|
|||
// We cannot return to the original namespace.
|
||||
// As we don't know nothing about affected threads, let's just
|
||||
// quit immediately.
|
||||
log.Fatalf("returning to the original namespace failed, quitting: %#v", err)
|
||||
log.Fatalf("returning to the original namespace failed, quitting: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ func newNetworkNamespace() (NetNS, error) {
|
|||
cmd.Stdout = os.Stderr
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot set up a loopback device in the new namespace: %#v", err)
|
||||
return "", fmt.Errorf("cannot set up a loopback device in the new namespace: %v", err)
|
||||
}
|
||||
|
||||
cmd = exec.Command("mount", "-o", "bind", "/proc/self/ns/net", f.Name())
|
||||
|
|
@ -96,7 +96,7 @@ func newNetworkNamespace() (NetNS, error) {
|
|||
cmd.Stdout = os.Stderr
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot bind mount the new namespace: %#v", err)
|
||||
return "", fmt.Errorf("cannot bind mount the new namespace: %v", err)
|
||||
}
|
||||
|
||||
ns := NetNS(path.Base(f.Name()))
|
||||
|
|
@ -136,12 +136,12 @@ func (n NetNS) Delete() error {
|
|||
cmd.Stdout = os.Stdout
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot unmount the network namespace: %#v", err)
|
||||
return fmt.Errorf("cannot unmount the network namespace: %v", err)
|
||||
}
|
||||
|
||||
err = os.Remove(n.Path())
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot delete the network namespace file: %#v", err)
|
||||
return fmt.Errorf("cannot delete the network namespace file: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue