chore(tests):
Some checks failed
Gitea Build Check / Build (push) Failing after 26s

refactored & fixed old test cases
This commit is contained in:
SoXX 2024-08-13 11:07:14 +02:00
parent cfc7e5362d
commit 75bbbb4408
8 changed files with 51 additions and 342 deletions

View File

@ -2,79 +2,26 @@ package error
import "testing" import "testing"
func TestEntityAlreadyExists_Error(t *testing.T) { func TestDatabase_Error(t *testing.T) {
type fields struct {
Reason string
}
tests := []struct { tests := []struct {
name string name string
fields fields
want string want string
}{ }{
{ {
name: "Test : Valid error String", name: "Test 1: Reason",
want: "EntityAlreadyExists error", fields: fields{Reason: "TEST ERROR"},
want: "Database error: TEST ERROR",
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
e := &EntityAlreadyExists{} e := Database{
if got := e.Error(); got != tt.want { Reason: tt.fields.Reason,
t.Errorf("Error() = %v, want %v", got, tt.want) }
}
})
}
}
func TestNoDataFound_Error(t *testing.T) {
tests := []struct {
name string
want string
}{
{
name: "Test : Valid error String",
want: "NoDataFound error",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e := &NoDataFound{}
if got := e.Error(); got != tt.want {
t.Errorf("Error() = %v, want %v", got, tt.want)
}
})
}
}
func TestNoDataWritten_Error(t *testing.T) {
tests := []struct {
name string
want string
}{
{
name: "Test : Valid error String",
want: "NoDataWritten error",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e := &NoDataWritten{}
if got := e.Error(); got != tt.want {
t.Errorf("Error() = %v, want %v", got, tt.want)
}
})
}
}
func TestNoRelationCreated_Error(t *testing.T) {
tests := []struct {
name string
want string
}{
{
name: "Test : Valid error String",
want: "relationship creation error",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e := &NoRelationCreated{}
if got := e.Error(); got != tt.want { if got := e.Error(); got != tt.want {
t.Errorf("Error() = %v, want %v", got, tt.want) t.Errorf("Error() = %v, want %v", got, tt.want)
} }

View File

@ -3,42 +3,9 @@ package models
import "testing" import "testing"
func TestPostReference_TableName(t *testing.T) { func TestPostReference_TableName(t *testing.T) {
type fields struct { postReference := PostReference{}
PostID string expectedTableName := "PostReference"
SourceID string if tableName := postReference.TableName(); tableName != expectedTableName {
URL string t.Fatalf("expected %s, but got %s", expectedTableName, tableName)
SourcePostID string
FullFileURL string
PreviewFileURL string
SampleFileURL string
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "Test 1: PostReference",
fields: fields{},
want: "PostReference",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
po := PostReference{
PostID: tt.fields.PostID,
SourceID: tt.fields.SourceID,
URL: tt.fields.URL,
PostReferenceConfig: PostReferenceConfig{
SourcePostID: tt.fields.SourcePostID,
FullFileURL: tt.fields.FullFileURL,
PreviewFileURL: tt.fields.PreviewFileURL,
SampleFileURL: tt.fields.SampleFileURL,
},
}
if got := po.TableName(); got != tt.want {
t.Errorf("TableName() = %v, want %v", got, tt.want)
}
})
} }
} }

View File

@ -3,36 +3,9 @@ package models
import "testing" import "testing"
func TestPost_TableName(t *testing.T) { func TestPost_TableName(t *testing.T) {
type fields struct { post := Post{}
BaseModel BaseModel[PostID] expectedTableName := "Post"
Rating Rating if tableName := post.TableName(); tableName != expectedTableName {
Tags []Tag t.Fatalf("expected %s, but got %s", expectedTableName, tableName)
Favorites []UserFavorite
References []PostReference
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "Test 1: Is name Post",
fields: fields{},
want: "Post",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
po := Post{
BaseModel: tt.fields.BaseModel,
Rating: tt.fields.Rating,
Tags: tt.fields.Tags,
Favorites: tt.fields.Favorites,
References: tt.fields.References,
}
if got := po.TableName(); got != tt.want {
t.Errorf("TableName() = %v, want %v", got, tt.want)
}
})
} }
} }

View File

@ -3,38 +3,9 @@ package models
import "testing" import "testing"
func TestSource_TableName(t *testing.T) { func TestSource_TableName(t *testing.T) {
type fields struct { source := Source{}
BaseModel BaseModel[SourceID] expectedTableName := "Source"
DisplayName string if tableName := source.TableName(); tableName != expectedTableName {
Domain string t.Fatalf("expected %s, but got %s", expectedTableName, tableName)
Icon string
UserSources []UserSource
References []PostReference
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "Test 1: Is name Source",
fields: fields{},
want: "Source",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
so := Source{
BaseModel: tt.fields.BaseModel,
DisplayName: tt.fields.DisplayName,
Domain: tt.fields.Domain,
Icon: tt.fields.Icon,
UserSources: tt.fields.UserSources,
References: tt.fields.References,
}
if got := so.TableName(); got != tt.want {
t.Errorf("TableName() = %v, want %v", got, tt.want)
}
})
} }
} }

View File

@ -3,94 +3,25 @@ package models
import "testing" import "testing"
func TestTagAlias_TableName(t *testing.T) { func TestTagAlias_TableName(t *testing.T) {
type fields struct { tagAlias := TagAlias{}
Name string expectedTableName := "TagAlias"
TagID string if tableName := tagAlias.TableName(); tableName != expectedTableName {
} t.Fatalf("expected %s, but got %s", expectedTableName, tableName)
tests := []struct {
name string
fields fields
want string
}{
{
name: "Test 1: Is Name TagAlias",
fields: fields{},
want: "TagAlias",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ta := TagAlias{
Name: tt.fields.Name,
TagID: tt.fields.TagID,
}
if got := ta.TableName(); got != tt.want {
t.Errorf("TableName() = %v, want %v", got, tt.want)
}
})
} }
} }
func TestTagGroup_TableName(t *testing.T) { func TestTagGroup_TableName(t *testing.T) {
type fields struct { tagGroup := TagGroup{}
Name string expectedTableName := "TagGroup"
TagID string if tableName := tagGroup.TableName(); tableName != expectedTableName {
} t.Fatalf("expected %s, but got %s", expectedTableName, tableName)
tests := []struct {
name string
fields fields
want string
}{
{
name: "Test 1: Is name TagGroup",
fields: fields{},
want: "TagGroup",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ta := TagGroup{
Name: tt.fields.Name,
TagID: tt.fields.TagID,
}
if got := ta.TableName(); got != tt.want {
t.Errorf("TableName() = %v, want %v", got, tt.want)
}
})
} }
} }
func TestTag_TableName(t *testing.T) { func TestTags_TableName(t *testing.T) {
type fields struct { tag := Tag{}
Name string expectedTableName := "Tag"
Type TagType if tableName := tag.TableName(); tableName != expectedTableName {
Aliases []TagAlias t.Fatalf("expected %s, but got %s", expectedTableName, tableName)
Groups []TagGroup
Posts []Post
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "Test 1: Is name Tag",
fields: fields{},
want: "Tag",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ta := Tag{
Name: tt.fields.Name,
Type: tt.fields.Type,
Aliases: tt.fields.Aliases,
Groups: tt.fields.Groups,
Posts: tt.fields.Posts,
}
if got := ta.TableName(); got != tt.want {
t.Errorf("TableName() = %v, want %v", got, tt.want)
}
})
} }
} }

View File

@ -1,37 +1,11 @@
package models package models
import ( import "testing"
"testing"
"time"
)
func TestUserFavorite_TableName(t *testing.T) { func TestUserFavorite_TableName(t *testing.T) {
type fields struct { userFavorite := UserFavorite{}
UserID string expectedTableName := "UserFavorites"
PostID string if tableName := userFavorite.TableName(); tableName != expectedTableName {
CreatedAt time.Time t.Fatalf("expected %s, but got %s", expectedTableName, tableName)
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "Test 1: Is name UserFavorite",
fields: fields{},
want: "UserFavorite",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
us := UserFavorite{
UserID: tt.fields.UserID,
PostID: tt.fields.PostID,
CreatedAt: tt.fields.CreatedAt,
}
if got := us.TableName(); got != tt.want {
t.Errorf("TableName() = %v, want %v", got, tt.want)
}
})
} }
} }

View File

@ -3,40 +3,9 @@ package models
import "testing" import "testing"
func TestUserSource_TableName(t *testing.T) { func TestUserSource_TableName(t *testing.T) {
type fields struct { userSource := UserSource{}
User User expectedTableName := "UserSource"
UserID UserID if tableName := userSource.TableName(); tableName != expectedTableName {
Source Source t.Fatalf("expected %s, but got %s", expectedTableName, tableName)
SourceID SourceID
ScrapeTimeInterval string
AccountUsername string
AccountID string
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "Test 1: Is name UserSource",
fields: fields{},
want: "UserSource",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
us := UserSource{
User: tt.fields.User,
UserID: tt.fields.UserID,
Source: tt.fields.Source,
SourceID: tt.fields.SourceID,
ScrapeTimeInterval: tt.fields.ScrapeTimeInterval,
AccountUsername: tt.fields.AccountUsername,
AccountID: tt.fields.AccountID,
}
if got := us.TableName(); got != tt.want {
t.Errorf("TableName() = %v, want %v", got, tt.want)
}
})
} }
} }

View File

@ -3,32 +3,9 @@ package models
import "testing" import "testing"
func TestUser_TableName(t *testing.T) { func TestUser_TableName(t *testing.T) {
type fields struct { user := User{}
BaseModel BaseModel[UserID] expectedTableName := "User"
Favorites []UserFavorite if tableName := user.TableName(); tableName != expectedTableName {
Sources []UserSource t.Fatalf("expected %s, but got %s", expectedTableName, tableName)
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "Test 1: Is name User",
fields: fields{},
want: "User",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
us := User{
BaseModel: tt.fields.BaseModel,
Favorites: tt.fields.Favorites,
Sources: tt.fields.Sources,
}
if got := us.TableName(); got != tt.want {
t.Errorf("TableName() = %v, want %v", got, tt.want)
}
})
} }
} }