-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(api, db): team validation (#1123)
- Loading branch information
1 parent
dbaeade
commit 520c968
Showing
17 changed files
with
987 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package dto | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/moira-alert/moira/api" | ||
"github.com/moira-alert/moira/api/middleware" | ||
|
||
. "github.com/smartystreets/goconvey/convey" | ||
) | ||
|
||
func TestTeamValidation(t *testing.T) { | ||
Convey("Test team validation", t, func() { | ||
teamModel := TeamModel{} | ||
|
||
limits := api.GetTestLimitsConfig() | ||
|
||
request, _ := http.NewRequest("POST", "/api/teams", nil) | ||
request.Header.Set("Content-Type", "application/json") | ||
request = request.WithContext(middleware.SetContextValueForTest(request.Context(), "limits", limits)) | ||
|
||
Convey("with empty team.Name", func() { | ||
err := teamModel.Bind(request) | ||
|
||
So(err, ShouldResemble, errEmptyTeamName) | ||
}) | ||
|
||
Convey("with team.Name has characters more than in limit", func() { | ||
teamModel.Name = strings.Repeat("ё", limits.Team.MaxNameSize+1) | ||
|
||
err := teamModel.Bind(request) | ||
|
||
So(err, ShouldResemble, fmt.Errorf("team name cannot be longer than %d characters", limits.Team.MaxNameSize)) | ||
}) | ||
|
||
Convey("with team.Description has characters more than in limit", func() { | ||
teamModel.Name = strings.Repeat("ё", limits.Team.MaxNameSize) | ||
teamModel.Description = strings.Repeat("ё", limits.Team.MaxDescriptionSize+1) | ||
|
||
err := teamModel.Bind(request) | ||
|
||
So(err, ShouldResemble, fmt.Errorf("team description cannot be longer than %d characters", limits.Team.MaxDescriptionSize)) | ||
}) | ||
|
||
Convey("with valid team", func() { | ||
teamModel.Name = strings.Repeat("ё", limits.Team.MaxNameSize) | ||
teamModel.Description = strings.Repeat("ё", limits.Team.MaxDescriptionSize) | ||
|
||
err := teamModel.Bind(request) | ||
|
||
So(err, ShouldBeNil) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import "github.com/moira-alert/moira" | ||
|
||
func updateFrom213(logger moira.Logger, database moira.Database) error { | ||
logger.Info().Msg("Update 2.13 -> 2.14 started") | ||
|
||
err := fillTeamNamesHash(logger, database) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
logger.Info().Msg("Update 2.13 -> 2.14 was finished") | ||
return nil | ||
} | ||
|
||
func downgradeTo213(logger moira.Logger, database moira.Database) error { | ||
logger.Info().Msg("Downgrade 2.14 -> 2.13 started") | ||
|
||
err := removeTeamNamesHash(logger, database) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
logger.Info().Msg("Downgrade 2.14 -> 2.13 was finished") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.