Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"article.go",
"dao.go",
"draft.go",
],
importpath = "go-common/app/interface/main/creative/dao/article",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/creative/conf:go_default_library",
"//app/interface/main/creative/model/article:go_default_library",
"//app/interface/openplatform/article/model:go_default_library",
"//app/interface/openplatform/article/rpc/client:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
go_test(
name = "go_default_test",
srcs = [
"article_test.go",
"dao_test.go",
"draft_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/main/creative/conf:go_default_library",
"//app/interface/main/creative/model/article:go_default_library",
"//app/interface/openplatform/article/model:go_default_library",
"//app/interface/openplatform/article/rpc/client:go_default_library",
"//library/ecode:go_default_library",
"//vendor/github.com/bouk/monkey:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,250 @@
package article
import (
"context"
"go-common/library/log"
"strconv"
"strings"
artMdl "go-common/app/interface/main/creative/model/article"
"go-common/app/interface/openplatform/article/model"
"go-common/library/ecode"
)
// Articles get article list.
func (d *Dao) Articles(c context.Context, mid int64, pn, ps, sort, group, category int, ip string) (res *model.CreationArts, err error) {
var arg = &model.ArgCreationArts{
Mid: mid,
Pn: pn,
Ps: ps,
Sort: sort,
Group: group,
Category: category,
RealIP: ip,
}
if res, err = d.art.CreationUpperArticles(c, arg); err != nil {
log.Error("d.art.CreationUpperArticles (%v) error(%v)", arg, err)
if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
err = ecode.CreativeArticleRPCErr
}
}
return
}
// Categories list all category contain child.
func (d *Dao) Categories(c context.Context, ip string) (res *model.Categories, err error) {
var arg = &model.ArgIP{
RealIP: ip,
}
if res, err = d.art.Categories(c, arg); err != nil {
log.Error("d.art.Categories (%v) error(%v)", arg, err)
if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
err = ecode.CreativeArticleRPCErr
}
}
return
}
// CategoriesMap list all category.
func (d *Dao) CategoriesMap(c context.Context, ip string) (res map[int64]*model.Category, err error) {
var arg = &model.ArgIP{
RealIP: ip,
}
if res, err = d.art.CategoriesMap(c, arg); err != nil {
log.Error("d.art.CategoriesMap (%v) error(%v)", arg, err)
if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
err = ecode.CreativeArticleRPCErr
}
}
return
}
// Article get article detail.
func (d *Dao) Article(c context.Context, aid, mid int64, ip string) (res *model.Article, err error) {
var arg = &model.ArgAidMid{
Aid: aid,
Mid: mid,
RealIP: ip,
}
if res, err = d.art.CreationArticle(c, arg); err != nil {
log.Error("d.art.CreationArticle (%v) error(%v)", arg, err)
if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
err = ecode.CreativeArticleRPCErr
}
}
if res == nil || res.Meta == nil {
return
}
log.Info("d.art.CreationArticle id (%d) words (%d)", res.Meta.ID, len(res.Content))
return
}
// AddArticle add article.
func (d *Dao) AddArticle(c context.Context, art *artMdl.ArtParam) (id int64, err error) {
var arg = &model.ArgArticle{
Aid: art.AID,
Mid: art.MID,
Category: art.Category,
State: art.State,
Reprint: art.Reprint,
TemplateID: art.TemplateID,
Title: art.Title,
BannerURL: art.BannerURL,
Content: art.Content,
Summary: art.Summary,
RealIP: art.RealIP,
Words: art.Words,
DynamicIntro: art.DynamicIntro,
ImageURLs: art.ImageURLs,
OriginImageURLs: art.OriginImageURLs,
ActivityID: art.ActivityID,
}
if art.Tags != "" {
arg.Tags = strings.Split(art.Tags, ",")
} else {
arg.Tags = []string{}
}
log.Info("d.art.AddArticle id (%d) words (%d) ImageURLs (%s) OriginImageURLs (%s)", arg.Aid, len(arg.Content), art.ImageURLs, art.OriginImageURLs)
if id, err = d.art.AddArticle(c, arg); err != nil {
arg.Content = ""
log.Error("d.art.AddArticle (%v) error(%v)", arg, err)
if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
err = ecode.CreativeArticleRPCErr
}
}
return
}
// UpdateArticle update article.
func (d *Dao) UpdateArticle(c context.Context, art *artMdl.ArtParam) (err error) {
var arg = &model.ArgArticle{
Aid: art.AID,
Mid: art.MID,
Category: art.Category,
State: art.State,
Reprint: art.Reprint,
TemplateID: art.TemplateID,
Title: art.Title,
BannerURL: art.BannerURL,
Content: art.Content,
Summary: art.Summary,
RealIP: art.RealIP,
Words: art.Words,
DynamicIntro: art.DynamicIntro,
ImageURLs: art.ImageURLs,
OriginImageURLs: art.OriginImageURLs,
}
if art.Tags != "" {
arg.Tags = strings.Split(art.Tags, ",")
} else {
arg.Tags = []string{}
}
log.Info("d.art.UpdateArticle id (%d) words (%d) ImageURLs (%s) OriginImageURLs (%s)", arg.Aid, len(arg.Content), art.ImageURLs, art.OriginImageURLs)
if err = d.art.UpdateArticle(c, arg); err != nil {
arg.Content = ""
log.Error("d.art.UpdateArticle (%v) error(%v)", arg, err)
if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
err = ecode.CreativeArticleRPCErr
}
}
return
}
// DelArticle delete article.
func (d *Dao) DelArticle(c context.Context, aid, mid int64, ip string) (err error) {
var arg = &model.ArgAidMid{
Aid: aid,
Mid: mid,
RealIP: ip,
}
if err = d.art.DelArticle(c, arg); err != nil {
log.Error("d.art.AddArticle (%v) error(%v)", arg, err)
if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
err = ecode.CreativeArticleRPCErr
}
}
return
}
// WithDrawArticle withdraw article.
func (d *Dao) WithDrawArticle(c context.Context, aid, mid int64, ip string) (err error) {
var arg = &model.ArgAidMid{
Aid: aid,
Mid: mid,
RealIP: ip,
}
if err = d.art.CreationWithdrawArticle(c, arg); err != nil {
log.Error("d.art.CreationWithdrawArticle (%v) error(%v)", arg, err)
if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
err = ecode.CreativeArticleRPCErr
}
}
return
}
// IsAuthor checks that whether user has permission to write article.
func (d *Dao) IsAuthor(c context.Context, mid int64, ip string) (res bool, err error) {
var arg = &model.ArgMid{
Mid: mid,
RealIP: ip,
}
if res, err = d.art.IsAuthor(c, arg); err != nil {
if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
log.Error("d.art.IsAuthor (%v) error(%v)", arg, err)
err = ecode.CreativeArticleRPCErr
}
}
return
}
// RemainCount article up limit.
func (d *Dao) RemainCount(c context.Context, mid int64, ip string) (res int, err error) {
var arg = &model.ArgMid{
Mid: mid,
RealIP: ip,
}
if res, err = d.art.ArticleRemainCount(c, arg); err != nil {
log.Error("d.art.ArticleRemainCount (%v) error(%v)", arg, err)
if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
err = ecode.CreativeArticleRPCErr
}
}
return
}
// ArticleStat article stat
func (d *Dao) ArticleStat(c context.Context, mid int64, ip string) (res model.UpStat, err error) {
arg := &model.ArgMid{Mid: mid, RealIP: ip}
if res, err = d.art.CreationUpStat(c, arg); err != nil {
log.Error("d.art.UpStat(%+v) error(%v)", arg, err)
if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
err = ecode.CreativeArticleRPCErr
}
}
return
}
// ThirtyDayArticle thirty day article
func (d *Dao) ThirtyDayArticle(c context.Context, mid int64, ip string) (res []*model.ThirtyDayArticle, err error) {
arg := &model.ArgMid{Mid: mid, RealIP: ip}
if res, err = d.art.CreationUpThirtyDayStat(c, arg); err != nil {
log.Error("d.art.CreationUpThirtyDayStat(%+v) error(%v)", arg, err)
if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
err = ecode.CreativeArticleRPCErr
}
}
return
}
// ArticleMetas batch get articles by aids.
func (d *Dao) ArticleMetas(c context.Context, aids []int64, ip string) (res map[int64]*model.Meta, err error) {
arg := &model.ArgAids{Aids: aids, RealIP: ip}
if res, err = d.art.ArticleMetas(c, arg); err != nil {
log.Error("d.art.ArticleMetas(%+v) error(%v)", arg, err)
if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
err = ecode.CreativeArticleRPCErr
}
}
log.Info("d.art.ArticleMetas aids(%v)", aids)
return
}

View File

@@ -0,0 +1,278 @@
package article
import (
"context"
artMdl "go-common/app/interface/main/creative/model/article"
"testing"
"go-common/app/interface/openplatform/article/model"
"go-common/app/interface/openplatform/article/rpc/client"
"go-common/library/ecode"
"reflect"
"github.com/bouk/monkey"
"github.com/smartystreets/goconvey/convey"
)
func TestArticleArticles(t *testing.T) {
var (
c = context.TODO()
mid = int64(1)
pn = int(0)
ps = int(0)
sort = int(0)
group = int(0)
category = int(0)
ip = ""
)
convey.Convey("Articles", t, func(ctx convey.C) {
// mock
mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.art), "CreationUpperArticles",
func(_ *client.Service, _ context.Context, _ *model.ArgCreationArts) (res *model.CreationArts, err error) {
return nil, ecode.CreativeArticleRPCErr
})
defer mock.Unpatch()
res, err := d.Articles(c, mid, pn, ps, sort, group, category, ip)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
ctx.So(res, convey.ShouldBeNil)
})
})
}
func TestArticleCategories(t *testing.T) {
var (
c = context.TODO()
ip = ""
)
convey.Convey("Categories", t, func(ctx convey.C) {
// mock
mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.art), "Categories",
func(_ *client.Service, _ context.Context, _ *model.ArgIP) (res *model.Categories, err error) {
return nil, ecode.CreativeArticleRPCErr
})
defer mock.Unpatch()
res, err := d.Categories(c, ip)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
ctx.So(res, convey.ShouldBeNil)
})
})
}
func TestArticleCategoriesMap(t *testing.T) {
var (
c = context.TODO()
ip = ""
)
convey.Convey("CategoriesMap", t, func(ctx convey.C) {
// mock
mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.art), "CategoriesMap",
func(_ *client.Service, _ context.Context, _ *model.ArgIP) (res map[int64]*model.Category, err error) {
return nil, ecode.CreativeArticleRPCErr
})
defer mock.Unpatch()
res, err := d.CategoriesMap(c, ip)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldEqual, 20017)
ctx.So(len(res), convey.ShouldEqual, 0)
})
})
}
func TestArticleArticle(t *testing.T) {
var (
c = context.TODO()
aid = int64(1198)
mid = int64(0)
ip = ""
)
convey.Convey("Article", t, func(ctx convey.C) {
// mock
mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.art), "CreationArticle",
func(_ *client.Service, _ context.Context, _ *model.ArgAidMid) (res *model.Article, err error) {
return nil, ecode.CreativeArticleRPCErr
})
defer mock.Unpatch()
res, err := d.Article(c, aid, mid, ip)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
ctx.So(res, convey.ShouldBeNil)
})
})
}
func TestArticleAddArticle(t *testing.T) {
var (
c = context.TODO()
art = &artMdl.ArtParam{}
)
convey.Convey("AddArticle", t, func(ctx convey.C) {
// mock
mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.art), "AddArticle",
func(_ *client.Service, _ context.Context, _ *model.ArgArticle) (id int64, err error) {
return 0, ecode.CreativeArticleRPCErr
})
defer mock.Unpatch()
id, err := d.AddArticle(c, art)
ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
ctx.So(id, convey.ShouldEqual, 0)
})
})
}
func TestArticleUpdateArticle(t *testing.T) {
var (
c = context.TODO()
art = &artMdl.ArtParam{}
)
convey.Convey("UpdateArticle", t, func(ctx convey.C) {
// mock
mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.art), "UpdateArticle",
func(_ *client.Service, _ context.Context, _ *model.ArgArticle) (err error) {
return ecode.CreativeArticleRPCErr
})
defer mock.Unpatch()
err := d.UpdateArticle(c, art)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
})
})
}
func TestArticleDelArticle(t *testing.T) {
var (
c = context.TODO()
aid = int64(0)
mid = int64(0)
ip = ""
)
convey.Convey("DelArticle", t, func(ctx convey.C) {
// mock
mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.art), "DelArticle",
func(_ *client.Service, _ context.Context, _ *model.ArgAidMid) (err error) {
return ecode.CreativeArticleRPCErr
})
defer mock.Unpatch()
err := d.DelArticle(c, aid, mid, ip)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
})
})
}
func TestArticleWithDrawArticle(t *testing.T) {
var (
c = context.TODO()
aid = int64(0)
mid = int64(0)
ip = ""
)
convey.Convey("WithDrawArticle", t, func(ctx convey.C) {
err := d.WithDrawArticle(c, aid, mid, ip)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
})
})
}
func TestArticleIsAuthor(t *testing.T) {
var (
c = context.TODO()
mid = int64(0)
ip = ""
)
convey.Convey("IsAuthor", t, func(ctx convey.C) {
// mock
mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.art), "IsAuthor",
func(_ *client.Service, _ context.Context, _ *model.ArgMid) (res bool, err error) {
return false, ecode.CreativeArticleRPCErr
})
defer mock.Unpatch()
res, err := d.IsAuthor(c, mid, ip)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
ctx.So(res, convey.ShouldEqual, false)
})
})
}
func TestArticleRemainCount(t *testing.T) {
var (
c = context.TODO()
mid = int64(0)
ip = ""
)
convey.Convey("ArticleRemainCount", t, func(ctx convey.C) {
// mock
mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.art), "ArticleRemainCount",
func(_ *client.Service, _ context.Context, _ *model.ArgMid) (res int, err error) {
return 0, ecode.CreativeArticleRPCErr
})
defer mock.Unpatch()
res, err := d.RemainCount(c, mid, ip)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
ctx.So(res, convey.ShouldEqual, 0)
})
})
}
func TestArticleArticleStat(t *testing.T) {
var (
c = context.TODO()
mid = int64(2333)
ip = ""
)
convey.Convey("ArticleStat", t, func(ctx convey.C) {
// mock
//mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.art), "CreationUpStat",
// func(_ *client.Service, _ context.Context, _ *model.ArgMid) (res model.UpStat, err error) {
// return new(model.UpStat), ecode.CreativeArticleRPCErr
// })
//defer mock.Unpatch()
res, err := d.ArticleStat(c, mid, ip)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
}
func TestArticleThirtyDayArticle(t *testing.T) {
var (
c = context.TODO()
mid = int64(0)
ip = ""
)
convey.Convey("ThirtyDayArticle", t, func(ctx convey.C) {
res, err := d.ThirtyDayArticle(c, mid, ip)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
ctx.So(res, convey.ShouldBeNil)
})
})
}
func TestArticleArticleMetas(t *testing.T) {
var (
c = context.TODO()
aids = []int64{233}
ip = ""
)
convey.Convey("ArticleMetas", t, func(ctx convey.C) {
//mock
mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.art), "ArticleMetas",
func(_ *client.Service, _ context.Context, _ *model.ArgAids) (res map[int64]*model.Meta, err error) {
return nil, ecode.CreativeArticleRPCErr
})
defer mock.Unpatch()
res, err := d.ArticleMetas(c, aids, ip)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
ctx.So(res, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,24 @@
package article
import (
"go-common/app/interface/main/creative/conf"
article "go-common/app/interface/openplatform/article/rpc/client"
)
// Dao is archive dao.
type Dao struct {
// config
c *conf.Config
// rpc
art *article.Service
}
// New init api url
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
// rpc
art: article.New(c.ArticleRPC),
}
return
}

View File

@@ -0,0 +1,35 @@
package article
import (
"flag"
"go-common/app/interface/main/creative/conf"
"os"
"testing"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.archive.creative")
flag.Set("conf_token", "96b6a6c10bb311e894c14a552f48fef8")
flag.Set("tree_id", "2305")
flag.Set("conf_version", "docker-1")
flag.Set("deploy_env", "uat")
flag.Set("conf_host", "config.bilibili.co")
flag.Set("conf_path", "/tmp")
flag.Set("region", "sh")
flag.Set("zone", "sh001")
} else {
flag.Set("conf", "../../cmd/creative.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
m.Run()
os.Exit(0)
}

View File

@@ -0,0 +1,99 @@
package article
import (
"context"
artMdl "go-common/app/interface/main/creative/model/article"
"go-common/app/interface/openplatform/article/model"
"go-common/library/ecode"
"go-common/library/log"
"strconv"
"strings"
)
// AddDraft add draft.
func (d *Dao) AddDraft(c context.Context, art *artMdl.ArtParam) (id int64, err error) {
var arg = &model.ArgArticle{
Aid: art.AID,
Mid: art.MID,
Category: art.Category,
State: art.State,
Reprint: art.Reprint,
TemplateID: art.TemplateID,
Title: art.Title,
BannerURL: art.BannerURL,
Content: art.Content,
Summary: art.Summary,
RealIP: art.RealIP,
Words: art.Words,
DynamicIntro: art.DynamicIntro,
ImageURLs: art.ImageURLs,
OriginImageURLs: art.OriginImageURLs,
}
if art.Tags != "" {
arg.Tags = strings.Split(art.Tags, ",")
} else {
arg.Tags = []string{}
}
log.Info("d.art.AddDraft id (%d) words (%d) ImageURLs (%s) OriginImageURLs (%s)", arg.Aid, len(arg.Content), art.ImageURLs, art.OriginImageURLs)
if id, err = d.art.AddArtDraft(c, arg); err != nil {
arg.Content = ""
log.Error("d.art.AddArtDraft (%v) error(%v)", arg, err)
if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
err = ecode.CreativeArticleRPCErr
}
}
return
}
// DelDraft delete draft.
func (d *Dao) DelDraft(c context.Context, aid, mid int64, ip string) (err error) {
var arg = &model.ArgAidMid{
Aid: aid,
Mid: mid,
RealIP: ip,
}
if err = d.art.DelArtDraft(c, arg); err != nil {
log.Error("d.art.DelArtDraft (%v) error(%v)", arg, err)
if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
err = ecode.CreativeArticleRPCErr
}
}
return
}
// Draft get draft detail.
func (d *Dao) Draft(c context.Context, aid, mid int64, ip string) (res *model.Draft, err error) {
var arg = &model.ArgAidMid{
Aid: aid,
Mid: mid,
RealIP: ip,
}
if res, err = d.art.ArtDraft(c, arg); err != nil {
log.Error("d.art.ArtDraft (%v) error(%v)", arg, err)
if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
err = ecode.CreativeArticleRPCErr
}
}
if res == nil || res.Meta == nil {
return
}
log.Info("d.art.CreationArticle id (%d) words (%d)", res.Meta.ID, len(res.Content))
return
}
// Drafts get draft list.
func (d *Dao) Drafts(c context.Context, mid int64, pn, ps int, ip string) (res *model.Drafts, err error) {
var arg = &model.ArgUpDraft{
Mid: mid,
Pn: pn,
Ps: ps,
RealIP: ip,
}
if res, err = d.art.UpperDrafts(c, arg); err != nil {
log.Error("d.art.UpperDrafts (%v) error(%v)", arg, err)
if _, er := strconv.ParseInt(err.Error(), 10, 64); er != nil {
err = ecode.CreativeArticleRPCErr
}
}
return
}

View File

@@ -0,0 +1,74 @@
package article
import (
"context"
"testing"
artMdl "go-common/app/interface/main/creative/model/article"
"go-common/library/ecode"
"github.com/smartystreets/goconvey/convey"
)
func TestArticleAddDraft(t *testing.T) {
var (
c = context.TODO()
art = &artMdl.ArtParam{}
)
convey.Convey("AddDraft", t, func(ctx convey.C) {
id, err := d.AddDraft(c, art)
ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotEqual, ecode.ArtCreationNoPrivilege)
ctx.So(id, convey.ShouldEqual, 0)
})
})
}
func TestArticleDelDraft(t *testing.T) {
var (
c = context.TODO()
aid = int64(1)
mid = int64(0)
ip = ""
)
convey.Convey("DelDraft", t, func(ctx convey.C) {
err := d.DelDraft(c, aid, mid, ip)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotEqual, ecode.ArtCreationNoPrivilege)
})
})
}
func TestArticleDraft(t *testing.T) {
var (
c = context.TODO()
aid = int64(0)
mid = int64(0)
ip = ""
)
convey.Convey("Draft", t, func(ctx convey.C) {
res, err := d.Draft(c, aid, mid, ip)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotEqual, ecode.ArtCreationNoPrivilege)
ctx.So(res, convey.ShouldBeNil)
})
})
}
func TestArticleDrafts(t *testing.T) {
var (
c = context.TODO()
mid = int64(0)
pn = int(0)
ps = int(0)
ip = ""
)
convey.Convey("Drafts", t, func(ctx convey.C) {
res, err := d.Drafts(c, mid, pn, ps, ip)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotEqual, ecode.ArtCreationNoPrivilege)
ctx.So(res, convey.ShouldBeNil)
})
})
}