This repository has been archived by the owner on Jan 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from RTradeLtd/queue/workers-2
Queue Cleanup + Additional Tests: TEM-126
- Loading branch information
Showing
264 changed files
with
3,478 additions
and
3,726 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,27 +1,101 @@ | ||
package api | ||
|
||
import ( | ||
"os" | ||
"net/http" | ||
"net/http/httptest" | ||
"net/url" | ||
"testing" | ||
"time" | ||
|
||
"github.com/RTradeLtd/config" | ||
"github.com/RTradeLtd/rtfs" | ||
"github.com/gin-gonic/gin" | ||
|
||
"github.com/RTradeLtd/config" | ||
"github.com/c2h5oh/datasize" | ||
) | ||
|
||
const ( | ||
tooManyCredits = 10.9999997e+07 | ||
testUser = "testuser" | ||
) | ||
|
||
func Test_new(t *testing.T) { | ||
func Test_API(t *testing.T) { | ||
cfg, err := config.LoadConfig("../testenv/config.json") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
ipfs, err := rtfs.NewManager(cfg.IPFS.APIConnection.Host+":"+cfg.IPFS.APIConnection.Port, nil, time.Minute*5) | ||
api, err := Initialize(cfg, true) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
api, err := new(cfg, gin.New(), ipfs, true, os.Stdout) | ||
if err = api.FileSizeCheck(int64(datasize.GB.Bytes() * 1)); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err = api.FileSizeCheck(int64(datasize.GB.Bytes() * 10)); err == nil { | ||
t.Fatal("error expected") | ||
} | ||
type args struct { | ||
paymentType string | ||
blockchain string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantErr bool | ||
}{ | ||
{"ETHFail", args{"ETH", "ETH"}, true}, | ||
{"ETHPass", args{"eth", "ethereum"}, false}, | ||
{"BTCFail", args{"BTC", "BTC"}, true}, | ||
{"BTCPass", args{"btc", "bitcoin"}, false}, | ||
{"LTCFail", args{"LTC", "LTC"}, true}, | ||
{"LTCPass", args{"ltc", "litecoin"}, false}, | ||
{"XMRFail", args{"XMR", "XMR"}, true}, | ||
{"XMRPass", args{"xmr", "monero"}, false}, | ||
{"DASHFail", args{"DASH", "DASH"}, true}, | ||
{"DASHPass", args{"dash", "dash"}, false}, | ||
{"InvalidCoinFail", args{"biiiitcoooonnneeeeeeecccct", "biiiitcoooonnneeeeeeecccct"}, true}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if _, err := api.getDepositAddress(tt.args.paymentType); (err != nil) != tt.wantErr { | ||
t.Errorf("getDepositAddress() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if valid := api.validateBlockchain(tt.args.blockchain); !valid != tt.wantErr { | ||
t.Errorf("validateBlockchain() error = %v, wantErr %v", valid, tt.wantErr) | ||
} | ||
}) | ||
} | ||
if err = api.validateUserCredits(testUser, 1); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err = api.validateUserCredits(testUser, tooManyCredits); err == nil { | ||
t.Fatal("error expected") | ||
} | ||
if err := api.validateAdminRequest(testUser); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := api.validateAdminRequest("notareallaccount"); err == nil { | ||
t.Fatal("error expected") | ||
} | ||
user, err := api.um.FindByUserName(testUser) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
api.setupRoutes() | ||
previousCreditAmount := user.Credits | ||
api.refundUserCredits(testUser, "ipfs-pin", 10) | ||
user, err = api.um.FindByUserName(testUser) | ||
if user.Credits != previousCreditAmount+10 { | ||
t.Fatal("failed to refund credits") | ||
} | ||
recorder := httptest.NewRecorder() | ||
testCtx, _ := gin.CreateTestContext(recorder) | ||
urlValues := url.Values{} | ||
urlValues.Add("suchkey", "muchvalue") | ||
testCtx.Request = &http.Request{PostForm: urlValues} | ||
forms := api.extractPostForms(testCtx, "suchkey") | ||
if len(forms) == 0 { | ||
t.Fatal("failed to extract post forms") | ||
} | ||
if forms["suchkey"] != "muchvalue" { | ||
t.Fatal("failed to extract proper postform") | ||
} | ||
} |
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
Oops, something went wrong.