当前位置: 首页>>代码示例>>Golang>>正文


Golang tests.ResetLog函数代码示例

本文整理汇总了Golang中github.com/ardanlabs/kit/tests.ResetLog函数的典型用法代码示例。如果您正苦于以下问题:Golang ResetLog函数的具体用法?Golang ResetLog怎么用?Golang ResetLog使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ResetLog函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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

示例2: 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

示例3: setupGraph

// setupGraph initializes an in-memory Cayley graph and logging for an individual test.
func setupGraph(t *testing.T) (*db.DB, *cayley.Handle, []map[string]interface{}) {
	tests.ResetLog()

	items, _, _, _, err := wirefix.Get()
	if err != nil {
		t.Fatalf("%s\tShould load item records from the fixture file : %v", tests.Failed, err)
	}
	t.Logf("%s\tShould load item records from the fixture file.", tests.Success)

	db, err := db.NewMGO(tests.Context, tests.TestSession)
	if err != nil {
		t.Fatalf("%s\tShould be able to get a Mongo session : %v", tests.Failed, err)
	}

	store, err := cayley.NewMemoryGraph()
	if err != nil {
		t.Fatalf("\t%s\tShould be able to create a new Cayley graph : %v", tests.Failed, err)
	}
	t.Logf("\t%s\tShould be able to create a new Cayley graph.", tests.Success)

	// Convert the items to maps.
	var itemMaps []map[string]interface{}
	for _, itm := range items {
		itemMap := map[string]interface{}{
			"type":    itm.Type,
			"item_id": itm.ID,
			"version": itm.Version,
			"data":    itm.Data,
		}
		itemMaps = append(itemMaps, itemMap)
	}

	return db, store, itemMaps
}
开发者ID:coralproject,项目名称:xenia,代码行数:35,代码来源:relationships_test.go

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例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: 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

示例13: 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

示例14: 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

示例15: 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


注:本文中的github.com/ardanlabs/kit/tests.ResetLog函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。