github.com/hashicorp/packer@v1.14.3/config_test.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package main 5 6 import ( 7 "encoding/json" 8 "reflect" 9 "strings" 10 "testing" 11 ) 12 13 func TestDecodeConfig(t *testing.T) { 14 15 packerConfig := ` 16 { 17 "PluginMinPort": 10, 18 "PluginMaxPort": 25, 19 "disable_checkpoint": true, 20 "disable_checkpoint_signature": true, 21 "provisioners": { 22 "super-shell": "packer-provisioner-super-shell" 23 } 24 }` 25 26 var cfg config 27 err := decodeConfig(strings.NewReader(packerConfig), &cfg) 28 if err != nil { 29 t.Fatalf("error encountered decoding configuration: %v", err) 30 } 31 32 var expectedCfg config 33 json.NewDecoder(strings.NewReader(packerConfig)).Decode(&expectedCfg) 34 if !reflect.DeepEqual(cfg, expectedCfg) { 35 t.Errorf("failed to load custom configuration data; expected %v got %v", expectedCfg, cfg) 36 } 37 38 }