-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix : noemoji config not working + cover tests (#40)
* fix 🐛: fix mod Signed-off-by: moualhi zine el abidine <[email protected]> * test 🧪: noemojis ? Signed-off-by: moualhi zine el abidine <[email protected]> * test 🧪: noemojis ? Signed-off-by: moualhi zine el abidine <[email protected]> * test 🧪: noemojis ? Signed-off-by: moualhi zine el abidine <[email protected]> * test 🧪: noemojis ? Signed-off-by: moualhi zine el abidine <[email protected]> * test 🧪: noemojis ? Signed-off-by: moualhi zine el abidine <[email protected]> * test 🧪: noemojis ? Signed-off-by: moualhi zine el abidine <[email protected]> * test 🧪: noemojis ? Signed-off-by: moualhi zine el abidine <[email protected]> * test 🧪: noemojis ? Signed-off-by: moualhi zine el abidine <[email protected]> * test 🧪: noemojis ? Signed-off-by: moualhi zine el abidine <[email protected]> * test: noemojis ? Signed-off-by: moualhi zine el abidine <[email protected]> * fix 🐛: noemojis ? Signed-off-by: moualhi zine el abidine <[email protected]> * fix 🐛: updated branch * fix 🐛: issue with gh action * fix 🐛: issue with gh action --------- Signed-off-by: moualhi zine el abidine <[email protected]>
- Loading branch information
Showing
8 changed files
with
128 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,10 @@ jobs: | |
go-version: '1.22.1' | ||
- name: Check out code | ||
uses: actions/[email protected] | ||
- name: Set up Git | ||
run: | | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "GitHub Action" | ||
- name: Test and generate coverage report | ||
run: go test -coverprofile=coverage.out ./... | ||
- name: Upload coverage reports to Codecov | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"os" | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/alecthomas/assert/v2" | ||
"github.com/fatih/color" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func TestCommit(t *testing.T) { | ||
t.Run("success", func(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping test in short mode.") | ||
} | ||
|
||
tempDir, err := os.MkdirTemp("", "git-commit-test") | ||
if err != nil { | ||
t.Fatalf("error creating temp dir: %v", err) | ||
} | ||
defer os.RemoveAll(tempDir) | ||
|
||
if err := os.Chdir(tempDir); err != nil { | ||
t.Fatalf("error changing to temp dir: %v", err) | ||
} | ||
|
||
if err := exec.Command("git", "init").Run(); err != nil { | ||
t.Fatalf("error initializing git repo: %v", err) | ||
} | ||
|
||
if err := os.WriteFile("testfile", []byte("test content"), 0644); err != nil { | ||
t.Fatalf("error writing testfile: %v", err) | ||
} | ||
|
||
if err := exec.Command("git", "add", "testfile").Run(); err != nil { | ||
t.Fatalf("error adding testfile to index: %v", err) | ||
} | ||
|
||
if err := commit("test commit", "test commit body", false); err != nil { | ||
t.Fatalf("error committing: %v", err) | ||
} | ||
|
||
if err := exec.Command("git", "log", "-1", "--pretty=%s").Run(); err != nil { | ||
t.Fatalf("error checking commit: %v", err) | ||
} | ||
}) | ||
} | ||
|
||
func TestRootCmd_VersionFlag(t *testing.T) { | ||
|
||
var versionFlag bool | ||
// Save the original os.Stdout | ||
originalStdout := os.Stdout | ||
// Create a buffer to capture the output | ||
r, w, _ := os.Pipe() | ||
os.Stdout = w | ||
|
||
// Create a new command | ||
cmd := &cobra.Command{ | ||
Use: "goji", | ||
Short: "Goji CLI", | ||
Long: `Goji is a cli tool to generate conventional commits with emojis`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if versionFlag { | ||
color.Set(color.FgGreen) | ||
fmt.Printf("goji version: v%s\n", version) | ||
color.Unset() | ||
return | ||
} | ||
}, | ||
} | ||
|
||
// Set the version flag | ||
cmd.Flags().BoolVarP(&versionFlag, "version", "v", false, "Display version information") | ||
cmd.SetArgs([]string{"--version"}) | ||
|
||
// Execute the command | ||
if err := cmd.Execute(); err != nil { | ||
t.Fatalf("Error executing command: %v", err) | ||
} | ||
|
||
// Close the writer and restore os.Stdout | ||
w.Close() | ||
os.Stdout = originalStdout | ||
|
||
// Read the captured output | ||
var buf bytes.Buffer | ||
_, err := io.Copy(&buf, r) | ||
if err != nil { | ||
t.Fatalf("Error reading captured output: %v", err) | ||
} | ||
output := buf.String() | ||
|
||
// Assert that the output contains the expected version string | ||
assert.Contains(t, output, "goji version: v") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters