From fdc1e362399eeb7ebca84bfbbb8e4c92a36fcabc Mon Sep 17 00:00:00 2001 From: Tit Petric Date: Wed, 3 Apr 2019 15:09:23 +0200 Subject: [PATCH] upd(messaging): type updates, tests --- messaging/types/channel.go | 12 ++++++------ messaging/types/command.go | 6 ------ messaging/types/command_param.go | 9 +++++++++ messaging/types/main_test.go | 17 ----------------- messaging/types/mention_test.go | 10 +++++++--- 5 files changed, 22 insertions(+), 32 deletions(-) create mode 100644 messaging/types/command_param.go delete mode 100644 messaging/types/main_test.go diff --git a/messaging/types/channel.go b/messaging/types/channel.go index e2fb1636d..555347ca2 100644 --- a/messaging/types/channel.go +++ b/messaging/types/channel.go @@ -3,18 +3,18 @@ package types import ( "time" - "encoding/json" + "github.com/jmoiron/sqlx/types" "github.com/crusttech/crust/internal/rules" ) type ( Channel struct { - ID uint64 `json:"id" db:"id"` - Name string `json:"name" db:"name"` - Topic string `json:"topic" db:"topic"` - Type ChannelType `json:"type" db:"type"` - Meta json.RawMessage `json:"-" db:"meta"` + ID uint64 `json:"id" db:"id"` + Name string `json:"name" db:"name"` + Topic string `json:"topic" db:"topic"` + Type ChannelType `json:"type" db:"type"` + Meta types.JSONText `json:"-" db:"meta"` CreatorID uint64 `json:"creatorId" db:"rel_creator"` OrganisationID uint64 `json:"organisationId" db:"rel_organisation"` diff --git a/messaging/types/command.go b/messaging/types/command.go index 82994f3d5..4329155cf 100644 --- a/messaging/types/command.go +++ b/messaging/types/command.go @@ -6,12 +6,6 @@ type ( Params CommandParamSet `db:"params" json:"params"` Description string `db:"description" json:"description"` } - - CommandParam struct { - Name string `db:"name" json:"name"` - Type string `db:"type" json:"type"` - Required bool `db:"required" json:"required"` - } ) var ( diff --git a/messaging/types/command_param.go b/messaging/types/command_param.go new file mode 100644 index 000000000..49476756f --- /dev/null +++ b/messaging/types/command_param.go @@ -0,0 +1,9 @@ +package types + +type ( + CommandParam struct { + Name string `db:"name" json:"name"` + Type string `db:"type" json:"type"` + Required bool `db:"required" json:"required"` + } +) diff --git a/messaging/types/main_test.go b/messaging/types/main_test.go deleted file mode 100644 index 3625f8a10..000000000 --- a/messaging/types/main_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package types - -import ( - "fmt" - "runtime" - "testing" -) - -func assert(t *testing.T, ok bool, format string, args ...interface{}) bool { - if !ok { - _, file, line, _ := runtime.Caller(1) - caller := fmt.Sprintf("\nAsserted at:%s:%d", file, line) - - t.Fatalf(format+caller, args...) - } - return ok -} diff --git a/messaging/types/mention_test.go b/messaging/types/mention_test.go index 713124c2a..d1c5f6e1c 100644 --- a/messaging/types/mention_test.go +++ b/messaging/types/mention_test.go @@ -1,14 +1,18 @@ +// +build unit + package types import ( "testing" + + "github.com/crusttech/crust/internal/test" ) func TestMentionSet_Diff(t *testing.T) { ex := MentionSet{&Mention{ID: 1000}, &Mention{ID: 1001}} add, upd, del := ex.Diff(MentionSet{&Mention{ID: 1001}, &Mention{UserID: 1}}) - assert(t, len(add) == 1 && len(add.FindByUserID(1)) == 1, "Did not find expected mention (UserID:1) for creation") - assert(t, len(upd) == 1 && upd.FindByID(1001) != nil, "Did not find expected mention (id:1001) for update") - assert(t, len(del) == 1 && del.FindByID(1000) != nil, "Did not find expected mention (id:1000) for removal") + test.Assert(t, len(add) == 1 && len(add.FindByUserID(1)) == 1, "Did not find expected mention (UserID:1) for creation") + test.Assert(t, len(upd) == 1 && upd.FindByID(1001) != nil, "Did not find expected mention (id:1001) for update") + test.Assert(t, len(del) == 1 && del.FindByID(1000) != nil, "Did not find expected mention (id:1000) for removal") }