github.com/hashicorp/packer@v1.14.3/builder/file/config_test.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package file
     5  
     6  import (
     7  	"strings"
     8  	"testing"
     9  )
    10  
    11  func testConfig() map[string]interface{} {
    12  	return map[string]interface{}{
    13  		"source":  "src.txt",
    14  		"target":  "dst.txt",
    15  		"content": "Hello, world!",
    16  	}
    17  }
    18  
    19  func TestContentSourceConflict(t *testing.T) {
    20  	raw := testConfig()
    21  
    22  	var c Config
    23  	_, errs := c.Prepare(raw)
    24  	if !strings.Contains(errs.Error(), ErrContentSourceConflict.Error()) {
    25  		t.Errorf("Expected config error: %s", ErrContentSourceConflict.Error())
    26  	}
    27  }
    28  
    29  func TestNoFilename(t *testing.T) {
    30  	raw := testConfig()
    31  
    32  	delete(raw, "filename")
    33  	var c Config
    34  	_, errs := c.Prepare(raw)
    35  	if errs == nil {
    36  		t.Errorf("Expected config error: %s", ErrTargetRequired.Error())
    37  	}
    38  }
    39  
    40  func TestNoContent(t *testing.T) {
    41  	raw := testConfig()
    42  
    43  	delete(raw, "content")
    44  	delete(raw, "source")
    45  	var c Config
    46  	warns, _ := c.Prepare(raw)
    47  
    48  	if len(warns) == 0 {
    49  		t.Error("Expected config warning without any content")
    50  	}
    51  }