• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang ln.SetOutput函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestEditUserProfileError

func TestEditUserProfileError(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	ln.SetOutput(ioutil.Discard, "test_logger")

	someProfile := client.UserProfile{
		UserID:    23,
		Phone:     "123-123-1234",
		Website:   "www.google.com",
		FirstName: "Homer",
		LastName:  "Simpson",
		Address1:  "12345 Seasame St.",
		City:      "Springfield",
		State:     "IL",
		Zip:       "11252",
		Country:   "USA",
		Company:   "Simpsons",
	}
	fakeClient := clientfakes.NewFakeClient()
	fakeClient.RegisterFunction("editUserProfile", func(params url.Values) (interface{}, error) {
		return 0, errors.New("some serious error happened")
	})

	adaptor := New(fakeClient)

	success, err := adaptor.EditUserProfile(&someProfile)

	require.NotNil(t, err)
	assert.False(t, success)
}
开发者ID:john-cai,项目名称:tools,代码行数:30,代码来源:user_service_test.go


示例2: TestGetSubusers

func TestGetSubusers(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	expected := []client.Subuser{
		{
			ID:       1,
			Username: "dustin",
			Email:    "[email protected]",
		}, {
			ID:       2,
			Username: "jovel",
			Email:    "[email protected]",
		},
	}

	fakeClient := clientfakes.NewFakeClient()
	fakeClient.RegisterFunction("getSubusers", func(params url.Values) (interface{}, error) {
		return expected, nil
	})

	adaptor := New(fakeClient)
	actual, adaptorError := adaptor.GetSubusers(&client.SubuserRequest{UserID: 180})

	assert.Nil(t, adaptorError)
	if assert.NotNil(t, actual) {
		assert.Equal(t, len(expected), len(actual))
		for i, _ := range actual {
			assert.Equal(t, expected[i].ID, actual[i].ID)
			assert.Equal(t, expected[i].Username, actual[i].Username)
			assert.Equal(t, expected[i].Email, actual[i].Email)
		}
	}
}
开发者ID:john-cai,项目名称:tools,代码行数:33,代码来源:subuser_test.go


示例3: TestAddFiltersInvalid

func TestAddFiltersInvalid(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	user := client.Signup{
		Username: "username",
		UserID:   1,
		Password: "password",
		Email:    "[email protected]",
	}

	fakeClient := clientfakes.NewFakeClient()
	fakeClient.RegisterFunction("enableUserFilter", func(params url.Values) (interface{}, error) {
		return 1, nil
	})

	expectedApidError := fmt.Errorf("apid internal server error")

	fakeClient.RegisterFunction("addUserFilters", func(params url.Values) (interface{}, error) {
		return 0, expectedApidError
	})
	adaptor := New(fakeClient)
	errs := adaptor.AddFilters(user)

	assert.Len(t, errs, 4)
	assert.Equal(t, errs[0], expectedApidError)
	assert.Equal(t, errs[1], expectedApidError)
	assert.Equal(t, errs[2], expectedApidError)
	assert.Equal(t, errs[3], expectedApidError)
}
开发者ID:john-cai,项目名称:tools,代码行数:29,代码来源:signup_test.go


示例4: TestGetSignupPackageInfoValid

func TestGetSignupPackageInfoValid(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	// Apid return free package
	fakeClient := clientfakes.NewFakeClient()

	expectedResponse := client.PackageRecord{ID: 1, IsFree: 1, PackageGroupID: 1, Credits: 12000}
	fakeClient.RegisterFunction("get", func(params url.Values) (interface{}, error) {
		return []client.PackageRecord{expectedResponse}, nil
	})

	adaptor := New(fakeClient)

	freePackage := adaptor.GetSignupPackageInfo("abc")
	assert.Equal(t, expectedResponse, freePackage)

	// Apid return paid package, then our function will return 12k Free package
	fakeClient = clientfakes.NewFakeClient()

	fakeClient.RegisterFunction("get", func(params url.Values) (interface{}, error) {
		return []client.PackageRecord{client.PackageRecord{ID: 1, IsFree: 0, PackageGroupID: 1, Credits: 12000}}, nil
	})

	adaptor = New(fakeClient)

	freePackage = adaptor.GetSignupPackageInfo("abc")
	assert.Equal(t, client.PackageRecord{ID: FreePackageID, IsFree: 1, PackageGroupID: FreePackageGroupID, Credits: FreeAccountCreditsLimits}, freePackage)
}
开发者ID:john-cai,项目名称:tools,代码行数:28,代码来源:signup_test.go


示例5: TestAddUserPackageForSubuser

func TestAddUserPackageForSubuser(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	fakeClient := clientfakes.NewFakeClient()
	addPackageSpy := fakeClient.RegisterFunction("add", func(param url.Values) (interface{}, error) {
		return "success", nil
	})

	adaptor := New(fakeClient)

	err := adaptor.AddUserPackage(
		client.Signup{
			UserID:            180,
			ResellerID:        888,
			UserPackageStatus: 444,
		})
	assert.Len(t, err, 0)

	//verify subuser params are removed
	params := addPackageSpy.CalledParams["values"][0]
	exists := strings.Contains(params, "package_id")
	assert.False(t, exists, "package id should be null")
	exists = strings.Contains(params, "package_group_id")
	assert.False(t, exists, "package group id should be null")
	exists = strings.Contains(params, "package_status")
	assert.False(t, exists, "package status should be null")

	//verify subuser params is modified
	re := regexp.MustCompile(`{"status":"(\d*)"}`)
	matches := re.FindAllStringSubmatch(params, -1)
	status := matches[0][1]
	exists = strings.Contains(params, "status")
	assert.True(t, exists, "status is passed through")
	assert.Equal(t, "444", status, "status should be pass through") //default is 1 = SendGrid Free
}
开发者ID:john-cai,项目名称:tools,代码行数:35,代码来源:signup_test.go


示例6: TestEditUserNoUpdate

func TestEditUserNoUpdate(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	// When a call is made to update a user, but there are no changes in the db
	// (If we are editing to the same info the user already has in the db)
	userID := 23
	var actualParams url.Values

	fakeClient := clientfakes.NewFakeClient()
	fakeClient.RegisterFunction("editUser", func(params url.Values) (interface{}, error) {
		actualParams = params
		return 0, nil
	})

	adaptor := New(fakeClient)

	request := &client.User{
		ID:             userID,
		AccountOwnerID: 123,
		Username:       "jake_the_dog",
		Email:          "[email protected]",
	}

	actual, adaptorErr := adaptor.EditUser(request)

	assert.NoError(t, adaptorErr)
	assert.Equal(t, actualParams, url.Values{"userid": []string{strconv.Itoa(userID)}, "reseller_id": []string{"123"}, "username": []string{"jake_the_dog"}, "email": []string{"[email protected]"}})
	assert.True(t, actual)
}
开发者ID:john-cai,项目名称:tools,代码行数:29,代码来源:user_service_test.go


示例7: TestAddFiltersValid

func TestAddFiltersValid(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	user := client.Signup{
		Username: "username",
		UserID:   1,
		Password: "password",
		Email:    "[email protected]",
	}

	// filter already enabled
	fakeClient := clientfakes.NewFakeClient()
	fakeClient.RegisterFunction("enableUserFilter", func(params url.Values) (interface{}, error) {
		return 1, nil
	})

	// no errors, but register one row updated
	fakeClient.RegisterFunction("addUserFilters", func(params url.Values) (interface{}, error) {
		return 1, nil
	})
	adaptor := New(fakeClient)
	errs := adaptor.AddFilters(user)

	assert.Len(t, errs, 0)
}
开发者ID:john-cai,项目名称:tools,代码行数:25,代码来源:signup_test.go


示例8: TestGetEmptyUser

func TestGetEmptyUser(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	userID := 23

	expected := User{ID: userID}

	fakeClient := clientfakes.NewFakeClient()

	fakeClient.RegisterFunction("getUserInfo", func(params url.Values) (interface{}, error) {
		userIDFromParams, _ := strconv.Atoi(params.Get("userid"))
		switch userIDFromParams {
		case userID:
			return expected, nil
		}

		return nil, fmt.Errorf("not a valid call")
	})

	adaptor := New(fakeClient)

	actual, adaptorErr := adaptor.GetUser(userID)

	require.Nil(t, adaptorErr)
	require.NotNil(t, actual)
	assert.Equal(t, expected.ID, actual.ID)
	assert.Equal(t, expected.Username, actual.Username)
	assert.Equal(t, expected.AccountOwnerID, actual.AccountOwnerID)
	assert.Equal(t, expected.AccountID, actual.AccountID)
}
开发者ID:john-cai,项目名称:tools,代码行数:30,代码来源:user_service_test.go


示例9: TestCreateUserError

func TestCreateUserError(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	expectedNewUserID := 1234

	// value to be passed into apid
	expectedUsername := "test_user"

	// expected output from apidadaptor
	expectedErr := adaptor.NewError("error when adding user")

	fakeClient := clientfakes.NewFakeClient()
	fakeClient.RegisterFunction("addUser", func(params url.Values) (interface{}, error) {
		username := params.Get("username")
		if username == expectedUsername {
			return 0, fmt.Errorf("some apid error")
		}
		return expectedNewUserID, nil
	})

	adaptor := New(fakeClient)

	_, adaptorErr := adaptor.CreateUser(
		client.Signup{
			Username: expectedUsername,
			Email:    "[email protected]",
			Password: "asdfasdf",
		})

	if assert.NotNil(t, adaptorErr, adaptorErr.Error()) {
		assert.Equal(t, expectedErr.Error(), adaptorErr.Error())
		assert.Equal(t, expectedErr.SuggestedStatusCode, adaptorErr.SuggestedStatusCode)
	}
}
开发者ID:john-cai,项目名称:tools,代码行数:34,代码来源:signup_test.go


示例10: TestUpdateURLMailDomainFailure

func TestUpdateURLMailDomainFailure(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	fakeClient := clientfakes.NewFakeClient()

	var actualParams url.Values
	err := errors.New("error")

	fakeClient.RegisterFunction("update", func(params url.Values) (interface{}, error) {
		actualParams = params
		return nil, err
	})

	adaptor := New(fakeClient)
	testUserID := 1
	testUrlDomain := fmt.Sprintf("u%d.ct.sendgrid.net", testUserID)
	testMailDomain := "sendgrid.net"

	updateErr := adaptor.UpdateURLMailDomain(testUserID)

	assert.NotNil(t, updateErr)
	assert.Equal(t, actualParams.Get("tableName"), "user")
	assert.Equal(t, actualParams.Get("where"), fmt.Sprintf(`{"id" : "%d"}`, testUserID))
	assert.Equal(t, actualParams.Get("values"), fmt.Sprintf(`[{"url_domain": "%s"},{"mail_domain": "%s"}]`, testUrlDomain, testMailDomain))
}
开发者ID:john-cai,项目名称:tools,代码行数:25,代码来源:signup_test.go


示例11: TestAddIPGroup

func TestAddIPGroup(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	missingUserIDError := errors.New("missing userid")

	fakeClient := clientfakes.NewFakeClient()
	fakeClient.RegisterFunction("addUserIpGroup", func(param url.Values) (interface{}, error) {
		if param.Get("userid") == "0" {
			return 0, missingUserIDError
		}

		return 1, nil
	})

	adaptor := New(fakeClient)

	// test good case
	err := adaptor.AddIPGroup(
		client.Signup{
			UserID: 180,
		})
	assert.Len(t, err, 0)

	// test missing user error
	err = adaptor.AddIPGroup(client.Signup{})

	assert.Len(t, err, 1)
	assert.Equal(t, missingUserIDError, err[0])

}
开发者ID:john-cai,项目名称:tools,代码行数:30,代码来源:signup_test.go


示例12: TestEditUser

func TestEditUser(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	userID := 23
	var actualParams url.Values

	fakeClient := clientfakes.NewFakeClient()
	fakeClient.RegisterFunction("editUser", func(params url.Values) (interface{}, error) {
		actualParams = params
		return 1, nil
	})

	adaptor := New(fakeClient)
	request := &client.User{
		ID:             userID,
		AccountOwnerID: 123,
		Username:       "jake_the_dog",
		Email:          "[email protected]",
	}

	actual, adaptorErr := adaptor.EditUser(request)

	assert.NoError(t, adaptorErr)
	assert.Equal(t, actualParams, url.Values{"userid": []string{strconv.Itoa(userID)}, "reseller_id": []string{"123"}, "username": []string{"jake_the_dog"}, "email": []string{"[email protected]"}})
	assert.True(t, actual)
}
开发者ID:john-cai,项目名称:tools,代码行数:26,代码来源:user_service_test.go


示例13: TestInsertDeactivationReaonsApidErr

func TestInsertDeactivationReaonsApidErr(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	fakeClient := clientfakes.NewFakeClient()
	expectedValidReasons := []userChurnReason{
		userChurnReason{ID: 1, Reason: "reason_a"},
		userChurnReason{ID: 2, Reason: "reason_b"},
	}
	fakeClient.RegisterFunction("get", func(params url.Values) (interface{}, error) {
		if params.Get("tableName") == "competitors" {
			return []competitor{competitor{ID: 3}}, nil
		}
		return expectedValidReasons, nil
	})
	fakeClient.RegisterFunction("add", func(params url.Values) (interface{}, error) {
		if params.Get("tableName") == "competitors" {
			return "success", nil
		}
		return "", errors.New("some apid error adding to user_churn")
	})

	adaptor := New(fakeClient)
	reason := "reason_a"
	moving := true
	inHouse := true
	adaptorErr := adaptor.InsertDeactivationReason(1800, reason, moving, inHouse, "new provider", "notes on why")

	require.NotNil(t, adaptorErr, "should error")
}
开发者ID:john-cai,项目名称:tools,代码行数:29,代码来源:user_package_test.go


示例14: TestGetUserByUsernameSlaveFailMasterSuccess

func TestGetUserByUsernameSlaveFailMasterSuccess(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	username := "mrpickles"

	bad := User{ID: 0}
	expected := User{ID: 123, Username: username, AccountOwnerID: 4000, AccountID: "iamanaccountid"}

	fakeClient := clientfakes.NewFakeClient()
	fakeClient.RegisterFunction("getUserInfo", func(params url.Values) (interface{}, error) {
		return bad, nil
	})

	fakeClient.RegisterFunction("getUserInfoMaster", func(params url.Values) (interface{}, error) {
		return expected, nil
	})

	adaptor := New(fakeClient)
	actual, clientErr := adaptor.GetUserByUsername(username)

	assert.Nil(t, clientErr)
	require.NotNil(t, actual)
	assert.Equal(t, expected.ID, actual.ID)
	assert.Equal(t, expected.Username, actual.Username)
	assert.Equal(t, expected.AccountOwnerID, actual.AccountOwnerID)
	assert.Equal(t, expected.AccountID, actual.AccountID)
}
开发者ID:john-cai,项目名称:tools,代码行数:27,代码来源:user_service_test.go


示例15: TestGetUserHolds

func TestGetUserHolds(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	var userIDFromParams int

	expected := UserHolds{
		"10":  "test",
		"101": "test2",
	}

	fakeClient := clientfakes.NewFakeClient()
	fakeClient.RegisterFunction("getUserHolds", func(params url.Values) (interface{}, error) {
		userIDFromParams, _ = strconv.Atoi(params.Get("userid"))
		return expected, nil
	})

	adaptor := New(fakeClient)

	actual, err := adaptor.GetUserHolds(23)

	require.Nil(t, err)
	require.NotNil(t, actual)
	assert.Equal(t, actual, expected)
	assert.Equal(t, userIDFromParams, 23)
}
开发者ID:john-cai,项目名称:tools,代码行数:25,代码来源:user_service_test.go


示例16: TestGetUserProfileUserNotFound

func TestGetUserProfileUserNotFound(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	ln.SetOutput(ioutil.Discard, "test_logger")

	someOtherUserID := 24

	fakeClient := clientfakes.NewFakeClient()
	fakeClient.RegisterFunction("getUserProfile", func(params url.Values) (interface{}, error) {
		return nil, errors.New("some serious error happened")
	})

	adaptor := New(fakeClient)

	actual, err := adaptor.GetUserProfile(someOtherUserID)

	require.NotNil(t, err)
	require.Nil(t, actual)

}
开发者ID:john-cai,项目名称:tools,代码行数:20,代码来源:user_service_test.go


示例17: TestEditUserProfile

func TestEditUserProfile(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	expected := client.UserProfile{
		UserID:    23,
		Phone:     "123-123-1234",
		Website:   "www.google.com",
		FirstName: "Homer",
		LastName:  "Simpson",
		Address1:  "12345 Seasame St.",
		City:      "Springfield",
		State:     "IL",
		Zip:       "11252",
		Country:   "USA",
		Company:   "Simpsons",
	}
	toModify := client.UserProfile{}

	fakeClient := clientfakes.NewFakeClient()
	fakeClient.RegisterFunction("editUserProfile", func(params url.Values) (interface{}, error) {
		userID, _ := strconv.Atoi(params.Get("user_id"))
		toModify.UserID = userID
		toModify.Phone = params.Get("phone")
		toModify.Website = params.Get("website")
		toModify.FirstName = params.Get("first_name")
		toModify.LastName = params.Get("last_name")
		toModify.Address1 = params.Get("address")
		toModify.City = params.Get("city")
		toModify.State = params.Get("state")
		toModify.Zip = params.Get("zip")
		toModify.Country = params.Get("country")
		toModify.Company = params.Get("company")
		return 1, nil
	})

	adaptor := New(fakeClient)

	success, err := adaptor.EditUserProfile(&expected)

	require.Nil(t, err)
	assert.True(t, success)
	assert.Equal(t, expected.Phone, toModify.Phone)
	assert.Equal(t, expected.Website, toModify.Website)
	assert.Equal(t, expected.FirstName, toModify.FirstName)
	assert.Equal(t, expected.LastName, toModify.LastName)
	assert.Equal(t, expected.Address1, toModify.Address1)
	assert.Equal(t, expected.City, toModify.City)
	assert.Equal(t, expected.State, toModify.State)
	assert.Equal(t, expected.Zip, toModify.Zip)
	assert.Equal(t, expected.Country, toModify.Country)
	assert.Equal(t, expected.Company, toModify.Company)
}
开发者ID:john-cai,项目名称:tools,代码行数:52,代码来源:user_service_test.go


示例18: TestAddTalonFingerprintSuccessError

func TestAddTalonFingerprintSuccessError(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	fakeClient := clientfakes.NewFakeClient()
	fakeClient.RegisterFunction("add", func(params url.Values) (interface{}, error) {
		return "", errors.New("some error")
	})
	adaptor := New(fakeClient)
	ok, adaptorErr := adaptor.AddUserFingerprint(TalonFingerprint{})

	assert.NotNil(t, adaptorErr, "error should have occured")
	assert.False(t, ok, "fingerprint errored")
}
开发者ID:john-cai,项目名称:tools,代码行数:13,代码来源:provision_test.go


示例19: TestAddTalonFingerprintSuccessOnDuplicate

func TestAddTalonFingerprintSuccessOnDuplicate(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	fakeClient := clientfakes.NewFakeClient()
	fakeClient.RegisterFunction("add", func(params url.Values) (interface{}, error) {
		return "", errors.New("key exists")
	})
	adaptor := New(fakeClient)
	ok, adaptorErr := adaptor.AddUserFingerprint(TalonFingerprint{})

	require.Nil(t, adaptorErr, "no error should have occured")
	assert.True(t, ok, "fingerprint added")
}
开发者ID:john-cai,项目名称:tools,代码行数:13,代码来源:provision_test.go


示例20: TestDeactivateUserPackageError

func TestDeactivateUserPackageError(t *testing.T) {
	ln.SetOutput(ioutil.Discard, "test_logger")

	fakeClient := clientfakes.NewFakeClient()

	fakeClient.RegisterFunction("update", func(params url.Values) (interface{}, error) {
		return "", errors.New("some apid error for downgrade user package")
	})

	adaptor := New(fakeClient)
	adaptorErr := adaptor.DeactivateUserPackage(1800)

	require.NotNil(t, adaptorErr, "should error")
}
开发者ID:john-cai,项目名称:tools,代码行数:14,代码来源:user_package_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang go-kinesis.Kinesis类代码示例发布时间:2022-05-28
下一篇:
Golang ln.Err函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap