mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 20:55:47 +00:00
test: create tests for the util functions
This commit is contained in:
@@ -6,6 +6,7 @@ require (
|
|||||||
dagger.io/dagger v0.10.0
|
dagger.io/dagger v0.10.0
|
||||||
github.com/charmbracelet/bubbles v0.20.0
|
github.com/charmbracelet/bubbles v0.20.0
|
||||||
github.com/charmbracelet/bubbletea v1.1.1
|
github.com/charmbracelet/bubbletea v1.1.1
|
||||||
|
github.com/charmbracelet/glamour v0.8.0
|
||||||
github.com/charmbracelet/lipgloss v0.13.0
|
github.com/charmbracelet/lipgloss v0.13.0
|
||||||
github.com/spf13/cobra v1.8.1
|
github.com/spf13/cobra v1.8.1
|
||||||
)
|
)
|
||||||
@@ -14,26 +15,36 @@ require (
|
|||||||
github.com/99designs/gqlgen v0.17.31 // indirect
|
github.com/99designs/gqlgen v0.17.31 // indirect
|
||||||
github.com/Khan/genqlient v0.6.0 // indirect
|
github.com/Khan/genqlient v0.6.0 // indirect
|
||||||
github.com/adrg/xdg v0.4.0 // indirect
|
github.com/adrg/xdg v0.4.0 // indirect
|
||||||
|
github.com/alecthomas/chroma/v2 v2.14.0 // indirect
|
||||||
github.com/atotto/clipboard v0.1.4 // indirect
|
github.com/atotto/clipboard v0.1.4 // indirect
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||||
|
github.com/aymerick/douceur v0.2.0 // indirect
|
||||||
github.com/charmbracelet/x/ansi v0.2.3 // indirect
|
github.com/charmbracelet/x/ansi v0.2.3 // indirect
|
||||||
github.com/charmbracelet/x/term v0.2.0 // indirect
|
github.com/charmbracelet/x/term v0.2.0 // indirect
|
||||||
|
github.com/dlclark/regexp2 v1.11.0 // indirect
|
||||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
|
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
|
||||||
|
github.com/gorilla/css v1.0.1 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/mattn/go-localereader v0.0.1 // indirect
|
github.com/mattn/go-localereader v0.0.1 // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||||
|
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
|
||||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
|
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
|
||||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||||
github.com/muesli/termenv v0.15.2 // indirect
|
github.com/muesli/reflow v0.3.0 // indirect
|
||||||
|
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a // indirect
|
||||||
github.com/rivo/uniseg v0.4.7 // indirect
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
github.com/sahilm/fuzzy v0.1.1 // indirect
|
github.com/sahilm/fuzzy v0.1.1 // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
github.com/vektah/gqlparser/v2 v2.5.6 // indirect
|
github.com/vektah/gqlparser/v2 v2.5.6 // indirect
|
||||||
|
github.com/yuin/goldmark v1.7.4 // indirect
|
||||||
|
github.com/yuin/goldmark-emoji v1.0.3 // indirect
|
||||||
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
|
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
|
||||||
|
golang.org/x/net v0.27.0 // indirect
|
||||||
golang.org/x/sync v0.8.0 // indirect
|
golang.org/x/sync v0.8.0 // indirect
|
||||||
golang.org/x/sys v0.26.0 // indirect
|
golang.org/x/sys v0.26.0 // indirect
|
||||||
|
golang.org/x/term v0.22.0 // indirect
|
||||||
golang.org/x/text v0.19.0 // indirect
|
golang.org/x/text v0.19.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
syntax for the test file
|
||||||
|
au|August|August-Brandt|augustbrandt170@gmail.com
|
||||||
|
al|Alex|Alex-itu|lolk@itu.dk
|
||||||
@@ -31,11 +31,12 @@ var rootCmd = &cobra.Command{
|
|||||||
switch len(args) {
|
switch len(args) {
|
||||||
case 0:
|
case 0:
|
||||||
// launch the tui
|
// launch the tui
|
||||||
sel_auth := tui.Entry()
|
args = append(args, tui.Entry_CM())
|
||||||
for _, a := range sel_auth {
|
fmt.Println(args[0])
|
||||||
fmt.Println(a)
|
//sel_auth := tui.Entry()
|
||||||
}
|
// for _, a := range sel_auth {
|
||||||
os.Exit(0)
|
// fmt.Println(a)
|
||||||
|
// }
|
||||||
case 1:
|
case 1:
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
utils.GitWrapper(args[0])
|
utils.GitWrapper(args[0])
|
||||||
|
|||||||
@@ -47,9 +47,7 @@ func CheckAuthorFile() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func DeleteOneAuthor(author string) {
|
func DeleteOneAuthor(author string) {
|
||||||
//author_file := Find_authorfile()
|
author_file := Find_authorfile()
|
||||||
|
|
||||||
author_file := "author_file"
|
|
||||||
|
|
||||||
// open author_file
|
// open author_file
|
||||||
file, err := os.OpenFile(author_file, os.O_RDWR, 0644)
|
file, err := os.OpenFile(author_file, os.O_RDWR, 0644)
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ func add_x_users(excludeMode []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to select a group of users to exclude in the commit message
|
// helper function to select groups of users to exclude in the commit message
|
||||||
func group_selection(group []User, excludeMode []string) []string {
|
func group_selection(group []User, excludeMode []string) []string {
|
||||||
for _, user := range Users {
|
for _, user := range Users {
|
||||||
if !(slices.Contains(group, user)) {
|
if !(slices.Contains(group, user)) {
|
||||||
|
|||||||
@@ -40,6 +40,15 @@ func Define_users(author_file string) {
|
|||||||
group_info = append(group_info, strings.Split(input[1], "|")...)
|
group_info = append(group_info, strings.Split(input[1], "|")...)
|
||||||
}
|
}
|
||||||
info := strings.Split(input_str, "|")
|
info := strings.Split(input_str, "|")
|
||||||
|
if len(info) < 4 {
|
||||||
|
if len(info) > 0 {
|
||||||
|
println("Error: User ", info[0], " is missing information")
|
||||||
|
} else {
|
||||||
|
println("Error: Some user is missing information")
|
||||||
|
}
|
||||||
|
println("Please check the author file for proper syntax")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
usr := User{Username: info[2], Email: info[3], Names: info[0] + "/" + info[1]}
|
usr := User{Username: info[2], Email: info[3], Names: info[0] + "/" + info[1]}
|
||||||
Users[info[0]] = usr
|
Users[info[0]] = usr
|
||||||
Users[info[1]] = usr
|
Users[info[1]] = usr
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package utils_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"main/src_code/go_src/cmd/utils"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
const author_data = `syntax for the test file
|
||||||
|
te|testing|TestUser|test@test.test|ex
|
||||||
|
ti|testtest|UserName2|testing@user.io;;gr1`
|
||||||
|
|
||||||
|
var envVar = os.Getenv("author_file")
|
||||||
|
|
||||||
|
func setup() {
|
||||||
|
// setup test data
|
||||||
|
os.WriteFile("author_file_test", []byte(author_data), 0644)
|
||||||
|
os.Setenv("author_file", "author_file_test")
|
||||||
|
}
|
||||||
|
|
||||||
|
func teardown() {
|
||||||
|
// remove test data
|
||||||
|
os.Remove("author_file_test")
|
||||||
|
os.Setenv("author_file", envVar)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Author tests BEGIN
|
||||||
|
func Test_FindAuthorFile(t* testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
// Test Find_authorfile
|
||||||
|
authorfile := utils.Find_authorfile()
|
||||||
|
if authorfile != "author_file_test" {
|
||||||
|
t.Errorf("Find_authorfile() = %v; want authors_file_test", authorfile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_DeleteAuthor(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
// Test DeleteOneAuthor
|
||||||
|
og_bytes, err := os.ReadFile("author_file_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error reading file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.DeleteOneAuthor("te")
|
||||||
|
deleted_bytes, err := os.ReadFile("author_file_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error reading file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if string(og_bytes) == string(deleted_bytes) {
|
||||||
|
t.Errorf("DeleteOneAuthor() did not delete author")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Author tests END
|
||||||
|
|
||||||
|
// User tests BEGIN
|
||||||
|
func Test_DefineUsers(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
// Test Define_users
|
||||||
|
utils.Define_users("author_file_test")
|
||||||
|
if len(utils.Users) != 4 {
|
||||||
|
t.Errorf("Define_users() = %v; want 4", len(utils.Users))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_RemoveUser(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
// Test RemoveUser
|
||||||
|
utils.Define_users("author_file_test")
|
||||||
|
|
||||||
|
utils.RemoveUser("te")
|
||||||
|
|
||||||
|
if len(utils.Users) != 3 {
|
||||||
|
t.Errorf("RemoveUser() = %v; want 3", len(utils.Users))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// User tests END
|
||||||
|
|
||||||
|
// Commit tests BEGIN
|
||||||
|
|
||||||
|
func Test_Commit(t* testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
utils.Define_users("author_file_test")
|
||||||
|
// Test Commit
|
||||||
|
authors := []string{"te"}
|
||||||
|
message := "Test commit message"
|
||||||
|
commit := utils.Commit(message, authors)
|
||||||
|
if commit != "Test commit message\n\nCo-authored-by: TestUser <test@test.test>" {
|
||||||
|
t.Errorf("Commit() = %v; want Test commit message\n", commit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Commit tests END
|
||||||
Reference in New Issue
Block a user