@@ -7,7 +7,7 @@ if (-not (Get-Module -Name Pester -ListAvailable))
7
7
}
8
8
9
9
# Import the script being tested
10
- $scriptPath = Join-Path - Path (Get-Item - Path $PSScriptRoot ).Parent.FullName - ChildPath ' action.ps1'
10
+ $replaceTokens = Join-Path - Path (Get-Item - Path $PSScriptRoot ).Parent.FullName - ChildPath ' action.ps1'
11
11
12
12
Describe ' ReplaceTokens Function' {
13
13
@@ -22,15 +22,15 @@ Describe 'ReplaceTokens Function' {
22
22
Remove-Item - Path $testDir - Recurse - Force
23
23
}
24
24
25
- It ' Replaces tokens when environment variables exist' {
25
+ It ' Replaces mustache-style tokens when environment variables exist' {
26
26
# Arrange
27
- $testFile = Join-Path - Path $testDir - ChildPath ' test1 .txt'
27
+ $testFile = Join-Path - Path $testDir - ChildPath ' mustache-style .txt'
28
28
Set-Content - Path $testFile - Value ' Hello, {{NAME}}!' - Encoding utf8NoBOM - NoNewline
29
29
30
30
$env: NAME = ' Alice'
31
31
32
32
# Act
33
- & $scriptPath - Path $testFile - Style ' mustache' - Encoding ' utf8NoBOM' - NoNewline
33
+ & $replaceTokens - Path $testFile - Style ' mustache' - Encoding ' utf8NoBOM' - NoNewline
34
34
$result = Get-Content - Path $testFile - Raw
35
35
36
36
# Assert
@@ -39,11 +39,11 @@ Describe 'ReplaceTokens Function' {
39
39
40
40
It ' Does not replace tokens if no matching environment variable exists' {
41
41
# Arrange
42
- $testFile = Join-Path - Path $testDir - ChildPath ' test2 .txt'
42
+ $testFile = Join-Path - Path $testDir - ChildPath ' missing-env-var .txt'
43
43
Set-Content - Path $testFile - Value ' Welcome, {{REPLACE_TOKENS_ACTION}}!' - Encoding utf8NoBOM - NoNewline
44
44
45
45
# Act
46
- & $scriptPath - Path $testFile - Style ' mustache' - Encoding ' utf8NoBOM' - NoNewline
46
+ & $replaceTokens - Path $testFile - Style ' mustache' - Encoding ' utf8NoBOM' - NoNewline
47
47
$result = Get-Content - Path $testFile - Raw
48
48
49
49
# Assert
@@ -52,13 +52,13 @@ Describe 'ReplaceTokens Function' {
52
52
53
53
It ' Handles empty environment variable values correctly' {
54
54
# Arrange
55
- $testFile = Join-Path - Path $testDir - ChildPath ' test3 .txt'
55
+ $testFile = Join-Path - Path $testDir - ChildPath ' empty-env-var .txt'
56
56
Set-Content - Path $testFile - Value ' Your ID: {{ID}}' - Encoding utf8NoBOM - NoNewline
57
57
58
58
$env: ID = ' '
59
59
60
60
# Act
61
- & $scriptPath - Path $testFile - Style ' mustache' - Encoding ' utf8NoBOM' - NoNewline
61
+ & $replaceTokens - Path $testFile - Style ' mustache' - Encoding ' utf8NoBOM' - NoNewline
62
62
$result = Get-Content - Path $testFile - Raw
63
63
64
64
# Assert
@@ -67,7 +67,7 @@ Describe 'ReplaceTokens Function' {
67
67
68
68
It ' Applies correct encoding options' {
69
69
# Arrange
70
- $testFile = Join-Path - Path $testDir - ChildPath ' test5 .txt'
70
+ $testFile = Join-Path - Path $testDir - ChildPath ' encoding-test .txt'
71
71
Set-Content - Path $testFile - Value ' Encoding Test' - Encoding ascii - NoNewline
72
72
73
73
# Act
@@ -79,13 +79,13 @@ Describe 'ReplaceTokens Function' {
79
79
80
80
It ' Replaces tokens with envsubst style' {
81
81
# Arrange
82
- $testFile = Join-Path - Path $testDir - ChildPath ' test6 .txt'
82
+ $testFile = Join-Path - Path $testDir - ChildPath ' envsubst-style-basic .txt'
83
83
Set-Content - Path $testFile - Value ' Hello, ${NAME}!' - Encoding utf8NoBOM - NoNewline
84
84
85
85
$env: NAME = ' Bob'
86
86
87
87
# Act
88
- & $scriptPath - Path $testFile - Style ' envsubst' - Encoding ' utf8NoBOM' - NoNewline
88
+ & $replaceTokens - Path $testFile - Style ' envsubst' - Encoding ' utf8NoBOM' - NoNewline
89
89
$result = Get-Content - Path $testFile - Raw
90
90
91
91
# Assert
@@ -94,13 +94,13 @@ Describe 'ReplaceTokens Function' {
94
94
95
95
It ' Replaces tokens with make style' {
96
96
# Arrange
97
- $testFile = Join-Path - Path $testDir - ChildPath ' test7 .txt'
97
+ $testFile = Join-Path - Path $testDir - ChildPath ' make-style-basic .txt'
98
98
Set-Content - Path $testFile - Value ' Hello, $(NAME)!' - Encoding utf8NoBOM - NoNewline
99
99
100
100
$env: NAME = ' Charlie'
101
101
102
102
# Act
103
- & $scriptPath - Path $testFile - Style ' make' - Encoding ' utf8NoBOM' - NoNewline
103
+ & $replaceTokens - Path $testFile - Style ' make' - Encoding ' utf8NoBOM' - NoNewline
104
104
$result = Get-Content - Path $testFile - Raw
105
105
106
106
# Assert
@@ -109,13 +109,13 @@ Describe 'ReplaceTokens Function' {
109
109
110
110
It ' Does not replace tokens if file is excluded' {
111
111
# Arrange
112
- $testFile = Join-Path - Path $testDir - ChildPath ' test8 .txt'
112
+ $testFile = Join-Path - Path $testDir - ChildPath ' excluded-file .txt'
113
113
Set-Content - Path $testFile - Value ' Hello, {{NAME}}!' - Encoding utf8NoBOM - NoNewline
114
114
115
115
$env: NAME = ' Dave'
116
116
117
117
# Act
118
- & $scriptPath - Path $testFile - Style ' mustache' - Encoding ' utf8NoBOM' - NoNewline - Exclude ' test8 .txt'
118
+ & $replaceTokens - Path $testFile - Style ' mustache' - Encoding ' utf8NoBOM' - NoNewline - Exclude ' excluded-file .txt'
119
119
$result = Get-Content - Path $testFile - Raw
120
120
121
121
# Assert
@@ -124,11 +124,11 @@ Describe 'ReplaceTokens Function' {
124
124
125
125
It ' Fails the step if no tokens were replaced and fail is true' {
126
126
# Arrange
127
- $testFile = Join-Path - Path $testDir - ChildPath ' test9 .txt'
127
+ $testFile = Join-Path - Path $testDir - ChildPath ' no-tokens .txt'
128
128
Set-Content - Path $testFile - Value ' No tokens here!' - Encoding utf8NoBOM - NoNewline
129
129
130
130
# Act
131
- $result = & $scriptPath - Path $testFile - Style ' mustache' - Encoding ' utf8NoBOM' - NoNewline
131
+ $result = & $replaceTokens - Path $testFile - Style ' mustache' - Encoding ' utf8NoBOM' - NoNewline
132
132
133
133
# Assert
134
134
$result.Count | Should - Be 0 # No tokens were replaced
@@ -143,7 +143,7 @@ Describe 'ReplaceTokens Function' {
143
143
$env: 1INVALID = ' InvalidValue' # Won't be used as it's an invalid env var name
144
144
145
145
# Act
146
- & $scriptPath - Path $testFile - Style ' mustache' - Encoding ' utf8NoBOM' - NoNewline
146
+ & $replaceTokens - Path $testFile - Style ' mustache' - Encoding ' utf8NoBOM' - NoNewline
147
147
$result = Get-Content - Path $testFile - Raw
148
148
149
149
# Assert
@@ -158,7 +158,7 @@ Describe 'ReplaceTokens Function' {
158
158
$env: _TEST_VAR = ' UnderscoreValue'
159
159
160
160
# Act
161
- & $scriptPath - Path $testFile - Style ' mustache' - Encoding ' utf8NoBOM' - NoNewline
161
+ & $replaceTokens - Path $testFile - Style ' mustache' - Encoding ' utf8NoBOM' - NoNewline
162
162
$result = Get-Content - Path $testFile - Raw
163
163
164
164
# Assert
@@ -173,7 +173,7 @@ Describe 'ReplaceTokens Function' {
173
173
$env: SPECIAL = ' SpecialValue' # This won't be used
174
174
175
175
# Act
176
- & $scriptPath - Path $testFile - Style ' mustache' - Encoding ' utf8NoBOM' - NoNewline
176
+ & $replaceTokens - Path $testFile - Style ' mustache' - Encoding ' utf8NoBOM' - NoNewline
177
177
$result = Get-Content - Path $testFile - Raw
178
178
179
179
# Assert
@@ -189,7 +189,7 @@ Describe 'ReplaceTokens Function' {
189
189
$env: 123VAR = ' Invalid' # Won't be used as it's an invalid env var name
190
190
191
191
# Act
192
- & $scriptPath - Path $testFile - Style ' envsubst' - Encoding ' utf8NoBOM' - NoNewline
192
+ & $replaceTokens - Path $testFile - Style ' envsubst' - Encoding ' utf8NoBOM' - NoNewline
193
193
$result = Get-Content - Path $testFile - Raw
194
194
195
195
# Assert
@@ -205,7 +205,7 @@ Describe 'ReplaceTokens Function' {
205
205
$env: MAKE = ' Invalid' # Won't match the token format
206
206
207
207
# Act
208
- & $scriptPath - Path $testFile - Style ' make' - Encoding ' utf8NoBOM' - NoNewline
208
+ & $replaceTokens - Path $testFile - Style ' make' - Encoding ' utf8NoBOM' - NoNewline
209
209
$result = Get-Content - Path $testFile - Raw
210
210
211
211
# Assert
0 commit comments