Skip to content

Commit

Permalink
add modify file add commit status test
Browse files Browse the repository at this point in the history
  • Loading branch information
richardjennings committed Jan 9, 2024
1 parent 24a808d commit e927c1b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions internal/mygit/mygit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,34 @@ func Test_AddFile_Status_Commit(t *testing.T) {
files = testListFiles(t, config.ObjectPath(), false)
// blob, tree object, commit object
assert.Equal(t, 3, len(files))

// Test adding a modified file to the index

// update a file
if err := os.WriteFile(filepath.Join(dir, "hello"), []byte("hello world"), 0644); err != nil {
t.Fatal(err)
}
// status should be modified
buf = bytes.NewBuffer(nil)
if err := Status(buf); err != nil {
t.Fatal(err)
}
assert.Equal(t, " M hello\n", buf.String())
// add the file to the index
if err := Add("."); err != nil {
t.Fatal(err)
}
// create commit
sha, err = Commit()

Check failure on line 105 in internal/mygit/mygit_test.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to sha (ineffassign)
if err != nil {
t.Fatal(err)
}
// status should be empty
buf = bytes.NewBuffer(nil)
if err := Status(buf); err != nil {
t.Fatal(err)
}
assert.Equal(t, "", buf.String())
}

func testDir(t *testing.T) string {
Expand Down

0 comments on commit e927c1b

Please sign in to comment.