From b166e695cc21cb66c6d17c7365e2398f0ab103d3 Mon Sep 17 00:00:00 2001 From: Alexey Terentyev Date: Wed, 20 Jun 2018 12:50:36 +0300 Subject: [PATCH] Renamed validate function Signed-off-by: Alexey Terentyev --- models/migrations/v68.go | 4 ++-- models/topic.go | 4 ++-- models/topic_test.go | 18 +++++++++--------- routers/repo/topic.go | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/models/migrations/v68.go b/models/migrations/v68.go index 4fb758a85..d6a0d04c5 100644 --- a/models/migrations/v68.go +++ b/models/migrations/v68.go @@ -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 { diff --git a/models/topic.go b/models/topic.go index a2d87099f..247aac5ff 100644 --- a/models/topic.go +++ b/models/topic.go @@ -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) } diff --git a/models/topic_test.go b/models/topic_test.go index 8ed415899..ef374e557 100644 --- a/models/topic_test.go +++ b/models/topic_test.go @@ -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")) } diff --git a/routers/repo/topic.go b/routers/repo/topic.go index 20e15735f..63fcf793f 100644 --- a/routers/repo/topic.go +++ b/routers/repo/topic.go @@ -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) } }