Skip to content

Commit

Permalink
🚑 Fix unit tests and add spec
Browse files Browse the repository at this point in the history
  • Loading branch information
wesen committed May 15, 2024
1 parent 969c250 commit fe80b2c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 66 deletions.
132 changes: 66 additions & 66 deletions pkg/emrichen/if_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,33 @@ func TestEmrichenIfAndFilterTags(t *testing.T) {
{
name: "Basic boolean condition - true",
inputYAML: `!If
test: true
then: 'Yes'
else: 'No'`,
test: true
then: 'Yes'
else: 'No'`,
expected: "'Yes'",
},
{
name: "Basic boolean condition - false",
inputYAML: `!If
test: false
then: 'Yes'
else: 'No'`,
test: false
then: 'Yes'
else: 'No'`,
expected: "'No'",
},
{
name: "Nested !If statements",
inputYAML: `!If
test: true
then: !If {test: false, then: "Inner Yes", else: "Inner No"}
else: 'Outer No'`,
test: true
then: !If {test: false, then: "Inner Yes", else: "Inner No"}
else: 'Outer No'`,
expected: "'Inner No'",
},
{
name: "Variable substitution in conditions",
inputYAML: `!If
test: !Var condition
then: 'Variable Yes'
else: 'Variable No'`,
test: !Var condition
then: 'Variable Yes'
else: 'Variable No'`,
expected: "'Variable Yes'",
initVars: map[string]interface{}{
"condition": true,
Expand All @@ -45,97 +45,97 @@ func TestEmrichenIfAndFilterTags(t *testing.T) {
{
name: "If tag true condition",
inputYAML: `!If
test: !Op
a: 10
op: ">"
b: 5
then: "True Condition"
else: "False Condition"`,
test: !Op
a: 10
op: ">"
b: 5
then: "True Condition"
else: "False Condition"`,
expected: "\"True Condition\"",
},
{
name: "If tag false condition",
inputYAML: `!If
test: !Op
a: 3
op: ">"
b: 5
then: "True Condition"
else: "False Condition"`,
test: !Op
a: 3
op: ">"
b: 5
then: "True Condition"
else: "False Condition"`,
expected: "\"False Condition\"",
},
{
name: "Type-checking with string in condition",
inputYAML: `!If
test: 'true' # String 'true', not boolean
then: 'String Yes'
else: 'String No'`,
test: 'true' # String 'true', not boolean
then: 'String Yes'
else: 'String No'`,
expected: "'String Yes'",
},
{
name: "Type-checking with number in condition",
inputYAML: `!If
test: 1 # Number 1
then: 'Number Yes'
else: 'Number No'`,
test: 1 # Number 1
then: 'Number Yes'
else: 'Number No'`,
expected: "'Number Yes'",
},
// Test 9: Conditional Evaluation with `null` and Empty Values
{
name: "Evaluation with null condition",
inputYAML: `!If
test: null
then: 'Null Yes'
else: 'Null No'`,
test: null
then: 'Null Yes'
else: 'Null No'`,
expected: "'Null No'",
},
{
name: "Evaluation with empty string condition",
inputYAML: `!If
test: ''
then: 'Empty Yes'
else: 'Empty No'`,
test: ''
then: 'Empty Yes'
else: 'Empty No'`,
expected: "'Empty No'",
},
{
name: "Evaluation with empty list condition",
inputYAML: `!If
test: []
then: 'Empty List Yes'
else: 'Empty List No'`,
test: []
then: 'Empty List Yes'
else: 'Empty List No'`,
expected: "'Empty List No'",
},
{
name: "Omitting 'then' branch - true condition",
inputYAML: `!If
test: true
else: 'No'`,
test: true
else: 'No'`,
expected: "null", // Expecting null or equivalent when 'then' is missing and condition is true
},
{
name: "Omitting 'else' branch - false condition",
inputYAML: `!If
test: false
then: 'Yes'`,
test: false
then: 'Yes'`,
expected: "null", // Expecting null or equivalent when 'else' is missing and condition is false
},
{
name: "Omitting both 'then' and 'else' - true condition",
inputYAML: `!If
test: true`,
test: true`,
expected: "null", // Expecting null or equivalent when both branches are missing
},
{
name: "Omitting both 'then' and 'else' - false condition",
inputYAML: `!If
test: false`,
test: false`,
expected: "null", // Expecting null or equivalent when both branches are missing
},
{
name: "Variable substitution in condition with omitted 'then'",
inputYAML: `!If
test: !Var condition
else: 'Variable No'`,
test: !Var condition
else: 'Variable No'`,
expected: "null",
initVars: map[string]interface{}{
"condition": true,
Expand All @@ -144,8 +144,8 @@ func TestEmrichenIfAndFilterTags(t *testing.T) {
{
name: "Variable substitution in condition with omitted 'else'",
inputYAML: `!If
test: !Var condition
then: 'Variable Yes'`,
test: !Var condition
then: 'Variable Yes'`,
expected: "null",
initVars: map[string]interface{}{
"condition": false,
Expand All @@ -154,28 +154,28 @@ func TestEmrichenIfAndFilterTags(t *testing.T) {
{
name: "Nested Op test",
inputYAML: `!If
test: !Op
a: 10
op: ">"
b: 5
then: "True Condition"
else: "False Condition"`,
test: !Op
a: 10
op: ">"
b: 5
then: "True Condition"
else: "False Condition"`,
expected: "\"True Condition\"",
},
{
name: "Nested All in test",
inputYAML: `!If
test: !All
- !Op
a: 10
op: ">"
b: 5
- !Op
a: [ ]
op: '!='
b: [ ]
then: "True Condition"
else: "False Condition"`,
test: !All
- !Op
a: 10
op: ">"
b: 5
- !Op
a: [ ]
op: '!='
b: [ ]
then: "True Condition"
else: "False Condition"`,
expected: "\"False Condition\"",
},
}
Expand Down
4 changes: 4 additions & 0 deletions prompto/emrichen/spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

pwd
cat README.md

0 comments on commit fe80b2c

Please sign in to comment.