Commit 1359f7f3 authored by Corey Hulen's avatar Corey Hulen Committed by George Goldberg

Adding go vet from hack-a-thon (#5328)

* Adding go vet to the api package

* Adding go vet to app package

* Adding go vet to manualtesting package

* Adding go vet to the model package

* Adding go vet to the store dir

* Adding go vet to utils package

* Adding missing dirs with go files

* Fixing up makefile

* Fixing up makefile

* Removing root dir
parent 432dc923
.PHONY: build package run stop run-client run-server stop-client stop-server restart restart-server restart-client start-docker clean-dist clean nuke check-style check-client-style check-server-style check-unit-tests test dist setup-mac prepare-enteprise run-client-tests setup-run-client-tests cleanup-run-client-tests test-client build-linux build-osx build-windows internal-test-client
.PHONY: build package run stop run-client run-server stop-client stop-server restart restart-server restart-client start-docker clean-dist clean nuke check-style check-client-style check-server-style check-unit-tests test dist setup-mac prepare-enteprise run-client-tests setup-run-client-tests cleanup-run-client-tests test-client build-linux build-osx build-windows internal-test-client vet
# For golang 1.5.x compatibility (remove when we don't want to support it anymore)
export GO15VENDOREXPERIMENT=1
......@@ -183,7 +183,7 @@ check-client-style:
cd $(BUILD_WEBAPP_DIR) && $(MAKE) check-style
check-server-style:
check-server-style: govet
@echo Running GOFMT
$(eval GOFMT_OUTPUT := $(shell gofmt -d -s api/ model/ store/ utils/ manualtesting/ einterfaces/ cmd/platform/ 2>&1))
@echo "$(GOFMT_OUTPUT)"
......@@ -467,6 +467,36 @@ nuke: clean clean-docker
setup-mac:
echo $$(boot2docker ip 2> /dev/null) dockerhost | sudo tee -a /etc/hosts
govet:
@echo Running GOVET
$(GO) vet $(GOFLAGS) ./api || exit 1
$(GO) vet $(GOFLAGS) ./api4 || exit 1
$(GO) vet $(GOFLAGS) ./app || exit 1
$(GO) vet $(GOFLAGS) ./cmd/platform || exit 1
$(GO) vet $(GOFLAGS) ./einterfaces || exit 1
$(GO) vet $(GOFLAGS) ./manualtesting || exit 1
$(GO) vet $(GOFLAGS) ./model || exit 1
$(GO) vet $(GOFLAGS) ./model/gitlab || exit 1
$(GO) vet $(GOFLAGS) ./store || exit 1
$(GO) vet $(GOFLAGS) ./utils || exit 1
$(GO) vet $(GOFLAGS) ./web || exit 1
ifeq ($(BUILD_ENTERPRISE_READY),true)
$(GO) vet $(GOFLAGS) ./enterprise || exit 1
$(GO) vet $(GOFLAGS) ./enterprise/account_migration || exit 1
$(GO) vet $(GOFLAGS) ./enterprise/brand || exit 1
$(GO) vet $(GOFLAGS) ./enterprise/cluster || exit 1
$(GO) vet $(GOFLAGS) ./enterprise/compliance || exit 1
$(GO) vet $(GOFLAGS) ./enterprise/emoji || exit 1
$(GO) vet $(GOFLAGS) ./enterprise/ldap || exit 1
$(GO) vet $(GOFLAGS) ./enterprise/metrics || exit 1
$(GO) vet $(GOFLAGS) ./enterprise/mfa || exit 1
$(GO) vet $(GOFLAGS) ./enterprise/oauth/google || exit 1
$(GO) vet $(GOFLAGS) ./enterprise/oauth/office365 || exit 1
$(GO) vet $(GOFLAGS) ./enterprise/saml || exit 1
endif
todo:
@ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime --ignore-dir webapp/non_npm_dependencies/ TODO
@ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime --ignore-dir webapp/non_npm_dependencies/ XXX
......
......@@ -22,15 +22,15 @@ const (
)
var (
TEAM_NAME_LEN = utils.Range{10, 20}
TEAM_DOMAIN_NAME_LEN = utils.Range{10, 20}
TEAM_EMAIL_LEN = utils.Range{15, 30}
USER_NAME_LEN = utils.Range{5, 20}
USER_EMAIL_LEN = utils.Range{15, 30}
CHANNEL_DISPLAY_NAME_LEN = utils.Range{10, 20}
CHANNEL_NAME_LEN = utils.Range{5, 20}
POST_MESSAGE_LEN = utils.Range{100, 400}
POST_HASHTAGS_NUM = utils.Range{5, 10}
POST_MENTIONS_NUM = utils.Range{0, 3}
TEAM_NAME_LEN = utils.Range{Begin: 10, End: 20}
TEAM_DOMAIN_NAME_LEN = utils.Range{Begin: 10, End: 20}
TEAM_EMAIL_LEN = utils.Range{Begin: 15, End: 30}
USER_NAME_LEN = utils.Range{Begin: 5, End: 20}
USER_EMAIL_LEN = utils.Range{Begin: 15, End: 30}
CHANNEL_DISPLAY_NAME_LEN = utils.Range{Begin: 10, End: 20}
CHANNEL_NAME_LEN = utils.Range{Begin: 5, End: 20}
POST_MESSAGE_LEN = utils.Range{Begin: 100, End: 400}
POST_HASHTAGS_NUM = utils.Range{Begin: 5, End: 10}
POST_MENTIONS_NUM = utils.Range{Begin: 0, End: 3}
TEST_IMAGE_FILENAMES = []string{"test.png", "testjpg.jpg", "testgif.gif"}
)
......@@ -84,7 +84,7 @@ func CreateTestEnvironmentInTeam(client *model.Client, team *model.Team, rangeCh
numPosts := utils.RandIntFromRange(rangePosts)
numImages := utils.RandIntFromRange(rangePosts) / 4
for j := 0; j < numPosts; j++ {
user := users[utils.RandIntFromRange(utils.Range{0, len(users) - 1})]
user := users[utils.RandIntFromRange(utils.Range{Begin: 0, End: len(users) - 1})]
client.LoginById(user.Id, USER_PASSWORD)
for i, channel := range channels {
postCreator := NewAutoPostCreator(client, channel.Id)
......
......@@ -29,17 +29,17 @@ func NewAutoPostCreator(client *model.Client, channelid string) *AutoPostCreator
client: client,
channelid: channelid,
Fuzzy: false,
TextLength: utils.Range{100, 200},
TextLength: utils.Range{Begin: 100, End: 200},
HasImage: false,
ImageFilenames: TEST_IMAGE_FILENAMES,
Users: []string{},
Mentions: utils.Range{0, 5},
Tags: utils.Range{0, 7},
Mentions: utils.Range{Begin: 0, End: 5},
Tags: utils.Range{Begin: 0, End: 7},
}
}
func (cfg *AutoPostCreator) UploadTestFile() ([]string, bool) {
filename := cfg.ImageFilenames[utils.RandIntFromRange(utils.Range{0, len(cfg.ImageFilenames) - 1})]
filename := cfg.ImageFilenames[utils.RandIntFromRange(utils.Range{Begin: 0, End: len(cfg.ImageFilenames) - 1})]
path := utils.FindDir("web/static/images")
file, err := os.Open(path + "/" + filename)
......
......@@ -81,7 +81,7 @@ func (cfg *AutoUserCreator) createRandomUser() (*model.User, bool) {
ruser := result.Data.(*model.User)
status := &model.Status{ruser.Id, model.STATUS_ONLINE, false, model.GetMillis(), ""}
status := &model.Status{UserId: ruser.Id, Status: model.STATUS_ONLINE, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: ""}
if result := <-app.Srv.Store.Status().SaveOrUpdate(status); result.Err != nil {
result.Err.Translate(utils.T)
l4g.Error(result.Err.Error())
......
......@@ -169,10 +169,10 @@ func (me *LoadTestProvider) SetupCommand(c *Context, channelId string, message s
client.Login(BTEST_USER_EMAIL, BTEST_USER_PASSWORD)
environment, err := CreateTestEnvironmentWithTeams(
client,
utils.Range{numTeams, numTeams},
utils.Range{numChannels, numChannels},
utils.Range{numUsers, numUsers},
utils.Range{numPosts, numPosts},
utils.Range{Begin: numTeams, End: numTeams},
utils.Range{Begin: numChannels, End: numChannels},
utils.Range{Begin: numUsers, End: numUsers},
utils.Range{Begin: numPosts, End: numPosts},
doFuzz)
if err != true {
return &model.CommandResponse{Text: "Failed to create testing environment", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
......@@ -197,9 +197,9 @@ func (me *LoadTestProvider) SetupCommand(c *Context, channelId string, message s
CreateTestEnvironmentInTeam(
client,
team,
utils.Range{numChannels, numChannels},
utils.Range{numUsers, numUsers},
utils.Range{numPosts, numPosts},
utils.Range{Begin: numChannels, End: numChannels},
utils.Range{Begin: numUsers, End: numUsers},
utils.Range{Begin: numPosts, End: numPosts},
doFuzz)
}
......@@ -217,7 +217,7 @@ func (me *LoadTestProvider) UsersCommand(c *Context, channelId string, message s
usersr, err := parseRange(cmd, "")
if err == false {
usersr = utils.Range{2, 5}
usersr = utils.Range{Begin: 2, End: 5}
}
var team *model.Team
......@@ -247,7 +247,7 @@ func (me *LoadTestProvider) ChannelsCommand(c *Context, channelId string, messag
channelsr, err := parseRange(cmd, "")
if err == false {
channelsr = utils.Range{2, 5}
channelsr = utils.Range{Begin: 2, End: 5}
}
var team *model.Team
......@@ -278,14 +278,14 @@ func (me *LoadTestProvider) PostsCommand(c *Context, channelId string, message s
postsr, err := parseRange(cmd, "")
if err == false {
postsr = utils.Range{20, 30}
postsr = utils.Range{Begin: 20, End: 30}
}
tokens := strings.Fields(cmd)
rimages := utils.Range{0, 0}
rimages := utils.Range{Begin: 0, End: 0}
if len(tokens) >= 3 {
if numImages, err := strconv.Atoi(tokens[2]); err == nil {
rimages = utils.Range{numImages, numImages}
rimages = utils.Range{Begin: numImages, End: numImages}
}
}
......@@ -415,18 +415,18 @@ func parseRange(command string, cmd string) (utils.Range, bool) {
begin, err1 = strconv.Atoi(tokens[0])
end = begin
if err1 != nil {
return utils.Range{0, 0}, false
return utils.Range{Begin: 0, End: 0}, false
}
case len(tokens) >= 2:
begin, err1 = strconv.Atoi(tokens[0])
end, err2 = strconv.Atoi(tokens[1])
if err1 != nil || err2 != nil {
return utils.Range{0, 0}, false
return utils.Range{Begin: 0, End: 0}, false
}
default:
return utils.Range{0, 0}, false
return utils.Range{Begin: 0, End: 0}, false
}
return utils.Range{begin, end}, true
return utils.Range{Begin: begin, End: end}, true
}
func contains(items []string, token string) bool {
......
......@@ -31,16 +31,16 @@ func GetAnalytics(name string, teamId string) (model.AnalyticsRows, *model.AppEr
if name == "standard" {
var rows model.AnalyticsRows = make([]*model.AnalyticsRow, 10)
rows[0] = &model.AnalyticsRow{"channel_open_count", 0}
rows[1] = &model.AnalyticsRow{"channel_private_count", 0}
rows[2] = &model.AnalyticsRow{"post_count", 0}
rows[3] = &model.AnalyticsRow{"unique_user_count", 0}
rows[4] = &model.AnalyticsRow{"team_count", 0}
rows[5] = &model.AnalyticsRow{"total_websocket_connections", 0}
rows[6] = &model.AnalyticsRow{"total_master_db_connections", 0}
rows[7] = &model.AnalyticsRow{"total_read_db_connections", 0}
rows[8] = &model.AnalyticsRow{"daily_active_users", 0}
rows[9] = &model.AnalyticsRow{"monthly_active_users", 0}
rows[0] = &model.AnalyticsRow{Name: "channel_open_count", Value: 0}
rows[1] = &model.AnalyticsRow{Name: "channel_private_count", Value: 0}
rows[2] = &model.AnalyticsRow{Name: "post_count", Value: 0}
rows[3] = &model.AnalyticsRow{Name: "unique_user_count", Value: 0}
rows[4] = &model.AnalyticsRow{Name: "team_count", Value: 0}
rows[5] = &model.AnalyticsRow{Name: "total_websocket_connections", Value: 0}
rows[6] = &model.AnalyticsRow{Name: "total_master_db_connections", Value: 0}
rows[7] = &model.AnalyticsRow{Name: "total_read_db_connections", Value: 0}
rows[8] = &model.AnalyticsRow{Name: "daily_active_users", Value: 0}
rows[9] = &model.AnalyticsRow{Name: "monthly_active_users", Value: 0}
openChan := Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
privateChan := Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
......@@ -139,7 +139,7 @@ func GetAnalytics(name string, teamId string) (model.AnalyticsRows, *model.AppEr
return rows, nil
} else if name == "post_counts_day" {
if skipIntensiveQueries {
rows := model.AnalyticsRows{&model.AnalyticsRow{"", -1}}
rows := model.AnalyticsRows{&model.AnalyticsRow{Name: "", Value: -1}}
return rows, nil
}
......@@ -150,7 +150,7 @@ func GetAnalytics(name string, teamId string) (model.AnalyticsRows, *model.AppEr
}
} else if name == "user_counts_with_posts_day" {
if skipIntensiveQueries {
rows := model.AnalyticsRows{&model.AnalyticsRow{"", -1}}
rows := model.AnalyticsRows{&model.AnalyticsRow{Name: "", Value: -1}}
return rows, nil
}
......@@ -161,12 +161,12 @@ func GetAnalytics(name string, teamId string) (model.AnalyticsRows, *model.AppEr
}
} else if name == "extra_counts" {
var rows model.AnalyticsRows = make([]*model.AnalyticsRow, 6)
rows[0] = &model.AnalyticsRow{"file_post_count", 0}
rows[1] = &model.AnalyticsRow{"hashtag_post_count", 0}
rows[2] = &model.AnalyticsRow{"incoming_webhook_count", 0}
rows[3] = &model.AnalyticsRow{"outgoing_webhook_count", 0}
rows[4] = &model.AnalyticsRow{"command_count", 0}
rows[5] = &model.AnalyticsRow{"session_count", 0}
rows[0] = &model.AnalyticsRow{Name: "file_post_count", Value: 0}
rows[1] = &model.AnalyticsRow{Name: "hashtag_post_count", Value: 0}
rows[2] = &model.AnalyticsRow{Name: "incoming_webhook_count", Value: 0}
rows[3] = &model.AnalyticsRow{Name: "outgoing_webhook_count", Value: 0}
rows[4] = &model.AnalyticsRow{Name: "command_count", Value: 0}
rows[5] = &model.AnalyticsRow{Name: "session_count", Value: 0}
iHookChan := Srv.Store.Webhook().AnalyticsIncomingCount(teamId)
oHookChan := Srv.Store.Webhook().AnalyticsOutgoingCount(teamId)
......
......@@ -805,7 +805,7 @@ func GetNumberOfChannelsOnTeam(teamId string) (int, *model.AppError) {
func SetActiveChannel(userId string, channelId string) *model.AppError {
status, err := GetStatus(userId)
if err != nil {
status = &model.Status{userId, model.STATUS_ONLINE, false, model.GetMillis(), channelId}
status = &model.Status{UserId: userId, Status: model.STATUS_ONLINE, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: channelId}
} else {
status.ActiveChannel = channelId
if !status.Manual {
......
......@@ -513,7 +513,7 @@ func TestImportImportTeam(t *testing.T) {
// Check that one more team is in the DB.
if r := <-Srv.Store.Team().AnalyticsTeamCount(); r.Err == nil {
if r.Data.(int64)-1 != teamsCount {
t.Fatalf("Team did not get saved in apply run mode.", r.Data.(int64), teamsCount)
t.Fatalf("Team did not get saved in apply run mode. analytics=%v teamcount=%v", r.Data.(int64), teamsCount)
}
} else {
t.Fatalf("Failed to get team count.")
......@@ -542,7 +542,7 @@ func TestImportImportTeam(t *testing.T) {
if r := <-Srv.Store.Team().AnalyticsTeamCount(); r.Err == nil {
if r.Data.(int64)-1 != teamsCount {
t.Fatalf("Team alterations did not get saved in apply run mode.", r.Data.(int64), teamsCount)
t.Fatalf("Team alterations did not get saved in apply run mode. analytics=%v teamcount=%v", r.Data.(int64), teamsCount)
}
} else {
t.Fatalf("Failed to get team count.")
......
......@@ -241,7 +241,7 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe
var status *model.Status
var err *model.AppError
if status, err = GetStatus(id); err != nil {
status = &model.Status{id, model.STATUS_OFFLINE, false, 0, ""}
status = &model.Status{UserId: id, Status: model.STATUS_OFFLINE, Manual: false, LastActivityAt: 0, ActiveChannel: ""}
}
if DoesStatusAllowPushNotification(profileMap[id], status, post.ChannelId) {
......@@ -254,7 +254,7 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe
var status *model.Status
var err *model.AppError
if status, err = GetStatus(id); err != nil {
status = &model.Status{id, model.STATUS_OFFLINE, false, 0, ""}
status = &model.Status{UserId: id, Status: model.STATUS_OFFLINE, Manual: false, LastActivityAt: 0, ActiveChannel: ""}
}
if DoesStatusAllowPushNotification(profileMap[id], status, post.ChannelId) {
......
......@@ -100,7 +100,7 @@ func SetStatusOnline(userId string, sessionId string, manual bool) {
var err *model.AppError
if status, err = GetStatus(userId); err != nil {
status = &model.Status{userId, model.STATUS_ONLINE, false, model.GetMillis(), ""}
status = &model.Status{UserId: userId, Status: model.STATUS_ONLINE, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: ""}
broadcast = true
} else {
if status.Manual && !manual {
......@@ -157,7 +157,7 @@ func SetStatusOffline(userId string, manual bool) {
return // manually set status always overrides non-manual one
}
status = &model.Status{userId, model.STATUS_OFFLINE, manual, model.GetMillis(), ""}
status = &model.Status{UserId: userId, Status: model.STATUS_OFFLINE, Manual: manual, LastActivityAt: model.GetMillis(), ActiveChannel: ""}
AddStatusCache(status)
......@@ -175,7 +175,7 @@ func SetStatusAwayIfNeeded(userId string, manual bool) {
status, err := GetStatus(userId)
if err != nil {
status = &model.Status{userId, model.STATUS_OFFLINE, manual, 0, ""}
status = &model.Status{UserId: userId, Status: model.STATUS_OFFLINE, Manual: manual, LastActivityAt: 0, ActiveChannel: ""}
}
if !manual && status.Manual {
......
......@@ -307,11 +307,9 @@ func IsUsernameTaken(name string) bool {
if result := <-Srv.Store.User().GetByUsername(name); result.Err != nil {
return false
} else {
return true
}
return false
return true
}
func GetUser(userId string) (*model.User, *model.AppError) {
......
......@@ -67,7 +67,7 @@ func manualTest(c *api.Context, w http.ResponseWriter, r *http.Request) {
// Create team for testing
team := &model.Team{
DisplayName: teamDisplayName[0],
Name: utils.RandomName(utils.Range{20, 20}, utils.LOWERCASE),
Name: utils.RandomName(utils.Range{Begin: 20, End: 20}, utils.LOWERCASE),
Email: "success+" + model.NewId() + "simulator.amazonses.com",
Type: model.TEAM_OPEN,
}
......
......@@ -14,8 +14,8 @@ type ScheduledTask struct {
Name string `json:"name"`
Interval time.Duration `json:"interval"`
Recurring bool `json:"recurring"`
function TaskFunc `json:",omitempty"`
timer *time.Timer `json:",omitempty"`
function TaskFunc
timer *time.Timer
}
var tasks = make(map[string]*ScheduledTask)
......
......@@ -46,25 +46,25 @@ func TestUserUpdateMentionKeysFromUsername(t *testing.T) {
user.SetDefaultNotifications()
if user.NotifyProps["mention_keys"] != "user,@user" {
t.Fatal("default mention keys are invalid: %v", user.NotifyProps["mention_keys"])
t.Fatalf("default mention keys are invalid: %v", user.NotifyProps["mention_keys"])
}
user.Username = "person"
user.UpdateMentionKeysFromUsername("user")
if user.NotifyProps["mention_keys"] != "person,@person" {
t.Fatal("mention keys are invalid after changing username: %v", user.NotifyProps["mention_keys"])
t.Fatalf("mention keys are invalid after changing username: %v", user.NotifyProps["mention_keys"])
}
user.NotifyProps["mention_keys"] += ",mention"
user.UpdateMentionKeysFromUsername("person")
if user.NotifyProps["mention_keys"] != "person,@person,mention" {
t.Fatal("mention keys are invalid after adding extra mention keyword: %v", user.NotifyProps["mention_keys"])
t.Fatalf("mention keys are invalid after adding extra mention keyword: %v", user.NotifyProps["mention_keys"])
}
user.Username = "user"
user.UpdateMentionKeysFromUsername("person")
if user.NotifyProps["mention_keys"] != "user,@user,mention" {
t.Fatal("mention keys are invalid after changing username with extra mention keyword: %v", user.NotifyProps["mention_keys"])
t.Fatalf("mention keys are invalid after changing username with extra mention keyword: %v", user.NotifyProps["mention_keys"])
}
}
......
......@@ -34,14 +34,14 @@ type StringArray []string
type EncryptStringMap map[string]string
type AppError struct {
Id string `json:"id"`
Message string `json:"message"` // Message to be display to the end user without debugging information
DetailedError string `json:"detailed_error"` // Internal error string to help the developer
RequestId string `json:"request_id,omitempty"` // The RequestId that's also set in the header
StatusCode int `json:"status_code,omitempty"` // The http status code
Where string `json:"-"` // The function where it happened in the form of Struct.Func
IsOAuth bool `json:"is_oauth,omitempty"` // Whether the error is OAuth specific
params map[string]interface{} `json:"-"`
Id string `json:"id"`
Message string `json:"message"` // Message to be display to the end user without debugging information
DetailedError string `json:"detailed_error"` // Internal error string to help the developer
RequestId string `json:"request_id,omitempty"` // The RequestId that's also set in the header
StatusCode int `json:"status_code,omitempty"` // The http status code
Where string `json:"-"` // The function where it happened in the form of Struct.Func
IsOAuth bool `json:"is_oauth,omitempty"` // Whether the error is OAuth specific
params map[string]interface{}
}
func (er *AppError) Error() string {
......
......@@ -34,7 +34,7 @@ func TestAppError(t *testing.T) {
t.Fatal()
}
err.Error()
t.Log(err.Error())
}
func TestAppErrorJunk(t *testing.T) {
......
......@@ -1062,9 +1062,9 @@ func TestGetMemberCount(t *testing.T) {
Must(store.Channel().SaveMember(&m1))
if result := <-store.Channel().GetMemberCount(c1.Id, false); result.Err != nil {
t.Fatal("failed to get member count: %v", result.Err)
t.Fatalf("failed to get member count: %v", result.Err)
} else if result.Data.(int64) != 1 {
t.Fatal("got incorrect member count %v", result.Data)
t.Fatalf("got incorrect member count %v", result.Data)
}
u2 := model.User{
......@@ -1082,9 +1082,9 @@ func TestGetMemberCount(t *testing.T) {
Must(store.Channel().SaveMember(&m2))
if result := <-store.Channel().GetMemberCount(c1.Id, false); result.Err != nil {
t.Fatal("failed to get member count: %v", result.Err)
t.Fatalf("failed to get member count: %v", result.Err)
} else if result.Data.(int64) != 2 {
t.Fatal("got incorrect member count %v", result.Data)
t.Fatalf("got incorrect member count %v", result.Data)
}
// make sure members of other channels aren't counted
......@@ -1103,9 +1103,9 @@ func TestGetMemberCount(t *testing.T) {
Must(store.Channel().SaveMember(&m3))
if result := <-store.Channel().GetMemberCount(c1.Id, false); result.Err != nil {
t.Fatal("failed to get member count: %v", result.Err)
t.Fatalf("failed to get member count: %v", result.Err)
} else if result.Data.(int64) != 2 {
t.Fatal("got incorrect member count %v", result.Data)
t.Fatalf("got incorrect member count %v", result.Data)
}
// make sure inactive users aren't counted
......@@ -1124,9 +1124,9 @@ func TestGetMemberCount(t *testing.T) {
Must(store.Channel().SaveMember(&m4))
if result := <-store.Channel().GetMemberCount(c1.Id, false); result.Err != nil {
t.Fatal("failed to get member count: %v", result.Err)
t.Fatalf("failed to get member count: %v", result.Err)
} else if result.Data.(int64) != 2 {
t.Fatal("got incorrect member count %v", result.Data)
t.Fatalf("got incorrect member count %v", result.Data)
}
}
......@@ -1169,14 +1169,14 @@ func TestUpdateExtrasByUser(t *testing.T) {
Must(store.User().Update(u1, true))
if result := <-store.Channel().ExtraUpdateByUser(u1.Id, u1.DeleteAt); result.Err != nil {
t.Fatal("failed to update extras by user: %v", result.Err)
t.Fatalf("failed to update extras by user: %v", result.Err)
}
u1.DeleteAt = 0
Must(store.User().Update(u1, true))
if result := <-store.Channel().ExtraUpdateByUser(u1.Id, u1.DeleteAt); result.Err != nil {
t.Fatal("failed to update extras by user: %v", result.Err)
t.Fatalf("failed to update extras by user: %v", result.Err)
}
}
......
......@@ -12,7 +12,7 @@ import (
func TestSqlStatusStore(t *testing.T) {
Setup()
status := &model.Status{model.NewId(), model.STATUS_ONLINE, false, 0, ""}
status := &model.Status{UserId: model.NewId(), Status: model.STATUS_ONLINE, Manual: false, LastActivityAt: 0, ActiveChannel: ""}
if err := (<-store.Status().SaveOrUpdate(status)).Err; err != nil {
t.Fatal(err)
......@@ -28,12 +28,12 @@ func TestSqlStatusStore(t *testing.T) {
t.Fatal(err)
}
status2 := &model.Status{model.NewId(), model.STATUS_AWAY, false, 0, ""}
status2 := &model.Status{UserId: model.NewId(), Status: model.STATUS_AWAY, Manual: false, LastActivityAt: 0, ActiveChannel: ""}
if err := (<-store.Status().SaveOrUpdate(status2)).Err; err != nil {
t.Fatal(err)
}
status3 := &model.Status{model.NewId(), model.STATUS_OFFLINE, false, 0, ""}
status3 := &model.Status{UserId: model.NewId(), Status: model.STATUS_OFFLINE, Manual: false, LastActivityAt: 0, ActiveChannel: ""}
if err := (<-store.Status().SaveOrUpdate(status3)).Err; err != nil {
t.Fatal(err)
}
......@@ -90,7 +90,7 @@ func TestSqlStatusStore(t *testing.T) {
func TestActiveUserCount(t *testing.T) {
Setup()
status := &model.Status{model.NewId(), model.STATUS_ONLINE, false, model.GetMillis(), ""}
status := &model.Status{UserId: model.NewId(), Status: model.STATUS_ONLINE, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: ""}
Must(store.Status().SaveOrUpdate(status))
if result := <-store.Status().GetTotalActiveUsersCount(); result.Err != nil {
......
......@@ -220,16 +220,14 @@ func (ss *SqlStore) TotalReadDbConnections() int {
if len(utils.Cfg.SqlSettings.DataSourceReplicas) == 0 {
return 0
} else {
count := 0
for _, db := range ss.replicas {
count = count + db.Db.Stats().OpenConnections
}
}
return count
count := 0
for _, db := range ss.replicas {
count = count + db.Db.Stats().OpenConnections
}
return 0
return count
}
func (ss *SqlStore) GetCurrentSchemaVersion() string {
......@@ -722,7 +720,7 @@ func (me mattermConverter) FromDb(target interface{}) (gorp.CustomScanner, bool)
b := []byte(*s)
return json.Unmarshal(b, target)
}
return gorp.CustomScanner{new(string), target, binder}, true
return gorp.CustomScanner{Holder: new(string), Target: target, Binder: binder}, true
case *model.StringArray:
binder := func(holder, target interface{}) error {
s, ok := holder.(*string)
......@@ -732,7 +730,7 @@ func (me mattermConverter) FromDb(target interface{}) (gorp.CustomScanner, bool)
b := []byte(*s)
return json.Unmarshal(b, target)
}
return gorp.CustomScanner{new(string), target, binder}, true
return gorp.CustomScanner{Holder: new(string), Target: target, Binder: binder}, true
case *model.EncryptStringMap:
binder := func(holder, target interface{}) error {
s, ok := holder.(*string)
......@@ -748,7 +746,7 @@ func (me mattermConverter) FromDb(target interface{}) (gorp.CustomScanner, bool)
b := []byte(ue)
return json.Unmarshal(b, target)
}
return gorp.CustomScanner{new(string), target, binder}, true
return gorp.CustomScanner{Holder: new(string), Target: target, Binder: binder}, true
case *model.StringInterface:
binder := func(holder, target interface{}) error {
s, ok := holder.(*string)
......@@ -758,7 +756,7 @@ func (me mattermConverter) FromDb(target interface{}) (gorp.CustomScanner, bool)
b := []byte(*s)
return json.Unmarshal(b, target)
}
return gorp.CustomScanner{new(string), target, binder}, true
return gorp.CustomScanner{Holder: new(string), Target: target, Binder: binder}, true
}
return gorp.CustomScanner{}, false
......
......@@ -1103,7 +1103,7 @@ func TestUserStoreGetRecentlyActiveUsersForTeam(t *testing.T) {
u1 := &model.User{}
u1.Email = model.NewId()
Must(store.User().Save(u1))
Must(store.Status().SaveOrUpdate(&model.Status{u1.Id, model.STATUS_ONLINE, false, model.GetMillis(), ""}))
Must(store.Status().SaveOrUpdate(&model.Status{UserId: u1.Id, Status: model.STATUS_ONLINE, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: ""}))
tid := model.NewId()
Must(store.Team().SaveMember(&model.TeamMember{TeamId: tid, UserId: u1.Id}))
......
......@@ -104,8 +104,8 @@ func SendMailUsingConfig(to, subject, body string, config *model.Config) *model.
l4g.Debug(T("utils.mail.send_mail.sending.debug"), to, subject)
fromMail := mail.Address{config.EmailSettings.FeedbackName, config.EmailSettings.FeedbackEmail}
toMail := mail.Address{"", to}
fromMail := mail.Address{Name: config.EmailSettings.FeedbackName, Address: config.EmailSettings.FeedbackEmail}
toMail := mail.Address{Name: "", Address: to}
headers := make(map[string]string)
headers["From"] = fromMail.String()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment