github.com/hashicorp/packer@v1.14.3/fix/fixer_qemu_disk_size_test.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package fix
     5  
     6  import (
     7  	"reflect"
     8  	"testing"
     9  )
    10  
    11  func TestFixerQEMUDiskSize_impl(t *testing.T) {
    12  	var _ Fixer = new(FixerQEMUDiskSize)
    13  }
    14  
    15  func TestFixerQEMUDiskSize(t *testing.T) {
    16  	cases := []struct {
    17  		Input    map[string]interface{}
    18  		Expected map[string]interface{}
    19  	}{
    20  		{
    21  			Input: map[string]interface{}{
    22  				"type":      "qemu",
    23  				"disk_size": int(40960),
    24  			},
    25  
    26  			Expected: map[string]interface{}{
    27  				"type":      "qemu",
    28  				"disk_size": "40960M",
    29  			},
    30  		},
    31  		{
    32  			Input: map[string]interface{}{
    33  				"type":      "qemu",
    34  				"disk_size": float64(50000),
    35  			},
    36  
    37  			Expected: map[string]interface{}{
    38  				"type":      "qemu",
    39  				"disk_size": "50000M",
    40  			},
    41  		},
    42  	}
    43  
    44  	for _, tc := range cases {
    45  		var f FixerQEMUDiskSize
    46  
    47  		input := map[string]interface{}{
    48  			"builders": []map[string]interface{}{tc.Input},
    49  		}
    50  
    51  		expected := map[string]interface{}{
    52  			"builders": []map[string]interface{}{tc.Expected},
    53  		}
    54  
    55  		output, err := f.Fix(input)
    56  		if err != nil {
    57  			t.Fatalf("err: %s", err)
    58  		}
    59  
    60  		if !reflect.DeepEqual(output, expected) {
    61  			t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected)
    62  		}
    63  	}
    64  }