github.com/vmware/govmomi@v0.51.0/ovf/importer/options_test.go (about)

     1  // © Broadcom. All Rights Reserved.
     2  // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package importer_test
     6  
     7  import (
     8  	"bytes"
     9  	"encoding/json"
    10  	"testing"
    11  
    12  	"github.com/vmware/govmomi/ovf/importer"
    13  )
    14  
    15  func TestDecodeOptions(t *testing.T) {
    16  	spec := []byte(`{
    17    "DiskProvisioning": "flat",
    18    "IPAllocationPolicy": "dhcpPolicy",
    19    "IPProtocol": "IPv4",
    20    "PropertyMapping": [
    21      {
    22        "Key": "ntp_server",
    23        "Value": "time.vmware.com"
    24      },
    25      {
    26        "key": "enable_ssh",
    27        "value": "True"
    28      }
    29    ],
    30    "NetworkMapping": [
    31      {
    32        "Name": "VM Network",
    33        "Network": ""
    34      }
    35    ],
    36    "MarkAsTemplate": false,
    37    "PowerOn": false,
    38    "InjectOvfEnv": false,
    39    "WaitForIP": false,
    40    "Name": null
    41  }
    42  `)
    43  	var opts importer.Options
    44  	err := json.NewDecoder(bytes.NewReader(spec)).Decode(&opts)
    45  	if err != nil {
    46  		t.Fatal(err)
    47  	}
    48  
    49  	// KeyValue are case insensitive
    50  	for i, p := range opts.PropertyMapping {
    51  		if p.Key == "" {
    52  			t.Errorf("empty PropertyMapping[%d].Key", i)
    53  		}
    54  		if p.Value == "" {
    55  			t.Errorf("empty PropertyMapping[%d].Value", i)
    56  		}
    57  	}
    58  }