本文整理汇总了Golang中github.com/sendgrid/ln.SetOutput函数的典型用法代码示例。如果您正苦于以下问题:Golang SetOutput函数的具体用法?Golang SetOutput怎么用?Golang SetOutput使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetOutput函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例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)
}
}
}
示例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)
}
示例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)
}
示例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
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
}
示例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))
}
示例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])
}
示例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)
}
示例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")
}
示例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)
}
示例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)
}