-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75e09a3
commit eadc29a
Showing
26 changed files
with
3,476 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package delegates | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
) | ||
|
||
/* | ||
Copyright (C) 2023 Ulbora Labs LLC. (www.ulboralabs.com) | ||
All rights reserved. | ||
Copyright (C) 2023 Ken Williamson | ||
All rights reserved. | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
// AddAbout AddAbout | ||
func (d *MCDelegate) AddAbout(a *About) *ResponseID { | ||
var arrtn ResponseID | ||
aJSON, err := json.Marshal(a) | ||
if err == nil { | ||
aarq, err := d.buildRequest(http.MethodPost, "/rs/about/add", aJSON, adminKey) | ||
if err == nil { | ||
aasuc, stat := d.proxy.Do(aarq, &arrtn) | ||
arrtn.Code = int64(stat) | ||
d.Log.Debug("suc: ", aasuc) | ||
d.Log.Debug("stat: ", stat) | ||
} | ||
} | ||
d.Log.Debug("rtn: ", arrtn) | ||
return &arrtn | ||
} | ||
|
||
// UpdateAbout UpdateAbout | ||
func (d *MCDelegate) UpdateAbout(r *About) *Response { | ||
var uartn Response | ||
aJSON, err := json.Marshal(r) | ||
if err == nil { | ||
rq, err := d.buildRequest(http.MethodPut, "/rs/about/update", aJSON, adminKey) | ||
if err == nil { | ||
usuc, stat := d.proxy.Do(rq, &uartn) | ||
uartn.Code = int64(stat) | ||
d.Log.Debug("suc: ", usuc) | ||
d.Log.Debug("stat: ", stat) | ||
} | ||
} | ||
d.Log.Debug("rtn: ", uartn) | ||
return &uartn | ||
} | ||
|
||
// GetAbout GetAbout | ||
func (d *MCDelegate) GetAbout() *About { | ||
var rtn About | ||
arq, err := d.buildRequest(http.MethodGet, "/rs/about/get", nil, adminKey) | ||
if err == nil { | ||
gasuc, stat := d.proxy.Do(arq, &rtn) | ||
d.Log.Debug("suc: ", gasuc) | ||
d.Log.Debug("stat: ", stat) | ||
} | ||
return &rtn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
package delegates | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"net/http" | ||
"reflect" | ||
"testing" | ||
|
||
px "github.com/GolangToolKits/go-http-proxy" | ||
lg "github.com/GolangToolKits/go-level-logger" | ||
) | ||
|
||
func TestMCDelegate_AddAbout(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(`{"success":true, "id":5}`)), | ||
} | ||
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 { | ||
r *About | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want *ResponseID | ||
}{ | ||
// TODO: Add test cases. | ||
{ | ||
name: "test 1", | ||
fields: fields{ | ||
proxy: proxy.New(), | ||
Log: log, | ||
RestURL: "http://localhost:3000", | ||
APIAdminKey: "54211789991515", | ||
APIKey: "557444414141", | ||
}, | ||
args: args{ | ||
r: &About{ | ||
Content: "just some rule more content !!!!!!", | ||
}, | ||
}, | ||
want: &ResponseID{ | ||
ID: 5, | ||
Success: true, | ||
Code: 200, | ||
}, | ||
}, | ||
} | ||
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.AddAbout(tt.args.r); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("MCDelegate.AddRule() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestMCDelegate_UpdateAbout(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(`{"success":true}`)), | ||
} | ||
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 { | ||
r *About | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want *Response | ||
}{ | ||
// TODO: Add test cases. | ||
{ | ||
name: "test 1", | ||
fields: fields{ | ||
proxy: proxy.New(), | ||
Log: log, | ||
RestURL: "http://localhost:3000", | ||
APIAdminKey: "54211789991515", | ||
APIKey: "557444414141", | ||
}, | ||
args: args{ | ||
r: &About{ | ||
ID: 2, | ||
Content: "just some rule update more content !!!!!!", | ||
}, | ||
}, | ||
want: &Response{ | ||
Success: true, | ||
Code: 200, | ||
}, | ||
}, | ||
} | ||
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.UpdateAbout(tt.args.r); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("MCDelegate.UpdateRule() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestMCDelegate_GetAbout(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":2, "content": "test"}`)), | ||
} | ||
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 | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
want *About | ||
}{ | ||
// TODO: Add test cases. | ||
{ | ||
name: "test 1", | ||
fields: fields{ | ||
proxy: proxy.New(), | ||
Log: log, | ||
RestURL: "http://localhost:3000", | ||
APIAdminKey: "54211789991515", | ||
APIKey: "557444414141", | ||
}, | ||
|
||
want: &About{ | ||
ID: 2, | ||
Content: "test", | ||
}, | ||
}, | ||
} | ||
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.GetAbout(); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("MCDelegate.GetRule() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.