Renamed validate function

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
This commit is contained in:
Alexey Terentyev 2018-06-20 12:50:36 +03:00
parent 3c4517f039
commit b166e695cc
No known key found for this signature in database
GPG Key ID: 60D6C550AEEBB467
4 changed files with 14 additions and 14 deletions

View File

@ -42,7 +42,7 @@ func reformatAndRemoveIncorrectTopics(x *xorm.Engine) (err error) {
break
}
for _, topic := range topics {
if models.TopicValidator(topic.Name) {
if models.ValidateTopic(topic.Name) {
continue
}
topic.Name = strings.Replace(strings.TrimSpace(strings.ToLower(topic.Name)), " ", "-", -1)
@ -55,7 +55,7 @@ func reformatAndRemoveIncorrectTopics(x *xorm.Engine) (err error) {
touchedRepo[id] = struct{}{}
}
if models.TopicValidator(topic.Name) {
if models.ValidateTopic(topic.Name) {
log.Info("Updating topic: id = %v, name = %v", topic.ID, topic.Name)
if _, err := sess.Table("topic").ID(topic.ID).
Update(&Topic{Name: topic.Name}); err != nil {

View File

@ -54,8 +54,8 @@ func (err ErrTopicNotExist) Error() string {
return fmt.Sprintf("topic is not exist [name: %s]", err.Name)
}
// TopicValidator checks topics by length and match pattern rules
func TopicValidator(topic string) bool {
// ValidateTopic checks topics by length and match pattern rules
func ValidateTopic(topic string) bool {
return len(topic) <= 35 && topicPattern.MatchString(topic)
}

View File

@ -57,14 +57,14 @@ func TestAddTopic(t *testing.T) {
}
func TestTopicValidator(t *testing.T) {
assert.True(t, TopicValidator("12345"))
assert.True(t, TopicValidator("2-test"))
assert.True(t, TopicValidator("test-3"))
assert.True(t, TopicValidator("first"))
assert.True(t, TopicValidator("second-test-topic"))
assert.True(t, TopicValidator("third-project-topic-with-max-length"))
assert.True(t, ValidateTopic("12345"))
assert.True(t, ValidateTopic("2-test"))
assert.True(t, ValidateTopic("test-3"))
assert.True(t, ValidateTopic("first"))
assert.True(t, ValidateTopic("second-test-topic"))
assert.True(t, ValidateTopic("third-project-topic-with-max-length"))
assert.False(t, TopicValidator("$fourth-test,topic"))
assert.False(t, TopicValidator("-fifth-test-topic"))
assert.False(t, TopicValidator("sixth-go-project-topic-with-excess-length"))
assert.False(t, ValidateTopic("$fourth-test,topic"))
assert.False(t, ValidateTopic("-fifth-test-topic"))
assert.False(t, ValidateTopic("sixth-go-project-topic-with-excess-length"))
}

View File

@ -36,7 +36,7 @@ func TopicsPost(ctx *context.Context) {
topics[i] = topic
i++
}
if !models.TopicValidator(topic) {
if !models.ValidateTopic(topic) {
invalidTopics = append(invalidTopics, topic)
}
}