Skip to content

Commit

Permalink
test 🧪: new test
Browse files Browse the repository at this point in the history
Signed-off-by: moualhi zine el abidine <[email protected]>
  • Loading branch information
muandane committed Nov 17, 2023
1 parent 00ea836 commit 702676f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
1 change: 1 addition & 0 deletions pkg/config/configInit.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func GetGitRootDir() (string, error) {

func SaveGitmojisToFile(config initConfig, filename string) error {
gitDir, err := GetGitRootDir()

if err != nil {
return err
}

Check warning on line 46 in pkg/config/configInit.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/configInit.go#L45-L46

Added lines #L45 - L46 were not covered by tests
Expand Down
38 changes: 19 additions & 19 deletions pkg/config/configInit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,6 @@ import (
"testing"
)

func TestAddCustomCommitTypes(t *testing.T) {
gitmojis := []Gitmoji{}
customGitmojis := AddCustomCommitTypes(gitmojis)

if len(customGitmojis) != 11 {
t.Errorf("Expected 11 gitmojis, got %d", len(customGitmojis))
}
}

func TestGetGitRootDir(t *testing.T) {
gitDir, err := GetGitRootDir()
if err != nil {
t.Errorf("Error finding git root directory: %v", err)
}

if gitDir == "" {
t.Error("Expected git root directory to be non-empty")
}
}
func TestSaveGitmojisToFile(t *testing.T) {
gitmojis := AddCustomCommitTypes([]Gitmoji{})
config := initConfig{
Expand Down Expand Up @@ -55,6 +36,16 @@ func TestSaveGitmojisToFile(t *testing.T) {
// Clean up
os.Remove(filepath.Join(gitDir, ".goji.json"))
}
func TestGetGitRootDir(t *testing.T) {
gitDir, err := GetGitRootDir()
if err != nil {
t.Errorf("Error finding git root directory: %v", err)
}

if gitDir == "" {
t.Error("Expected git root directory to be non-empty")
}
}

func TestInitRepoConfig(t *testing.T) {
err := InitRepoConfig()
Expand All @@ -77,3 +68,12 @@ func TestInitRepoConfig(t *testing.T) {
// Clean up
os.Remove(filepath.Join(gitDir, ".goji.json"))
}

func TestAddCustomCommitTypes(t *testing.T) {
gitmojis := []Gitmoji{}
customGitmojis := AddCustomCommitTypes(gitmojis)

if len(customGitmojis) != 11 {
t.Errorf("Expected 11 gitmojis, got %d", len(customGitmojis))
}
}
10 changes: 10 additions & 0 deletions pkg/utils/commitMessage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ import (
"github.com/stretchr/testify/mock"
)

type MockSurvey struct {
mock.Mock
}

func (m *MockSurvey) AskOne(prompt survey.Prompt, response interface{}, options ...survey.AskOpt) error {
args := m.Called(prompt, response, options)
return args.Error(0)
}

func TestAskQuestions(t *testing.T) {
testCases := []struct {
Name string
Expand Down Expand Up @@ -129,6 +138,7 @@ func TestAskQuestions_Failure(t *testing.T) {
t.Errorf("Expected commit message '', got '%s'", commitMessage)
}
}

func TestIsInSkipQuestions(t *testing.T) {
testCases := []struct {
skipQuestions []string
Expand Down

0 comments on commit 702676f

Please sign in to comment.