Complete file tree and packages managment rework

This commit is contained in:
Florian Sylvain
2022-12-27 21:00:19 +01:00
parent 39afc0c066
commit 451fd8452b
11 changed files with 153 additions and 161 deletions
+42
View File
@@ -0,0 +1,42 @@
package articles
import (
"log"
"testing"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson"
)
var Article1, _ = bson.Marshal(Article{
IdName: "test_article_1",
Date: 1671482492,
Content: gin.H{},
})
var Article2, _ = bson.Marshal(Article{
IdName: "test_article_2",
Date: 1671899112,
Content: gin.H{},
})
var BSONConvertedArticles = [][]byte{Article1, Article2}
func TestGetAllArticlesBusiness(t *testing.T) {
documents := GetAllArticlesBusiness(BSONConvertedArticles)
article := documents[0]
if article.IdName != "test_article_1" {
log.Fatalf(`Excepted "test_article_1" as IdName, found "%v"`, article.IdName)
} else if article.Date != 1671482492 {
log.Fatalf(`Excepted 1671482492 as Date, found "%v"`, article.Date)
}
}
func TestIsArticleIdAlreadyUsed(t *testing.T) {
if IsArticleIdAlreadyUsed("test_article_1", BSONConvertedArticles) == false {
log.Fatalf(`Excepted true, found false`)
} else if IsArticleIdAlreadyUsed("test_article_3", BSONConvertedArticles) == true {
log.Fatalf(`Excepted false, found true`)
}
}