From 5df33d692fa725f2d9f48d4a9c8fc3ab064e2c13 Mon Sep 17 00:00:00 2001 From: Tit Petric Date: Mon, 12 Nov 2018 19:35:53 +0100 Subject: [PATCH] upd(crm): add chart tests, fix tests --- crm/repository/chart.go | 8 ++++++-- crm/repository/chart_test.go | 27 +++++++++++++++++++++++++++ crm/repository/content_test.go | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 crm/repository/chart_test.go diff --git a/crm/repository/chart.go b/crm/repository/chart.go index e1d018452..a8dec8b3d 100644 --- a/crm/repository/chart.go +++ b/crm/repository/chart.go @@ -31,6 +31,10 @@ func (m *module) Chart(r *request.ModuleChart) (interface{}, error) { return nil, errors.Wrap(err, "Error creating statik filesystem") } - filename := "./chart-" + r.Kind + ".json" - return fs.ReadFile(statikFS, filename) + filename := "/chart-" + r.Kind + ".json" + body, err := fs.ReadFile(statikFS, filename) + if err != nil { + return nil, errors.Wrap(err, "Error when reading "+filename) + } + return body, err } diff --git a/crm/repository/chart_test.go b/crm/repository/chart_test.go new file mode 100644 index 000000000..2da72b89d --- /dev/null +++ b/crm/repository/chart_test.go @@ -0,0 +1,27 @@ +package repository + +import ( + "context" + "testing" + + "github.com/crusttech/crust/crm/rest/request" +) + +func TestModuleGraph(t *testing.T) { + repository := Module(context.TODO(), nil).With(context.Background(), nil) + + params := &request.ModuleChart{ + Kind: "line", + } + + { + _, err := repository.Chart(params) + assert(t, err == nil, "Error when getting module graph: %+v", err) + } + + { + params.Kind = "404" + _, err := repository.Chart(params) + assert(t, err != nil, "Expected error when getting chart for 404") + } +} diff --git a/crm/repository/content_test.go b/crm/repository/content_test.go index 45124f288..911e7ee37 100644 --- a/crm/repository/content_test.go +++ b/crm/repository/content_test.go @@ -118,7 +118,7 @@ func TestContent(t *testing.T) { assert(t, err == nil, "Error when retrieving contents: %+v", err) assert(t, len(mr.Contents) == 1, "Expected one content, got %d", len(mr.Contents)) assert(t, mr.Meta.Count == 1, "Expected Meta.Count == 1, got %d", mr.Meta.Count) - assert(t, mr.Contents[0].ModuleID == m.ModuleID, "Expected content module to match, %s != %s", m.ModuleID, mr.Contents[0].ModuleID) + assert(t, mr.Contents[0].ModuleID == m.ModuleID, "Expected content module to match, %d != %d", m.ModuleID, mr.Contents[0].ModuleID) } // fetch all contents by query