I want to write a protocol test. My current idea is to define a series of steps. Each Step contains a Trigger
and Expectation
- e.g. trigger MsgA
and expect MsgB
.
type Series struct {
Steps []Step
}
What I don't like about this, is that the Series
is not explicit: I would have to either create the slice in sequence and then hope it never gets messed up, and rely on it, or sort
it and then have to implement the sort funcs, which is utterly unnecessary.
What is a good design to formally define the Series
, and in this way make it explicit?
The best idea I have for now is to create a map with int
indexes:
type Series struct {
Steps map[int]Step
}
series := Series{
Steps: map[int]Step{
0: Step{},
1: Step{},
2: Step{},
...
}
}
Another option could be to build myself a linked list. go
doesn't have an implementation (afaik). It feels odd to have to build one myself for this. But such a solution would also loose the explicit feature a bit: Basically you always have to navigate through the linked list to get the whole sequence (e.g. "what is step 4").