-
-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathinterpolator_test.go
More file actions
64 lines (54 loc) · 1.74 KB
/
interpolator_test.go
File metadata and controls
64 lines (54 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package common
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestPlainText(t *testing.T) {
var vi VariablesInterpolator
s := "plain text"
result, err := vi.Interpolate(context.Background(), s)
assert.Equal(t, nil, err)
assert.Equal(t, s, result)
}
func TestMissingVariable(t *testing.T) {
var vi VariablesInterpolator
result, err := vi.Interpolate(context.Background(), "${{ VAR_NAME }} is here")
assert.Equal(t, nil, err)
assert.Equal(t, " is here", result)
}
func TestDollarEscape(t *testing.T) {
var vi VariablesInterpolator
result, err := vi.Interpolate(context.Background(), "it is not a variable $$!")
assert.Equal(t, nil, err)
assert.Equal(t, "it is not a variable $!", result)
}
func TestDollarWithoutEscape(t *testing.T) {
var vi VariablesInterpolator
result, err := vi.Interpolate(context.Background(), "it is not a variable $!")
assert.Equal(t, nil, err)
assert.Equal(t, "it is not a variable $!", result)
}
func TestEscapeOpening(t *testing.T) {
var vi VariablesInterpolator
result, err := vi.Interpolate(context.Background(), "$${{ VAR_NAME }}")
assert.Equal(t, nil, err)
assert.Equal(t, "${{ VAR_NAME }}", result)
}
func TestWithoutClosing(t *testing.T) {
var vi VariablesInterpolator
_, err := vi.Interpolate(context.Background(), "the end ${{")
assert.NotEqual(t, nil, err)
}
func TestUnexpectedEOL(t *testing.T) {
var vi VariablesInterpolator
_, err := vi.Interpolate(context.Background(), "the end ${{ VAR }")
assert.NotEqual(t, nil, err)
}
func TestSecrets(t *testing.T) {
var vi VariablesInterpolator
vi.Add("secrets", map[string]string{"user": "qwerty"})
result, err := vi.Interpolate(context.Background(), "${{ secrets.user }}")
assert.Equal(t, nil, err)
assert.Equal(t, "qwerty", result)
}