forked from motiv-labs/janus
/
context_api.go
40 lines (32 loc) · 927 Bytes
/
context_api.go
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
package bootstrap
import (
"time"
"github.com/DATA-DOG/godog"
"github.com/hellofresh/janus/pkg/api"
"github.com/pkg/errors"
)
// RegisterAPIContext registers godog suite context for handling API related steps
func RegisterAPIContext(s *godog.Suite, readOnly bool, apiRepo api.Repository, ch chan<- api.ConfigurationMessage) {
ctx := &apiContext{readOnly: readOnly, apiRepo: apiRepo, ch: ch}
s.BeforeScenario(ctx.clearAPI)
}
type apiContext struct {
readOnly bool
apiRepo api.Repository
ch chan<- api.ConfigurationMessage
}
func (c *apiContext) clearAPI(arg interface{}) {
if !c.readOnly {
data, err := c.apiRepo.FindAll()
if err != nil {
panic(errors.Wrap(err, "Failed to get all registered route specs"))
}
for _, definition := range data {
c.ch <- api.ConfigurationMessage{
Operation: api.RemovedOperation,
Configuration: definition,
}
}
time.Sleep(time.Second)
}
}