mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-01-04 07:39:43 -06:00
* feat: add initial docs site * feat: allow workflows to be defined from go sdk * fix release action * chore: remove server dependencies from client * fix: use correct certificate for server * chore: add port and bind address to grpc config * fix: add env for grpc config * fix: nil pointer when output is null * chore: support variation in output args * fix unresolve merge conflict * fix: quickstart improvements * temp remove database url * fix: action id not required for event * fix: actionid validation for events * Remove deleted files
89 lines
2.0 KiB
Go
89 lines
2.0 KiB
Go
package datautils
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestRenderTemplateFields(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
data map[string]interface{}
|
|
input map[string]interface{}
|
|
expected map[string]interface{}
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "simple string template",
|
|
data: map[string]interface{}{"testing": "datavalue"},
|
|
input: map[string]interface{}{
|
|
"render": "{{ .testing }}",
|
|
},
|
|
expected: map[string]interface{}{
|
|
"render": "datavalue",
|
|
},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "nested map template",
|
|
data: map[string]interface{}{"testing": "nestedvalue"},
|
|
input: map[string]interface{}{
|
|
"nested": map[string]interface{}{
|
|
"render": "{{ .testing }}",
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"nested": map[string]interface{}{
|
|
"render": "nestedvalue",
|
|
},
|
|
},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "object template",
|
|
data: map[string]interface{}{"testing": `{ "nested": "nestedvalue" }`},
|
|
input: map[string]interface{}{
|
|
"nested": map[string]interface{}{
|
|
"render": "{{ .testing }}",
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"nested": map[string]interface{}{
|
|
"render": map[string]interface{}{
|
|
"nested": "nestedvalue",
|
|
},
|
|
},
|
|
},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "replace object",
|
|
data: map[string]interface{}{"testing": `{ "nested": "nestedvalue" }`},
|
|
input: map[string]interface{}{
|
|
"object": "{{ .testing }}",
|
|
},
|
|
expected: map[string]interface{}{
|
|
"nested": "nestedvalue",
|
|
},
|
|
wantErr: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
output, err := RenderTemplateFields(tt.data, tt.input)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("RenderTemplateFields() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !tt.wantErr {
|
|
jsonExpected, _ := json.Marshal(tt.expected)
|
|
jsonResult, _ := json.Marshal(output)
|
|
if string(jsonExpected) != string(jsonResult) {
|
|
t.Errorf("Expected %v, got %v", string(jsonExpected), string(jsonResult))
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|