Skip to content

Commit 138074d

Browse files
committed
test: test file name tweaks
1 parent 2bf0ffe commit 138074d

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

test/ReplaceTokens.Tests.ps1

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if (-not (Get-Module -Name Pester -ListAvailable))
77
}
88

99
# 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'
1111

1212
Describe 'ReplaceTokens Function' {
1313

@@ -22,15 +22,15 @@ Describe 'ReplaceTokens Function' {
2222
Remove-Item -Path $testDir -Recurse -Force
2323
}
2424

25-
It 'Replaces tokens when environment variables exist' {
25+
It 'Replaces mustache-style tokens when environment variables exist' {
2626
# Arrange
27-
$testFile = Join-Path -Path $testDir -ChildPath 'test1.txt'
27+
$testFile = Join-Path -Path $testDir -ChildPath 'mustache-style.txt'
2828
Set-Content -Path $testFile -Value 'Hello, {{NAME}}!' -Encoding utf8NoBOM -NoNewline
2929

3030
$env:NAME = 'Alice'
3131

3232
# Act
33-
& $scriptPath -Path $testFile -Style 'mustache' -Encoding 'utf8NoBOM' -NoNewline
33+
& $replaceTokens -Path $testFile -Style 'mustache' -Encoding 'utf8NoBOM' -NoNewline
3434
$result = Get-Content -Path $testFile -Raw
3535

3636
# Assert
@@ -39,11 +39,11 @@ Describe 'ReplaceTokens Function' {
3939

4040
It 'Does not replace tokens if no matching environment variable exists' {
4141
# Arrange
42-
$testFile = Join-Path -Path $testDir -ChildPath 'test2.txt'
42+
$testFile = Join-Path -Path $testDir -ChildPath 'missing-env-var.txt'
4343
Set-Content -Path $testFile -Value 'Welcome, {{REPLACE_TOKENS_ACTION}}!' -Encoding utf8NoBOM -NoNewline
4444

4545
# Act
46-
& $scriptPath -Path $testFile -Style 'mustache' -Encoding 'utf8NoBOM' -NoNewline
46+
& $replaceTokens -Path $testFile -Style 'mustache' -Encoding 'utf8NoBOM' -NoNewline
4747
$result = Get-Content -Path $testFile -Raw
4848

4949
# Assert
@@ -52,13 +52,13 @@ Describe 'ReplaceTokens Function' {
5252

5353
It 'Handles empty environment variable values correctly' {
5454
# Arrange
55-
$testFile = Join-Path -Path $testDir -ChildPath 'test3.txt'
55+
$testFile = Join-Path -Path $testDir -ChildPath 'empty-env-var.txt'
5656
Set-Content -Path $testFile -Value 'Your ID: {{ID}}' -Encoding utf8NoBOM -NoNewline
5757

5858
$env:ID = ''
5959

6060
# Act
61-
& $scriptPath -Path $testFile -Style 'mustache' -Encoding 'utf8NoBOM' -NoNewline
61+
& $replaceTokens -Path $testFile -Style 'mustache' -Encoding 'utf8NoBOM' -NoNewline
6262
$result = Get-Content -Path $testFile -Raw
6363

6464
# Assert
@@ -67,7 +67,7 @@ Describe 'ReplaceTokens Function' {
6767

6868
It 'Applies correct encoding options' {
6969
# Arrange
70-
$testFile = Join-Path -Path $testDir -ChildPath 'test5.txt'
70+
$testFile = Join-Path -Path $testDir -ChildPath 'encoding-test.txt'
7171
Set-Content -Path $testFile -Value 'Encoding Test' -Encoding ascii -NoNewline
7272

7373
# Act
@@ -79,13 +79,13 @@ Describe 'ReplaceTokens Function' {
7979

8080
It 'Replaces tokens with envsubst style' {
8181
# Arrange
82-
$testFile = Join-Path -Path $testDir -ChildPath 'test6.txt'
82+
$testFile = Join-Path -Path $testDir -ChildPath 'envsubst-style-basic.txt'
8383
Set-Content -Path $testFile -Value 'Hello, ${NAME}!' -Encoding utf8NoBOM -NoNewline
8484

8585
$env:NAME = 'Bob'
8686

8787
# Act
88-
& $scriptPath -Path $testFile -Style 'envsubst' -Encoding 'utf8NoBOM' -NoNewline
88+
& $replaceTokens -Path $testFile -Style 'envsubst' -Encoding 'utf8NoBOM' -NoNewline
8989
$result = Get-Content -Path $testFile -Raw
9090

9191
# Assert
@@ -94,13 +94,13 @@ Describe 'ReplaceTokens Function' {
9494

9595
It 'Replaces tokens with make style' {
9696
# Arrange
97-
$testFile = Join-Path -Path $testDir -ChildPath 'test7.txt'
97+
$testFile = Join-Path -Path $testDir -ChildPath 'make-style-basic.txt'
9898
Set-Content -Path $testFile -Value 'Hello, $(NAME)!' -Encoding utf8NoBOM -NoNewline
9999

100100
$env:NAME = 'Charlie'
101101

102102
# Act
103-
& $scriptPath -Path $testFile -Style 'make' -Encoding 'utf8NoBOM' -NoNewline
103+
& $replaceTokens -Path $testFile -Style 'make' -Encoding 'utf8NoBOM' -NoNewline
104104
$result = Get-Content -Path $testFile -Raw
105105

106106
# Assert
@@ -109,13 +109,13 @@ Describe 'ReplaceTokens Function' {
109109

110110
It 'Does not replace tokens if file is excluded' {
111111
# Arrange
112-
$testFile = Join-Path -Path $testDir -ChildPath 'test8.txt'
112+
$testFile = Join-Path -Path $testDir -ChildPath 'excluded-file.txt'
113113
Set-Content -Path $testFile -Value 'Hello, {{NAME}}!' -Encoding utf8NoBOM -NoNewline
114114

115115
$env:NAME = 'Dave'
116116

117117
# 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'
119119
$result = Get-Content -Path $testFile -Raw
120120

121121
# Assert
@@ -124,11 +124,11 @@ Describe 'ReplaceTokens Function' {
124124

125125
It 'Fails the step if no tokens were replaced and fail is true' {
126126
# Arrange
127-
$testFile = Join-Path -Path $testDir -ChildPath 'test9.txt'
127+
$testFile = Join-Path -Path $testDir -ChildPath 'no-tokens.txt'
128128
Set-Content -Path $testFile -Value 'No tokens here!' -Encoding utf8NoBOM -NoNewline
129129

130130
# Act
131-
$result = & $scriptPath -Path $testFile -Style 'mustache' -Encoding 'utf8NoBOM' -NoNewline
131+
$result = & $replaceTokens -Path $testFile -Style 'mustache' -Encoding 'utf8NoBOM' -NoNewline
132132

133133
# Assert
134134
$result.Count | Should -Be 0 # No tokens were replaced
@@ -143,7 +143,7 @@ Describe 'ReplaceTokens Function' {
143143
$env:1INVALID = 'InvalidValue' # Won't be used as it's an invalid env var name
144144

145145
# Act
146-
& $scriptPath -Path $testFile -Style 'mustache' -Encoding 'utf8NoBOM' -NoNewline
146+
& $replaceTokens -Path $testFile -Style 'mustache' -Encoding 'utf8NoBOM' -NoNewline
147147
$result = Get-Content -Path $testFile -Raw
148148

149149
# Assert
@@ -158,7 +158,7 @@ Describe 'ReplaceTokens Function' {
158158
$env:_TEST_VAR = 'UnderscoreValue'
159159

160160
# Act
161-
& $scriptPath -Path $testFile -Style 'mustache' -Encoding 'utf8NoBOM' -NoNewline
161+
& $replaceTokens -Path $testFile -Style 'mustache' -Encoding 'utf8NoBOM' -NoNewline
162162
$result = Get-Content -Path $testFile -Raw
163163

164164
# Assert
@@ -173,7 +173,7 @@ Describe 'ReplaceTokens Function' {
173173
$env:SPECIAL = 'SpecialValue' # This won't be used
174174

175175
# Act
176-
& $scriptPath -Path $testFile -Style 'mustache' -Encoding 'utf8NoBOM' -NoNewline
176+
& $replaceTokens -Path $testFile -Style 'mustache' -Encoding 'utf8NoBOM' -NoNewline
177177
$result = Get-Content -Path $testFile -Raw
178178

179179
# Assert
@@ -189,7 +189,7 @@ Describe 'ReplaceTokens Function' {
189189
$env:123VAR = 'Invalid' # Won't be used as it's an invalid env var name
190190

191191
# Act
192-
& $scriptPath -Path $testFile -Style 'envsubst' -Encoding 'utf8NoBOM' -NoNewline
192+
& $replaceTokens -Path $testFile -Style 'envsubst' -Encoding 'utf8NoBOM' -NoNewline
193193
$result = Get-Content -Path $testFile -Raw
194194

195195
# Assert
@@ -205,7 +205,7 @@ Describe 'ReplaceTokens Function' {
205205
$env:MAKE = 'Invalid' # Won't match the token format
206206

207207
# Act
208-
& $scriptPath -Path $testFile -Style 'make' -Encoding 'utf8NoBOM' -NoNewline
208+
& $replaceTokens -Path $testFile -Style 'make' -Encoding 'utf8NoBOM' -NoNewline
209209
$result = Get-Content -Path $testFile -Raw
210210

211211
# Assert

0 commit comments

Comments
 (0)