-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: debug template print (#3171)
Signed-off-by: Austin Abro <[email protected]>
- Loading branch information
1 parent
31e70f5
commit 6a55bc3
Showing
3 changed files
with
110 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors | ||
|
||
// Package template provides functions for templating yaml files. | ||
package template | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/zarf-dev/zarf/src/pkg/variables" | ||
) | ||
|
||
func TestGetSanitizedTemplateMap(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
name string | ||
input map[string]*variables.TextTemplate | ||
expected map[string]string | ||
}{ | ||
{ | ||
name: "Sensitive entry", | ||
input: map[string]*variables.TextTemplate{ | ||
"###SENSITIVE###": {Sensitive: true, Value: "secret"}, | ||
}, | ||
expected: map[string]string{ | ||
"###SENSITIVE###": "**sanitized**", | ||
}, | ||
}, | ||
{ | ||
name: "Non-sensitive entries", | ||
input: map[string]*variables.TextTemplate{ | ||
"###VARIABLE###": {Sensitive: false, Value: "value"}, | ||
}, | ||
expected: map[string]string{ | ||
"###VARIABLE###": "value", | ||
}, | ||
}, | ||
{ | ||
name: "Sensitive and non-sensitive entries", | ||
input: map[string]*variables.TextTemplate{ | ||
"###ZARF_GIT_AUTH_PULL###": {Sensitive: true, Value: "secret1"}, | ||
"###ZARF_GIT_AUTH_PUSH###": {Sensitive: true, Value: "secret2"}, | ||
"###ZARF_GIT_PUSH###": {Sensitive: false, Value: "zarf-git-user"}, | ||
"###ZARF_GIT_PULL###": {Sensitive: false, Value: "zarf-git-read-user"}, | ||
}, | ||
expected: map[string]string{ | ||
"###ZARF_GIT_AUTH_PULL###": "**sanitized**", | ||
"###ZARF_GIT_AUTH_PUSH###": "**sanitized**", | ||
"###ZARF_GIT_PULL###": "zarf-git-read-user", | ||
"###ZARF_GIT_PUSH###": "zarf-git-user", | ||
}, | ||
}, | ||
{ | ||
name: "Nil map", | ||
input: nil, | ||
expected: map[string]string{}, | ||
}, | ||
{ | ||
name: "Empty map", | ||
input: map[string]*variables.TextTemplate{}, | ||
expected: map[string]string{}, | ||
}, | ||
{ | ||
name: "Map with nil value", | ||
input: map[string]*variables.TextTemplate{ | ||
"###ZARF_GIT_AUTH_PULL###": nil, | ||
}, | ||
expected: map[string]string{ | ||
"###ZARF_GIT_AUTH_PULL###": "", | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
output := getSanitizedTemplateMap(test.input) | ||
require.Equal(t, test.expected, output) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters