Skip to content

Commit

Permalink
Add name propeprty to Exeuction hash tags (+test)
Browse files Browse the repository at this point in the history
  • Loading branch information
krhubert committed Jan 9, 2019
1 parent b752a78 commit ead102d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
10 changes: 5 additions & 5 deletions execution/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ func (s Status) String() (r string) {
// Execution stores all informations about executions.
type Execution struct {
ID string `hash:"-"`
EventID string `hash:"eventID"`
EventID string `hash:"name:eventID"`
Status Status `hash:"-"`
Service *service.Service `hash:"service"`
TaskKey string `hash:"taskKey"`
Tags []string `hash:"tags"`
Inputs map[string]interface{} `hash:"inputs"`
Service *service.Service `hash:"name:service"`
TaskKey string `hash:"name:taskKey"`
Tags []string `hash:"name:tags"`
Inputs map[string]interface{} `hash:"name:inputs"`
OutputKey string `hash:"-"`
OutputData map[string]interface{} `hash:"-"`
Error string `hash:"-"`
Expand Down
24 changes: 24 additions & 0 deletions execution/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package execution
import (
"errors"
"testing"
"testing/quick"

"github.com/stretchr/testify/require"

"github.com/mesg-foundation/core/service"
"github.com/mesg-foundation/core/x/xstructhash"
)

var (
Expand Down Expand Up @@ -255,3 +257,25 @@ func TestStatus(t *testing.T) {
require.Equal(t, "completed", Completed.String())
require.Equal(t, "failed", Failed.String())
}

func TestExecutionIDHash(t *testing.T) {
ids := make(map[string]bool)

f := func(eventID, taskKey, inputs string, tags []string) bool {
e := Execution{
EventID: eventID,
TaskKey: taskKey,
Tags: tags,
Inputs: map[string]interface{}{inputs: "input"},
}

id := xstructhash.Hash(e, 1)
if ids[id] {
return false
}
ids[id] = true
return true
}

require.NoError(t, quick.Check(f, nil))
}

0 comments on commit ead102d

Please sign in to comment.