Skip to content

Commit

Permalink
fix: removed not needed dependency from github.com/Masterminds/sprig
Browse files Browse the repository at this point in the history
  • Loading branch information
lansfy committed Jan 4, 2025
1 parent 3fe17a1 commit a94c835
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 94 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
go: ['1.18.x', '1.23.x']
#go: ['1.18.x', '1.23.x']
go: ['1.23.x']
steps:

- name: Set up Go
Expand Down
12 changes: 1 addition & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module github.com/lansfy/gonkex
go 1.18

require (
github.com/Masterminds/sprig/v3 v3.2.2
github.com/fatih/color v1.7.0
github.com/google/uuid v1.3.1
github.com/joho/godotenv v1.3.0
github.com/kylelemons/godebug v1.1.0
github.com/mattn/go-colorable v0.1.12
github.com/stretchr/testify v1.7.1
github.com/tidwall/gjson v1.17.0
golang.org/x/sync v0.4.0
Expand All @@ -16,20 +16,10 @@ require (
)

require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
)
36 changes: 0 additions & 36 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/Masterminds/sprig/v3 v3.2.2 h1:17jRggJu518dr3QaafizSXOjKYp94wKfABxUmyxvxX8=
github.com/Masterminds/sprig/v3 v3.2.2/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
Expand All @@ -27,21 +14,9 @@ github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tidwall/gjson v1.17.0 h1:/Jocvlh98kcTfpN2+JzGQWQcqrPQwDrVEMApx/M5ZwM=
Expand All @@ -50,27 +25,16 @@ github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e h1:T8NU3HyQ8ClP4SEE+KbFlg6n0NhuTsN4MyznaarGsZM=
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
54 changes: 43 additions & 11 deletions mocks/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,40 @@ package mocks
import (
"errors"
"fmt"
"text/template"
)

func loadDefinition(path string, rawDef interface{}) (*Definition, error) {
type Loader interface {
LoadDefinition(rawDef interface{}) (*Definition, error)
}

type YamlLoaderOpts struct {
TemplateReplyFuncs template.FuncMap
}

func NewYamlLoader(opts *YamlLoaderOpts) Loader {
var funcs template.FuncMap
if opts != nil {
funcs = opts.TemplateReplyFuncs
}
return &loaderImpl{
TemplateReplyFuncs: funcs,
}
}

type loaderImpl struct {
TemplateReplyFuncs template.FuncMap
}

func (l *loaderImpl) LoadDefinition(rawDef interface{}) (*Definition, error) {
def, err := l.loadDefinition("$", rawDef)
if err != nil {
return nil, err
}
return def, nil
}

func (l *loaderImpl) loadDefinition(path string, rawDef interface{}) (*Definition, error) {
def, ok := rawDef.(map[interface{}]interface{})
if !ok {
return nil, fmt.Errorf("at path %s: Definition must be key-values", path)
Expand Down Expand Up @@ -44,7 +75,7 @@ func loadDefinition(path string, rawDef interface{}) (*Definition, error) {
return fmt.Errorf("strategy '%s': %w", strategyName, err)
}

replyStrategy, err := loadStrategy(path, strategyName, def, &ak)
replyStrategy, err := l.loadStrategy(path, strategyName, def, &ak)
if err != nil {
return nil, wrap(err)
}
Expand All @@ -59,34 +90,35 @@ func loadDefinition(path string, rawDef interface{}) (*Definition, error) {
return NewDefinition(path, requestConstraints, replyStrategy, callsConstraint), nil
}

func loadStrategy(path, strategyName string, definition map[interface{}]interface{}, ak *[]string) (ReplyStrategy, error) {
func (l *loaderImpl) loadStrategy(path, strategyName string, definition map[interface{}]interface{},
ak *[]string) (ReplyStrategy, error) {
path = path + "." + strategyName
switch strategyName {
case "nop":
return NewNopReply(), nil
case "constant":
*ak = append(*ak, "body", "statusCode", "headers")
return loadConstantStrategy(path, definition)
return l.loadConstantStrategy(path, definition)
case "sequence":
*ak = append(*ak, "sequence")
return loadSequenceReplyStrategy(path, definition)
return l.loadSequenceReplyStrategy(path, definition)
case "template":
*ak = append(*ak, "body", "statusCode", "headers")
return loadTemplateReplyStrategy(path, definition)
return l.loadTemplateReplyStrategy(path, definition)
case "basedOnRequest":
*ak = append(*ak, "basePath", "uris")
return loadBasedOnRequestReplyStrategy(path, definition)
return l.loadBasedOnRequestReplyStrategy(path, definition)
case "file":
*ak = append(*ak, "filename", "statusCode", "headers")
return loadFileStrategy(path, definition)
return l.loadFileStrategy(path, definition)
case "uriVary":
*ak = append(*ak, "basePath", "uris")
return loadUriVaryReplyStrategy(path, definition)
return l.loadUriVaryReplyStrategy(path, definition)
case "methodVary":
*ak = append(*ak, "methods")
return loadMethodVaryStrategy(path, definition)
return l.loadMethodVaryStrategy(path, definition)
case "dropRequest":
return loadDropRequestStrategy(path, definition)
return l.loadDropRequestStrategy(path, definition)
default:
return nil, errors.New("unknown strategy")
}
Expand Down
7 changes: 4 additions & 3 deletions mocks/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,18 @@ func (m *Mocks) GetNames() []string {
return names
}

func (m *Mocks) LoadDefinitions(definitions map[string]interface{}) error {
func (m *Mocks) LoadDefinitions(loader Loader, definitions map[string]interface{}) error {
for serviceName, definition := range definitions {
service := m.Service(serviceName)
if service == nil {
return fmt.Errorf("unknown mock name: %s", serviceName)
}

err := service.LoadDefinition(definition)
def, err := loader.LoadDefinition(definition)
if err != nil {
return err
return fmt.Errorf("load definition for '%s': %w", serviceName, err)
}
service.SetDefinition(def)
}
return nil
}
11 changes: 0 additions & 11 deletions mocks/service_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package mocks

import (
"context"
"fmt"
"net"
"net/http"
"sync"
Expand Down Expand Up @@ -69,16 +68,6 @@ func (m *ServiceMock) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}

func (m *ServiceMock) LoadDefinition(newDefinition interface{}) error {
def, err := loadDefinition("$", newDefinition)
if err != nil {
return fmt.Errorf("load definition for '%s': %w", m.ServiceName, err)
}
// load the Definition into the mock
m.SetDefinition(def)
return nil
}

func (m *ServiceMock) SetDefinition(newDefinition *Definition) {
m.Lock()
defer m.Unlock()
Expand Down
4 changes: 2 additions & 2 deletions mocks/strategy_based_on_request_reply.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"
)

func loadBasedOnRequestReplyStrategy(path string, def map[interface{}]interface{}) (ReplyStrategy, error) {
func (l *loaderImpl) loadBasedOnRequestReplyStrategy(path string, def map[interface{}]interface{}) (ReplyStrategy, error) {
var uris []*Definition
if u, ok := def["uris"]; ok {
urisList, ok := u.([]interface{})
Expand All @@ -20,7 +20,7 @@ func loadBasedOnRequestReplyStrategy(path string, def map[interface{}]interface{
if !ok {
return nil, errors.New("`uris` list item must be a map")
}
def, err := loadDefinition(path+"."+strconv.Itoa(i), v)
def, err := l.loadDefinition(path+"."+strconv.Itoa(i), v)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions mocks/strategy_constant_reply.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
)

func loadFileStrategy(path string, def map[interface{}]interface{}) (ReplyStrategy, error) {
func (l *loaderImpl) loadFileStrategy(path string, def map[interface{}]interface{}) (ReplyStrategy, error) {
filename, err := getRequiredStringKey(def, "filename", false)
if err != nil {
return nil, err
Expand All @@ -25,7 +25,7 @@ func loadFileStrategy(path string, def map[interface{}]interface{}) (ReplyStrate
return NewConstantReplyWithCode(content, statusCode, headers), nil
}

func loadConstantStrategy(path string, def map[interface{}]interface{}) (ReplyStrategy, error) {
func (l *loaderImpl) loadConstantStrategy(path string, def map[interface{}]interface{}) (ReplyStrategy, error) {
body, err := getRequiredStringKey(def, "body", true)
if err != nil {
return nil, err
Expand Down
4 changes: 3 additions & 1 deletion mocks/strategy_constant_reply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ body: "Multi-header test"`,
},
}

loader := &loaderImpl{}

for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
// Create the reply strategy
var def map[interface{}]interface{}
err := yaml.Unmarshal([]byte(tt.content), &def)
require.NoError(t, err)

reply, err := loadConstantStrategy("$", def)
reply, err := loader.loadConstantStrategy("$", def)
require.NoError(t, err)

// Mock request and response
Expand Down
2 changes: 1 addition & 1 deletion mocks/strategy_drop_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
)

func loadDropRequestStrategy(path string, _ map[interface{}]interface{}) (ReplyStrategy, error) {
func (l *loaderImpl) loadDropRequestStrategy(path string, _ map[interface{}]interface{}) (ReplyStrategy, error) {
return NewDropRequestReply(), nil
}

Expand Down
4 changes: 2 additions & 2 deletions mocks/strategy_method_vary_reply.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
)

func loadMethodVaryStrategy(path string, def map[interface{}]interface{}) (ReplyStrategy, error) {
func (l *loaderImpl) loadMethodVaryStrategy(path string, def map[interface{}]interface{}) (ReplyStrategy, error) {
var methods map[string]*Definition
if u, ok := def["methods"]; ok {
methodsMap, ok := u.(map[interface{}]interface{})
Expand All @@ -15,7 +15,7 @@ func loadMethodVaryStrategy(path string, def map[interface{}]interface{}) (Reply
}
methods = make(map[string]*Definition, len(methodsMap))
for method, v := range methodsMap {
def, err := loadDefinition(path+"."+method.(string), v)
def, err := l.loadDefinition(path+"."+method.(string), v)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions mocks/strategy_sequential_reply.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"
)

func loadSequenceReplyStrategy(path string, def map[interface{}]interface{}) (ReplyStrategy, error) {
func (l *loaderImpl) loadSequenceReplyStrategy(path string, def map[interface{}]interface{}) (ReplyStrategy, error) {
if _, ok := def["sequence"]; !ok {
return nil, errors.New("`sequence` key required")
}
Expand All @@ -17,7 +17,7 @@ func loadSequenceReplyStrategy(path string, def map[interface{}]interface{}) (Re
}
strategies := make([]*Definition, len(seqSlice))
for i, v := range seqSlice {
def, err := loadDefinition(path+"."+strconv.Itoa(i), v)
def, err := l.loadDefinition(path+"."+strconv.Itoa(i), v)
if err != nil {
return nil, err
}
Expand Down
11 changes: 5 additions & 6 deletions mocks/strategy_template_reply.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import (
"net/http"
"sync"
"text/template"

"github.com/Masterminds/sprig/v3"
)

func loadTemplateReplyStrategy(path string, def map[interface{}]interface{}) (ReplyStrategy, error) {
func (l *loaderImpl) loadTemplateReplyStrategy(path string, def map[interface{}]interface{}) (ReplyStrategy, error) {
body, err := getRequiredStringKey(def, "body", true)
if err != nil {
return nil, err
Expand All @@ -24,11 +22,12 @@ func loadTemplateReplyStrategy(path string, def map[interface{}]interface{}) (Re
if err != nil {
return nil, err
}
return NewTemplateReply(body, statusCode, headers)
return NewTemplateReply(body, statusCode, headers, l.TemplateReplyFuncs)
}

func NewTemplateReply(content string, statusCode int, headers map[string]string) (ReplyStrategy, error) {
tmpl, err := template.New("").Funcs(sprig.GenericFuncMap()).Parse(content)
func NewTemplateReply(content string, statusCode int, headers map[string]string,
funcs template.FuncMap) (ReplyStrategy, error) {
tmpl, err := template.New("").Funcs(funcs).Parse(content)
if err != nil {
return nil, fmt.Errorf("template syntax error: %w", err)
}
Expand Down
Loading

0 comments on commit a94c835

Please sign in to comment.