Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
KenWilliamson committed Aug 30, 2023
1 parent 4a9eeea commit 75e09a3
Show file tree
Hide file tree
Showing 19 changed files with 1,470 additions and 25 deletions.
14 changes: 14 additions & 0 deletions delegates/blogDelegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ func (d *MCDelegate) GetBlogByName(name string, start int64, end int64) *[]Blog
return &rtn
}

// GetAdminBlogByName GetAdminBlogByName
func (d *MCDelegate) GetAdminBlogByName(name string, start int64, end int64) *[]Blog {
var artn []Blog
astartStr := strconv.FormatInt(start, 10)
aendStr := strconv.FormatInt(end, 10)
abrq, err := d.buildRequest(http.MethodGet, "/rs/blog/admin/get/name/"+name+"/"+astartStr+"/"+aendStr, nil, adminKey)
if err == nil {
gsuc, stat := d.proxy.Do(abrq, &artn)
d.Log.Debug("suc: ", gsuc)
d.Log.Debug("stat: ", stat)
}
return &artn
}

// GetBlogList GetBlogList
func (d *MCDelegate) GetBlogList(start int64, end int64) *[]Blog {
var rtn []Blog
Expand Down
77 changes: 77 additions & 0 deletions delegates/blogDelegate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,83 @@ func TestMCDelegate_GetBlogByName(t *testing.T) {
}
}



func TestMCDelegate_GetAdminBlogByName(t *testing.T) {

// var proxy px.GoProxy

var proxy px.MockGoProxy
proxy.MockDoSuccess1 = true
proxy.MockResp = &http.Response{
Status: "200",
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(`[{"id":5, "name":"test blog 12345--------"}]`)),
}
proxy.MockRespCode = 200

var l lg.Logger
log := l.New()
log.SetLogLevel(lg.AllLevel)

type fields struct {
proxy px.Proxy
Log lg.Log
RestURL string
APIKey string
APIAdminKey string
}
type args struct {
name string
start int64
end int64
}
tests := []struct {
name string
fields fields
args args
want *Blog
wantID int64
wantName string
wantLen int
}{
// TODO: Add test cases.
{
name: "test 1",
fields: fields{
proxy: proxy.New(),
Log: log,
RestURL: "http://localhost:3000",
APIAdminKey: "54211789991515",
APIKey: "557444414141",
},
args: args{
name: "test blog 12345--------",
start: 0,
end: 100,
},
wantID: 5,
wantName: "test blog 12345--------",
wantLen: 1,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
d := &MCDelegate{
proxy: tt.fields.proxy,
Log: tt.fields.Log,
RestURL: tt.fields.RestURL,
APIKey: tt.fields.APIKey,
APIAdminKey: tt.fields.APIAdminKey,
}
if got := d.GetAdminBlogByName(tt.args.name, tt.args.start, tt.args.end); len(*got) != tt.wantLen ||
(*got)[0].ID != tt.wantID || (*got)[0].Name != tt.wantName {
t.Errorf("MCDelegate.GetBlogByName() = %v, want %v", got, tt.want)
}
})
}
}

func TestMCDelegate_GetBlogList(t *testing.T) {

// var proxy px.GoProxy
Expand Down
4 changes: 4 additions & 0 deletions delegates/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Delegate interface {
UpdateBlog(b *Blog) *Response
GetBlog(bid int64) *Blog
GetBlogByName(name string, start int64, end int64) *[]Blog
GetAdminBlogByName(name string, start int64, end int64) *[]Blog
GetBlogList(start int64, end int64) *[]Blog
GetAdminBlogList(start int64, end int64) *[]Blog
ActivateBlog(b *Blog) *Response
Expand All @@ -72,4 +73,7 @@ type Delegate interface {
UpdateConfig(c *Config) *Response // UpdateConfig()
GetConfig() *Config // GetConfig()

AddRule(r *Rule) *ResponseID
UpdateRule(r *Rule) *Response
GetRule() *Rule
}
26 changes: 26 additions & 0 deletions delegates/mockDelegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ type MockDelegate struct {
MockConfig *Config

MockUpdateConfigRes *Response

MockAddRuleResp *ResponseID

MockUpdateRuleResp *Response

MockRule *Rule
}

// New New
Expand Down Expand Up @@ -194,6 +200,11 @@ func (d *MockDelegate) GetBlogByName(name string, start int64, end int64) *[]Blo
return d.MockBlogList
}

// GetAdminBlogByName GetAdminBlogByName
func (d *MockDelegate) GetAdminBlogByName(name string, start int64, end int64) *[]Blog {
return d.MockBlogList
}

// GetBlogList GetBlogList
func (d *MockDelegate) GetBlogList(start int64, end int64) *[]Blog {
return d.MockBlogList
Expand Down Expand Up @@ -283,3 +294,18 @@ func (d *MockDelegate) UpdateConfig(c *Config) *Response {
func (d *MockDelegate) GetConfig() *Config {
return d.MockConfig
}

// AddRule AddRule
func (d *MockDelegate) AddRule(r *Rule) *ResponseID {
return d.MockAddRuleResp
}

// UpdateRule UpdateRule
func (d *MockDelegate) UpdateRule(r *Rule) *Response {
return d.MockUpdateRuleResp
}

// GetRule GetRule
func (d *MockDelegate) GetRule() *Rule {
return d.MockRule
}
Loading

0 comments on commit 75e09a3

Please sign in to comment.