github.com/vmware/govmomi@v0.37.1/govc/importx/options_test.go (about) 1 /* 2 Copyright (c) 2023-2023 VMware, Inc. All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package importx_test 18 19 import ( 20 "bytes" 21 "encoding/json" 22 "testing" 23 24 "github.com/vmware/govmomi/govc/importx" 25 ) 26 27 func TestDecodeOptions(t *testing.T) { 28 spec := []byte(`{ 29 "DiskProvisioning": "flat", 30 "IPAllocationPolicy": "dhcpPolicy", 31 "IPProtocol": "IPv4", 32 "PropertyMapping": [ 33 { 34 "Key": "ntp_server", 35 "Value": "time.vmware.com" 36 }, 37 { 38 "key": "enable_ssh", 39 "value": "True" 40 } 41 ], 42 "NetworkMapping": [ 43 { 44 "Name": "VM Network", 45 "Network": "" 46 } 47 ], 48 "MarkAsTemplate": false, 49 "PowerOn": false, 50 "InjectOvfEnv": false, 51 "WaitForIP": false, 52 "Name": null 53 } 54 `) 55 var opts importx.Options 56 err := json.NewDecoder(bytes.NewReader(spec)).Decode(&opts) 57 if err != nil { 58 t.Fatal(err) 59 } 60 61 // KeyValue are case insensitive 62 for i, p := range opts.PropertyMapping { 63 if p.Key == "" { 64 t.Errorf("empty PropertyMapping[%d].Key", i) 65 } 66 if p.Value == "" { 67 t.Errorf("empty PropertyMapping[%d].Value", i) 68 } 69 } 70 }