diff --git a/builder/qemu/builder_test.go b/builder/qemu/builder_test.go index d2a1d1eba9b..f885c570ba2 100644 --- a/builder/qemu/builder_test.go +++ b/builder/qemu/builder_test.go @@ -132,6 +132,48 @@ func TestBuilderPrepare_BootWait(t *testing.T) { } } +func TestBuilderPrepare_DiskCompaction(t *testing.T) { + var b Builder + config := testConfig() + + // Bad + config["skip_compaction"] = false + config["disk_compression"] = true + config["format"] = "img" + warns, err := b.Prepare(config) + if len(warns) > 0 { + t.Fatalf("bad: %#v", warns) + } + if err == nil { + t.Fatal("should have error") + } + if b.config.SkipCompaction != true { + t.Fatalf("SkipCompaction should be true") + } + if b.config.DiskCompression != false { + t.Fatalf("DiskCompression should be false") + } + + // Good + config["skip_compaction"] = false + config["disk_compression"] = true + config["format"] = "qcow2" + b = Builder{} + warns, err = b.Prepare(config) + if len(warns) > 0 { + t.Fatalf("bad: %#v", warns) + } + if err != nil { + t.Fatalf("should not have error: %s", err) + } + if b.config.SkipCompaction != false { + t.Fatalf("SkipCompaction should be false") + } + if b.config.DiskCompression != true { + t.Fatalf("DiskCompression should be true") + } +} + func TestBuilderPrepare_DiskSize(t *testing.T) { var b Builder config := testConfig()