Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ as described above, ex `echo $p1 >> the_file.log`

# Environment variables in conversations
Any environment variable prefixed with `MOCKDEV_` will be available in conversations, when generating response body.
ex. `MOCDEV_FOO` will be available using `{{ .ENV.FOO }}`. The current bind address, and the bind port is available as:
`{{ .CFG.Address }}` and `{{ .CFG.Port }}` (_note that the `Address` will most likely be `""` meaning that mockdev is
ex. `MOCDEV_FOO` will be available using `{{ .env.FOO }}`. The current bind address, and the bind port is available as:
`{{ .cfg.Address }}` and `{{ .cfg.Port }}` (_note that the `Address` will most likely be `""` meaning that mockdev is
bound to all addresses_)

# Current Time in conversations
Expand Down
22 changes: 15 additions & 7 deletions mockhttp/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,26 @@ func (s *conversationScores) tieBreak(candidates []Conversation) (Conversation,
}
var ss []kv
for k, v := range s.values {
ss = append(ss, kv{k, v})
if c, found := lookupByName(candidates, k); found && !c.IsBreaking() {
ss = append(ss, kv{k, v - (c.Order * 100)})
}
}
sort.Slice(ss, func(i, j int) bool {
return ss[i].v > ss[j].v
})

for _, s := range ss {
for _, c := range candidates {
if s.k == c.Name {
return c, nil
}
if theOne, found := lookupByName(candidates, ss[0].k); found {
return theOne, nil
} else {
return Conversation{}, fmt.Errorf("that is wierd, no candidates found in score")
}
}

func lookupByName(haystack []Conversation, needle string) (Conversation, bool) {
for _, c := range haystack {
if c.Name == needle {
return c, true
}
}
return Conversation{}, fmt.Errorf("that is wierd, no candidates found in score")
return Conversation{}, false
}