Merge branch 'main' into cobra_commands

This commit is contained in:
Slug-Boi
2024-10-24 21:02:17 +02:00
19 changed files with 287 additions and 279 deletions
+1 -1
View File
@@ -1 +1 @@
Syntax: name_short|Name|Username|email !!Remember to set the env var authors_file!!
Syntax: name_short|Name|Username|email (opt: |ex) (opt: ;;group1|group2|group3...) !!Remember to set the env var authors_file!!
+4
View File
@@ -0,0 +1,4 @@
Syntax for authorfile
test|test|test|test|ex;;test
tet|tessadsat|teta|asdadad|ex;;adsadas
teadsajdma|asdasdasda|adsdadasd|addsadasd;;adsadsadadas
+55
View File
@@ -0,0 +1,55 @@
package tui
import (
"bytes"
"os"
"testing"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/x/exp/teatest"
)
const author_data = `syntax for the test file
te|testing|TestUser|test@test.test|ex
ti|testtest|UserName2|testing@user.io;;gr1`
var envVar string
func setup() {
// setup test data
err := os.WriteFile("author_file_test", []byte(author_data), 0644)
if err != nil {
panic(err)
}
os.Setenv("author_file", "author_file_test")
envVar = os.Getenv("author_file")
}
func teardown() {
// remove test data
os.Remove("author_file_test")
os.Setenv("author_file", envVar)
}
func TestShowUser(t *testing.T) {
setup()
defer teardown()
m := intialModel_US(envVar)
tm := teatest.NewTestModel(
t, m,
teatest.WithInitialTermSize(300, 300),
)
teatest.WaitFor(t, tm.Output(), func(bts []byte) bool {
return bytes.Contains(bts, []byte("syntax for the test file"))
}, teatest.WithCheckInterval(time.Millisecond*100), teatest.WithDuration(time.Second*2))
tm.Send(tea.KeyMsg{
Type: tea.KeyRunes,
Runes: []rune("q"),
})
tm.WaitFinished(t, teatest.WithFinalTimeout(time.Second))
}
+40 -2
View File
@@ -65,7 +65,7 @@ func Test_add_all(t *testing.T) {
if !strings.Contains(commit, "\nCo-authored-by: test1 <test1>") ||
!strings.Contains(commit, "\nCo-authored-by: test2 <test2>") ||
!strings.Contains(commit, "\nCo-authored-by: test3 <test3>") {
t.Fatalf("String built incorrectly. Strings did not match: Created -> %s Expected -> Co-authored-by: test <test>",commit)
t.Fatalf("String built incorrectly. Strings did not match: Created -> %s Expected -> Co-authored-by: test1 <test1>\nCo-authored-by: test2 <test2>\n\nCo-authored-by: test3 <test3>",commit)
}
}
@@ -79,10 +79,48 @@ func Test_exclude_user(t *testing.T) {
commit := sb_build()
if strings.Contains(commit, "\nCo-authored-by: test1 <test1>") {
t.Fatalf("String built incorrectly. Strings did not match: Created -> %s Expected -> Co-authored-by: test <test>",commit)
t.Fatalf("String built incorrectly. Strings did not match: Created -> %s Expected -> Co-authored-by: test2 <test2>\n\nCo-authored-by: test3 <test3>",commit)
}
}
func Test_exclude_by_default(t *testing.T) {
// Reusing users from before
defExclude = append(defExclude, users["test1"].username)
sb.Reset()
add_x_users([]string{})
commit := sb_build()
if strings.Contains(commit, "\nCo-authored-by: test1 <test1>") {
t.Fatalf("String built incorrectly. Strings did not match: Created -> %s Expected -> Co-authored-by: test2 <test2>\n\nCo-authored-by: test3 <test3>",commit)
}
}
func Test_commit_with_grouping(t *testing.T) {
for k := range groups {
delete(groups, k)
}
defExclude = []string{}
groups["test1"] = []user{users["test1"]}
excludeMode := group_selection(groups["test1"], []string{})
sb.Reset()
add_x_users(excludeMode)
commit := sb_build()
if commit != "\nCo-authored-by: test1 <test1>" {
t.Fatalf("String built incorrectly. Strings did not match: Created -> %s Expected -> Co-authored-by: test <test>",commit)
}
}
+3
View File
@@ -0,0 +1,3 @@
module github.com/Slug-Boi/cocommit
go 1.21.9