本文整理汇总了Golang中github.com/ardanlabs/kit/tests.DisplayLog函数的典型用法代码示例。如果您正苦于以下问题:Golang DisplayLog函数的具体用法?Golang DisplayLog怎么用?Golang DisplayLog使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DisplayLog函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestAggregateGroup
func TestAggregateGroup(t *testing.T) {
tests.ResetLog()
defer tests.DisplayLog()
t.Log("Given the need aggregate across a form's submissions.")
{
url := "/v1/form/580627b42600e2035218509f/aggregate/all"
r := httptest.NewRequest("GET", url, nil)
w := httptest.NewRecorder()
a.ServeHTTP(w, r)
t.Logf("\tWhen calling aggregate endpoint: %s", url)
{
t.Log("\tWhen we user version v1 of the aggregate endpoint.")
if w.Code != 200 {
t.Fatalf("\t%s\tShould be able to get the aggregation keys : %v", tests.Failed, w.Code)
}
t.Logf("\t%s\tShould be able to get the aggregation keys .", tests.Success)
var ag form.Aggregation
if err := json.Unmarshal(w.Body.Bytes(), &ag); err != nil {
t.Fatalf("\t%s\tShould be able to unmarshal the results : %v", tests.Failed, err)
}
t.Logf("\t%s\tShould be able to unmarshal the results.", tests.Success)
if ag.Count != 9 {
t.Fatalf("\t%s\tShould have only one aggregation instead of %v.", tests.Failed, ag.Count)
}
t.Logf("\t%s\tShould have only one aggregation.", tests.Success)
}
}
}
开发者ID:coralproject,项目名称:xenia,代码行数:33,代码来源:aggregations_test.go
示例2: TestExec
// TestExec tests the execution of a specific query.
func TestExec(t *testing.T) {
tests.ResetLog()
defer tests.DisplayLog()
t.Log("Given the need to execute a specific query.")
{
url := "/v1/exec/" + qPrefix + "_basic?station_id=42021"
r := httptest.NewRequest("GET", url, nil)
w := httptest.NewRecorder()
a.ServeHTTP(w, r)
t.Logf("\tWhen calling url : %s", url)
{
if w.Code != http.StatusOK {
t.Fatalf("\t%s\tShould be able to retrieve the query : %v", tests.Failed, w.Code)
}
t.Logf("\t%s\tShould be able to retrieve the query.", tests.Success)
recv := tests.IndentJSON(w.Body.String())
resp := tests.IndentJSON(`{"results":[{"Name":"Basic","Docs":[{"name":"C14 - Pasco County Buoy, FL"}]}]}`)
if resp != recv {
t.Log(resp)
t.Log(recv)
t.Fatalf("\t%s\tShould get the expected result.", tests.Failed)
}
t.Logf("\t%s\tShould get the expected result.", tests.Success)
}
}
}
开发者ID:coralproject,项目名称:xenia,代码行数:32,代码来源:exec_test.go
示例3: TestDigest
// TestDigest tests the returning a form's digest
func TestDigest(t *testing.T) {
tests.ResetLog()
defer tests.DisplayLog()
t.Log("Given the need aggregate across a form's submissions.")
{
url := "/v1/form/580627b42600e2035218509f/digest"
r := httptest.NewRequest("GET", url, nil)
w := httptest.NewRecorder()
a.ServeHTTP(w, r)
t.Logf("\tWhen calling aggregate endpoint: %s", url)
{
t.Log("\tWhen we user version v1 of the aggregate endpoint.")
if w.Code != 200 {
t.Fatalf("\t%s\tShould be able to get the aggregation keys : %v", tests.Failed, w.Code)
}
t.Logf("\t%s\tShould be able to get the aggregation keys .", tests.Success)
var fm handlers.FormDigest
if err := json.Unmarshal(w.Body.Bytes(), &fm); err != nil {
t.Fatalf("\t%s\tShould be able to unmarshal the results : %v", tests.Failed, err)
}
t.Logf("\t%s\tShould be able to unmarshal the results.", tests.Success)
if len(fm.Questions) != 5 {
t.Fatalf("\t%s\tShould be able to return 1 question instead of %v.", tests.Failed, len(fm.Questions))
}
t.Logf("\t%s\tShould be able to return 1 question.", tests.Success)
}
}
}
开发者ID:coralproject,项目名称:xenia,代码行数:34,代码来源:aggregations_test.go
示例4: TestAggregateGroupSubmission
func TestAggregateGroupSubmission(t *testing.T) {
tests.ResetLog()
defer tests.DisplayLog()
t.Log("Given the need aggregate across a form's submissions.")
{
url := "/v1/form/580627b42600e2035218509f/aggregate/d452b94d-e650-41c6-80af-c56091315c90/submission"
r := httptest.NewRequest("GET", url, nil)
w := httptest.NewRecorder()
a.ServeHTTP(w, r)
t.Logf("\tWhen calling aggregate endpoint: %s", url)
{
t.Log("\tWhen we user version v1 of the aggregate endpoint.")
if w.Code != 200 {
t.Fatalf("\t%s\tShould be able to get the aggregation keys : %v", tests.Failed, w.Code)
}
t.Logf("\t%s\tShould be able to get the aggregation keys .", tests.Success)
var ta []form.TextAggregation
if err := json.Unmarshal(w.Body.Bytes(), &ta); err != nil {
t.Fatalf("\t%s\tShould be able to unmarshal the results : %v", tests.Failed, err)
}
t.Logf("\t%s\tShould be able to unmarshal the results.", tests.Success)
}
}
}
开发者ID:coralproject,项目名称:xenia,代码行数:28,代码来源:aggregations_test.go
示例5: TestMaskByName
// TestMaskByName tests the retrieval of a specific mask.
func TestMaskByName(t *testing.T) {
tests.ResetLog()
defer tests.DisplayLog()
t.Log("Given the need to get a specific mask.")
{
url := "/v1/mask/" + mCollection + "/observation_time"
r := httptest.NewRequest("GET", url, nil)
w := httptest.NewRecorder()
a.ServeHTTP(w, r)
t.Logf("\tWhen calling url : %s", url)
{
if w.Code != 200 {
t.Fatalf("\t%s\tShould be able to retrieve the mask : %v", tests.Failed, w.Code)
}
t.Logf("\t%s\tShould be able to retrieve the mask.", tests.Success)
var msk mask.Mask
if err := json.Unmarshal(w.Body.Bytes(), &msk); err != nil {
t.Fatalf("\t%s\tShould be able to unmarshal the results : %v", tests.Failed, err)
}
t.Logf("\t%s\tShould be able to unmarshal the results.", tests.Success)
if msk.Collection != mCollection && msk.Field != "observation_time" {
t.Fatalf("\t%s\tShould have the correct mask : %s - %s", tests.Failed, msk.Collection, msk.Field)
}
t.Logf("\t%s\tShould have the correct mask.", tests.Success)
}
}
}
开发者ID:coralproject,项目名称:xenia,代码行数:33,代码来源:mask_test.go
示例6: TestNamedOnView
// TestNamedOnView tests the execution of a specific named query on a view.
func TestNamedOnView(t *testing.T) {
tests.ResetLog()
defer tests.DisplayLog()
t.Log("Given the need to execute a specific query.")
{
url := "/v1/exec/" + qPrefix + "_basic_view/view/VTEST_thread/ITEST_c1b2bbfe-af9f-4903-8777-bd47c4d5b20a?item_of_interest=ITEST_d1dfa366-d2f7-4a4a-a64f-af89d4c97d82"
r := httptest.NewRequest("GET", url, nil)
w := httptest.NewRecorder()
a.ServeHTTP(w, r)
t.Logf("\tWhen calling url : %s", url)
{
if w.Code != http.StatusOK {
t.Fatalf("\t%s\tShould be able to retrieve the query : %v", tests.Failed, w.Code)
}
t.Logf("\t%s\tShould be able to retrieve the query.", tests.Success)
recv := tests.IndentJSON(w.Body.String())
resp := tests.IndentJSON(`{"results":[{"Name":"BasicView","Docs":[{"item_id":"ITEST_d1dfa366-d2f7-4a4a-a64f-af89d4c97d82"}]}]}`)
if resp != recv {
t.Log(resp)
t.Log(recv)
t.Fatalf("\t%s\tShould get the expected result.", tests.Failed)
}
t.Logf("\t%s\tShould get the expected result.", tests.Success)
}
}
}
开发者ID:coralproject,项目名称:xenia,代码行数:33,代码来源:exec_test.go
示例7: TestNoSession
// TestNoSession tests when a nil session is used.
func TestNoSession(t *testing.T) {
tests.ResetLog()
defer tests.DisplayLog()
t.Log("Given the need to test calls with a bad session.")
{
t.Log("\tWhen using a nil session")
{
if _, err := session.Create(tests.Context, nil, publicID, 10*time.Second); err == nil {
t.Errorf("\t%s\tShould Not be able to create a session.", tests.Failed)
} else {
t.Logf("\t%s\tShould Not be able to create a session.", tests.Success)
}
if _, err := session.GetBySessionID(tests.Context, nil, "NOT EXISTS"); err == nil {
t.Errorf("\t%s\tShould Not be able to retrieve the session.", tests.Failed)
} else {
t.Logf("\t%s\tShould Not be able to retrieve the session.", tests.Success)
}
if _, err := session.GetByLatest(tests.Context, nil, publicID); err == nil {
t.Errorf("\t%s\tShould Not be able to retrieve the session.", tests.Failed)
} else {
t.Logf("\t%s\tShould Not be able to retrieve the session.", tests.Success)
}
}
}
}
开发者ID:ramakrishna580,项目名称:kit,代码行数:29,代码来源:session_test.go
示例8: TestUDPAddr
// Test udp.Addr works correctly.
func TestUDPAddr(t *testing.T) {
tests.ResetLog()
defer tests.DisplayLog()
t.Log("Given the need to listen on any port and know that bound UDP address.")
{
// Create a configuration.
cfg := udp.Config{
NetType: "udp4",
Addr: ":0", // Defer port assignment to OS.
ConnHandler: udpConnHandler{},
ReqHandler: udpReqHandler{},
RespHandler: udpRespHandler{},
OptIntPool: udp.OptIntPool{
RecvMinPoolSize: func() int { return 2 },
RecvMaxPoolSize: func() int { return 1000 },
SendMinPoolSize: func() int { return 2 },
SendMaxPoolSize: func() int { return 1000 },
},
}
// Create a new UDP value.
u, err := udp.New("TEST", "TEST", cfg)
if err != nil {
t.Fatal("\tShould be able to create a new UDP listener.", tests.Failed, err)
}
t.Log("\tShould be able to create a new UDP listener.", tests.Success)
// Addr should be nil before start.
if addr := u.Addr(); addr != nil {
t.Fatalf("\tAddr() should be nil before Start; Addr() = %q. %s", addr, tests.Failed)
}
t.Log("\tAddr() should be nil before Start.", tests.Success)
// Start accepting client data.
if err := u.Start("TEST"); err != nil {
t.Fatal("\tShould be able to start the UDP listener.", tests.Failed, err)
}
defer u.Stop("TEST")
// Addr should be non-nil after Start.
addr := u.Addr()
if addr == nil {
t.Fatal("\tAddr() should be not be nil after Start.", tests.Failed)
}
t.Log("\tAddr() should be not be nil after Start.", tests.Success)
// The OS should assign a random open port, which shouldn't be 0.
_, port, err := net.SplitHostPort(addr.String())
if err != nil {
t.Fatalf("\tSplitHostPort should not fail. tests.Failed %v. %s", err, tests.Failed)
}
if port == "0" {
t.Fatalf("\tAddr port should not be %q. %s", port, tests.Failed)
}
t.Logf("\tAddr() should be not be 0 after Start (port = %q). %s", port, tests.Success)
}
}
开发者ID:ramakrishna580,项目名称:kit,代码行数:61,代码来源:udp_test.go
示例9: TestIsExpired
// TestIsExpired tests that we can properly identify when a
// session is expired or not.
func TestIsExpired(t *testing.T) {
tests.ResetLog()
defer tests.DisplayLog()
t.Log("Given the need to validate a session has expired.")
{
s := session.Session{
DateExpires: time.Now().Add(-time.Hour),
}
t.Log("\tWhen using an expired session.")
{
if !s.IsExpired(tests.Context) {
t.Fatalf("\t%s\tShould be expired.", tests.Failed)
}
t.Logf("\t%s\tShould be expired", tests.Success)
}
s = session.Session{
DateExpires: time.Now().Add(time.Hour),
}
t.Log("\tWhen using an valid session")
{
if s.IsExpired(tests.Context) {
t.Fatalf("\t%s\tShould Not be expired.", tests.Failed)
}
t.Logf("\t%s\tShould Not be expired", tests.Success)
}
}
}
开发者ID:ramakrishna580,项目名称:kit,代码行数:33,代码来源:session_test.go
示例10: TestRetrievePattern
// TestRetrievePattern tests the retrieval of a specific pattern.
func TestRetrievePattern(t *testing.T) {
tests.ResetLog()
defer tests.DisplayLog()
t.Log("Given the need to get a specific pattern.")
{
url := "/v1/pattern/" + patternPrefix + "comment"
r := httptest.NewRequest("GET", url, nil)
w := httptest.NewRecorder()
a.ServeHTTP(w, r)
t.Logf("\tWhen calling url : %s", url)
{
if w.Code != 200 {
t.Fatalf("\t%s\tShould be able to retrieve the pattern : %v", tests.Failed, w.Code)
}
t.Logf("\t%s\tShould be able to retrieve the pattern.", tests.Success)
var p pattern.Pattern
if err := json.Unmarshal(w.Body.Bytes(), &p); err != nil {
t.Fatalf("\t%s\tShould be able to unmarshal the results : %v", tests.Failed, err)
}
t.Logf("\t%s\tShould be able to unmarshal the results.", tests.Success)
if p.Type != patternPrefix+"comment" {
t.Fatalf("\t%s\tShould have the correct pattern : %s", tests.Failed, p.Type)
}
t.Logf("\t%s\tShould have the correct pattern.", tests.Success)
}
}
}
开发者ID:coralproject,项目名称:xenia,代码行数:33,代码来源:pattern_test.go
示例11: TestPool
// TestPool tests the pool is functional.
func TestPool(t *testing.T) {
tests.ResetLog()
defer tests.DisplayLog()
t.Log("Given the need to validate the work pool functions.")
{
cfg := pool.Config{
MinRoutines: func() int { return 100 },
MaxRoutines: func() int { return 5000 },
}
p, err := pool.New("TestPool", "Pool1", cfg)
if err != nil {
t.Fatal("\tShould not get error creating pool.", tests.Failed, err)
}
t.Log("\tShould not get error creating pool.", tests.Success)
for i := 0; i < 100; i++ {
p.Do("TestPool", &theWork{privateID: i})
}
time.Sleep(100 * time.Millisecond)
p.Shutdown("TestPool")
}
}
开发者ID:ramakrishna580,项目名称:kit,代码行数:27,代码来源:pool_test.go
示例12: TestScriptByName
// TestScriptByName tests the retrieval of a specific script.
func TestScriptByName(t *testing.T) {
tests.ResetLog()
defer tests.DisplayLog()
t.Log("Given the need to get a specific script.")
{
url := "/v1/script/" + sPrefix + "_basic_script_pre"
r := httptest.NewRequest("GET", url, nil)
w := httptest.NewRecorder()
a.ServeHTTP(w, r)
t.Logf("\tWhen calling url : %s", url)
{
if w.Code != 200 {
t.Fatalf("\t%s\tShould be able to retrieve the script : %v", tests.Failed, w.Code)
}
t.Logf("\t%s\tShould be able to retrieve the script.", tests.Success)
var scr script.Script
if err := json.Unmarshal(w.Body.Bytes(), &scr); err != nil {
t.Fatalf("\t%s\tShould be able to unmarshal the results : %v", tests.Failed, err)
}
t.Logf("\t%s\tShould be able to unmarshal the results.", tests.Success)
if scr.Name != sPrefix+"_basic_script_pre" {
t.Fatalf("\t%s\tShould have the correct script : %s", tests.Failed, scr.Name)
}
t.Logf("\t%s\tShould have the correct script.", tests.Success)
}
}
}
开发者ID:coralproject,项目名称:xenia,代码行数:33,代码来源:script_test.go
示例13: ExampleNew
// ExampleNew provides a basic example for using a pool.
func ExampleNew() {
tests.ResetLog()
defer tests.DisplayLog()
// Create a configuration.
cfg := pool.Config{
MinRoutines: func() int { return 3 },
MaxRoutines: func() int { return 4 },
}
// Create a new pool.
p, err := pool.New("TEST", "TheWork", cfg)
if err != nil {
fmt.Println(err)
return
}
// Pass in some work to be performed.
p.Do("TEST", &theWork{})
p.Do("TEST", &theWork{})
p.Do("TEST", &theWork{})
// Wait to the work to be processed.
time.Sleep(100 * time.Millisecond)
// Shutdown the pool.
p.Shutdown("TEST")
}
开发者ID:ramakrishna580,项目名称:kit,代码行数:29,代码来源:pool_test.go
示例14: TestSignaled
// TestSignaled tests when jobs is requested to shutdown.
func TestSignaled(t *testing.T) {
tests.ResetLog()
defer tests.DisplayLog()
t.Log("Given the need to test a task that is requested to shutdown.")
{
t.Log("\tWhen using a task that should see the signal.")
{
var job task
job.KillAfter(100 * time.Millisecond)
// Need the job method to quit as soon as we are done.
defer job.Kill()
go func() {
time.Sleep(50 * time.Millisecond)
syscall.Kill(syscall.Getpid(), syscall.SIGINT)
}()
if err := runner.Run(tests.Context, 3*time.Second, &job); err != runner.ErrSignaled {
t.Fatalf("\t%s\tShould receive a signaled error : %v", tests.Failed, err)
}
t.Logf("\t%s\tShould receive a signaled error.", tests.Success)
}
}
}
开发者ID:DmitryZinchenko,项目名称:kit,代码行数:27,代码来源:runner_test.go
示例15: TestActionsDELETE
// TestActionsDELETE sample test for the DELETE call.
func TestActionsDELETE(t *testing.T) {
tests.ResetLog()
defer tests.DisplayLog()
t.Log("Given the need to test DELETE action call.")
{
action := "flagged_by"
userID := "ITEST_a63af637-58af-472b-98c7-f5c00743bac6"
itemID := "ITEST_d1dfa366-d2f7-4a4a-a64f-af89d4c97d82"
url := fmt.Sprintf("/v1/action/%s/user/%s/on/item/%s", action, userID, itemID)
r := httptest.NewRequest("DELETE", url, nil)
w := httptest.NewRecorder()
a.ServeHTTP(w, r)
t.Logf("\tWhen calling url : %s", url)
{
t.Log("\tWhen we use version v1 of the actions endpoint.")
if w.Code != http.StatusOK {
t.Fatalf("\t%s\tShould be able to remove the action : %v", tests.Failed, w.Code)
}
t.Logf("\t%s\tShould be able to remove the action.", tests.Success)
}
}
}
开发者ID:coralproject,项目名称:xenia,代码行数:28,代码来源:action_test.go
示例16: TestRetrieveRelationship
// TestRetrieveRelationship tests the retrieval of a specific relationship.
func TestRetrieveRelationship(t *testing.T) {
tests.ResetLog()
defer tests.DisplayLog()
t.Log("Given the need to get a specific relationship.")
{
url := "/v1/relationship/" + relPrefix + "authored"
r := httptest.NewRequest("GET", url, nil)
w := httptest.NewRecorder()
a.ServeHTTP(w, r)
t.Logf("\tWhen calling url : %s", url)
{
if w.Code != 200 {
t.Fatalf("\t%s\tShould be able to retrieve the relationship : %v", tests.Failed, w.Code)
}
t.Logf("\t%s\tShould be able to retrieve the relationship.", tests.Success)
var rel relationship.Relationship
if err := json.Unmarshal(w.Body.Bytes(), &rel); err != nil {
t.Fatalf("\t%s\tShould be able to unmarshal the results : %v", tests.Failed, err)
}
t.Logf("\t%s\tShould be able to unmarshal the results.", tests.Success)
if rel.Predicate != relPrefix+"authored" {
t.Fatalf("\t%s\tShould have the correct relationship : %s", tests.Failed, rel.Predicate)
}
t.Logf("\t%s\tShould have the correct relationship.", tests.Success)
}
}
}
开发者ID:coralproject,项目名称:xenia,代码行数:33,代码来源:relationship_test.go
示例17: TestLoginUser
// TestLoginUser validates a user can login and not after changes.
func TestLoginUser(t *testing.T) {
tests.ResetLog()
defer tests.DisplayLog()
db, err := db.NewMGO(tests.Context, tests.TestSession)
if err != nil {
t.Fatalf("\t%s\tShould be able to get a Mongo session : %v", tests.Failed, err)
}
defer db.CloseMGO(tests.Context)
var publicID string
defer func() {
if err := removeUser(db, publicID); err != nil {
t.Fatalf("\t%s\tShould be able to remove the test user : %v", tests.Failed, err)
}
t.Logf("\t%s\tShould be able to remove the test user.", tests.Success)
}()
t.Log("Given the need to test user login.")
{
t.Log("\tWhen using a new user")
{
u1, err := auth.NewUser(auth.NUser{
Status: auth.StatusActive,
FullName: "Test Kennedy",
Email: "[email protected]",
Password: "_Password124",
})
if err != nil {
t.Fatalf("\t%s\tShould be able to build a new user : %v", tests.Failed, err)
}
t.Logf("\t%s\tShould be able to build a new user.", tests.Success)
if err := auth.CreateUser(tests.Context, db, u1); err != nil {
t.Fatalf("\t%s\tShould be able to create a user : %v", tests.Failed, err)
}
t.Logf("\t%s\tShould be able to create a user.", tests.Success)
// We need to do this so we can clean up after.
publicID = u1.PublicID
if _, err := auth.LoginUser(tests.Context, db, u1.Email, "_Password124"); err != nil {
t.Errorf("\t%s\tShould be able to login the user : %v", tests.Failed, err)
} else {
t.Logf("\t%s\tShould be able to login the user.", tests.Success)
}
if err := auth.UpdateUserPassword(tests.Context, db, u1, "password890"); err != nil {
t.Fatalf("\t%s\tShould be able to update the user password : %v", tests.Failed, err)
}
t.Logf("\t%s\tShould be able to update the user password.", tests.Success)
if _, err := auth.LoginUser(tests.Context, db, u1.Email, "_Password124"); err == nil {
t.Errorf("\t%s\tShould Not be able to login the user.", tests.Failed)
} else {
t.Logf("\t%s\tShould Not be able to login the user.", tests.Success)
}
}
}
}
开发者ID:decebal,项目名称:kit,代码行数:61,代码来源:auth_test.go
示例18: TestInvalidWebTokens
// TestInvalidWebTokens tests create an invalid web token and tests it fails.
func TestInvalidWebTokens(t *testing.T) {
tests.ResetLog()
defer tests.DisplayLog()
db, err := db.NewMGO(tests.Context, tests.TestSession)
if err != nil {
t.Fatalf("\t%s\tShould be able to get a Mongo session : %v", tests.Failed, err)
}
defer db.CloseMGO(tests.Context)
tokens := []string{
"",
"6dcda2da-92c3-11e5-8994-feff819cdc9f",
"OGY4OGI3YWQtZjc5Ny00ODI1LWI0MmUtMjIwZTY5ZDQxYjMzOmFKT2U1b0pFZlZ4cWUrR0JONEl0WlhmQTY0K3JsN2VGcmM2MVNQMkV1WVE9",
}
t.Log("Given the need to validate bad web tokens don't validate.")
{
for _, token := range tokens {
t.Logf("\tWhen using token [%s]", token)
{
if _, err := auth.ValidateWebToken(tests.Context, db, token); err == nil {
t.Errorf("\t%s\tShould Not be able to validate the web token : %v", tests.Failed, err)
} else {
t.Logf("\t%s\tShould Not be able to validate the web token.", tests.Success)
}
}
}
}
}
开发者ID:decebal,项目名称:kit,代码行数:31,代码来源:auth_test.go
示例19: TestDisableUser
// TestDisableUser test the disabling of a user.
func TestDisableUser(t *testing.T) {
tests.ResetLog()
defer tests.DisplayLog()
db, err := db.NewMGO(tests.Context, tests.TestSession)
if err != nil {
t.Fatalf("\t%s\tShould be able to get a Mongo session : %v", tests.Failed, err)
}
defer db.CloseMGO(tests.Context)
var publicID string
defer func() {
if err := removeUser(db, publicID); err != nil {
t.Fatalf("\t%s\tShould be able to remove the test user : %v", tests.Failed, err)
}
t.Logf("\t%s\tShould be able to remove the test user.", tests.Success)
}()
t.Log("Given the need to update a user.")
{
t.Log("\tWhen using an existing user.")
{
u1, err := auth.NewUser(auth.NUser{
Status: auth.StatusActive,
FullName: "Test Kennedy",
Email: "[email protected]",
Password: "_Password124",
})
if err != nil {
t.Fatalf("\t%s\tShould be able to build a new user : %v", tests.Failed, err)
}
t.Logf("\t%s\tShould be able to build a new user.", tests.Success)
if err := auth.CreateUser(tests.Context, db, u1); err != nil {
t.Fatalf("\t%s\tShould be able to create a user : %v", tests.Failed, err)
}
t.Logf("\t%s\tShould be able to create a user.", tests.Success)
// We need to do this so we can clean up after.
publicID = u1.PublicID
u2, err := auth.GetUserByPublicID(tests.Context, db, u1.PublicID, true)
if err != nil {
t.Fatalf("\t%s\tShould be able to retrieve the user by PublicID : %v", tests.Failed, err)
}
t.Logf("\t%s\tShould be able to retrieve the user by PublicID.", tests.Success)
if err := auth.UpdateUserStatus(tests.Context, db, u2.PublicID, auth.StatusDisabled); err != nil {
t.Fatalf("\t%s\tShould be able to disable the user : %v", tests.Failed, err)
}
t.Logf("\t%s\tShould be able to disable the user.", tests.Success)
if _, err := auth.GetUserByPublicID(tests.Context, db, u1.PublicID, true); err == nil {
t.Fatalf("\t%s\tShould Not be able to retrieve the user by PublicID.", tests.Failed)
}
t.Logf("\t%s\tShould Not be able to retrieve the user by PublicID.", tests.Success)
}
}
}
开发者ID:decebal,项目名称:kit,代码行数:60,代码来源:auth_test.go
示例20: TestModelInvalidation
// TestModelInvalidation tests things that can fail with model validation.
func TestModelInvalidation(t *testing.T) {
tests.ResetLog()
defer tests.DisplayLog()
t.Log("Given the need to validate models will invalidate with bad data.")
{
t.Log("\tWhen using a test user.")
{
var nu auth.NUser
if err := nu.Validate(); err == nil {
t.Errorf("\t%s\tShould Not be able to validate NUser value.", tests.Failed)
} else {
t.Logf("\t%s\tShould Not be able to validate NUser value.", tests.Success)
}
if _, err := auth.NewUser(nu); err == nil {
t.Errorf("\t%s\tShould Not be able to create a new user value.", tests.Failed)
} else {
t.Logf("\t%s\tShould Not be able to create a new user value.", tests.Success)
}
var u auth.User
if _, err := u.Pwd(); err == nil {
t.Errorf("\t%s\tShould Not be able to call Pwd is empty password.", tests.Failed)
} else {
t.Logf("\t%s\tShould Not be able to call Pwd is empty password.", tests.Success)
}
if _, err := u.Salt(); err == nil {
t.Errorf("\t%s\tShould Not be able to call Salt with bad values.", tests.Failed)
} else {
t.Logf("\t%s\tShould Not be able to call Salt with bad values.", tests.Success)
}
if _, err := u.WebToken(""); err == nil {
t.Errorf("\t%s\tShould Not be able to call WebToken with bad values.", tests.Failed)
} else {
t.Logf("\t%s\tShould Not be able to call WebToken with bad values.", tests.Success)
}
if ok := u.IsPasswordValid(""); ok {
t.Errorf("\t%s\tShould Not be able to call IsPasswordValid with empty password.", tests.Failed)
} else {
t.Logf("\t%s\tShould Not be able to call IsPasswordValid with empty password.", tests.Success)
}
u.Password = "123"
if ok := u.IsPasswordValid(""); ok {
t.Errorf("\t%s\tShould Not be able to call IsPasswordValid with bad password.", tests.Failed)
} else {
t.Logf("\t%s\tShould Not be able to call IsPasswordValid with bad password.", tests.Success)
}
}
}
}
开发者ID:decebal,项目名称:kit,代码行数:59,代码来源:auth_test.go
注:本文中的github.com/ardanlabs/kit/tests.DisplayLog函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论