add tests

This commit is contained in:
Adrien Delorme 2020-10-02 10:49:21 +02:00
parent bb22cfcf34
commit fcf16315a3
4 changed files with 62 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package command
import ( import (
"bytes" "bytes"
"io/ioutil"
"path/filepath" "path/filepath"
"testing" "testing"
@ -27,6 +28,15 @@ func outputCommand(t *testing.T, m Meta) (string, string) {
return out.String(), err.String() return out.String(), err.String()
} }
func testFixtureContent(n ...string) string {
path := filepath.Join(append([]string{fixturesDir}, n...)...)
b, err := ioutil.ReadFile(path)
if err != nil {
panic(err)
}
return string(b)
}
func testFixture(n ...string) string { func testFixture(n ...string) string {
paths := []string{fixturesDir} paths := []string{fixturesDir}
paths = append(paths, n...) paths = append(paths, n...)

View File

@ -153,6 +153,13 @@ Note: If your build names contain user variables or template
functions such as 'timestamp', these are processed at build time, functions such as 'timestamp', these are processed at build time,
and therefore only show in their raw form here. and therefore only show in their raw form here.
`}, `},
{
[]string{
"inspect", filepath.Join(testFixture("hcl-inspect-with-sensitive-vars")),
},
nil,
testFixtureContent("hcl-inspect-with-sensitive-vars", "expected-output.txt"),
},
} }
for _, tc := range tc { for _, tc := range tc {

View File

@ -0,0 +1,16 @@
Packer Inspect: HCL2 mode
> input-variables:
var.not_sensitive: "I am soooo not sensitive"
var.not_sensitive_unknown: "<unknown>"
var.sensitive: "<sensitive>"
var.sensitive_array: "[\n \"<sensitive>\",\n \"<sensitive>\",\n]"
var.sensitive_tags: "{\n \"first_key\" = \"<sensitive>\"\n \"second_key\" = \"<sensitive>\"\n}"
var.sensitive_unknown: "<unknown>"
> local-variables:
> builds:

View File

@ -0,0 +1,29 @@
variable "not_sensitive" {
default = "I am soooo not sensitive"
}
variable "not_sensitive_unknown" {
}
variable "sensitive" {
default = "I am soooo sensitive"
sensitive = true
}
variable "sensitive_array" {
default = ["Im supersensitive", "me too !!!!"]
sensitive = true
}
variable "sensitive_tags" {
default = {
first_key = "this-is-mega-sensitive"
second_key = "this-is-also-sensitive"
}
sensitive = true
}
variable "sensitive_unknown" {
sensitive = true
}