Skip to content

Commit

Permalink
Demonstrate the error that occurs when pushing a commit with a bad date
Browse files Browse the repository at this point in the history
  • Loading branch information
spraints committed Nov 7, 2024
1 parent 20bb13d commit 0221768
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ go-test-integration:

# Add our compiled `spokes-receive-pack` to the PATH while running tests:
PATH="$(CURDIR)/bin:$(PATH)" \
GIT_CONFIG_SYSTEM="$(CURDIR)/internal/integration/testdata/gitconfig" \
$(GO) test $(TESTINTEGRATIONFLAGS) $(TESTSUITE) 2>&1

@echo "$(M) disabling failpoints ..."
Expand Down
14 changes: 14 additions & 0 deletions internal/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ This commit object intentionally broken

type SpokesReceivePackTestSuite struct {
suite.Suite
suiteDir string
localRepo, remoteRepo string
}

func (suite *SpokesReceivePackTestSuite) SetupTest() {
var err error
req := require.New(suite.T())

pwd, err := os.Getwd()
req.NoError(err, "pwd")

// set up a folder that will be used as a "local" Git repo
localRepo, err := os.MkdirTemp("", "local")
req.NoError(err, fmt.Sprintf("unable to create the local Git repo: %s", err))
Expand Down Expand Up @@ -80,6 +84,7 @@ func (suite *SpokesReceivePackTestSuite) SetupTest() {
req.NoError(exec.Command("git", "config", "transfer.hideRefs", "refs/__hidden__").Run())

// store the state
suite.suiteDir = pwd
suite.localRepo = localRepo
suite.remoteRepo = remoteRepo
}
Expand Down Expand Up @@ -181,6 +186,15 @@ func (suite *SpokesReceivePackTestSuite) TestSpokesReceivePackHiddenRefs() {
"should partially fail")
}

func (suite *SpokesReceivePackTestSuite) TestBadDate() {
cmd := exec.Command("git", "-C", filepath.Join(suite.suiteDir, "testdata/bad-date/sha1.git"),
"push", "--receive-pack=spokes-receive-pack-wrapper", suite.remoteRepo, "main")
out, err := cmd.CombinedOutput()
suite.T().Logf("$ git %s\n%s", strings.Join(cmd.Args, " "), out)
assert.Error(suite.T(), err, "expect an error a repo with a malformed committer line in a commit")
assert.Contains(suite.T(), string(out), " badDate:", "should complain about a bad date")
}

func (suite *SpokesReceivePackTestSuite) TestWithGovernor() {
started := make(chan any)
govSock, msgs, cleanup := startFakeGovernor(suite.T(), started, nil)
Expand Down
4 changes: 4 additions & 0 deletions internal/integration/testdata/gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file has a subset of options from our prod /etc/gitconfig.

[receive]
fsckObjects = true

0 comments on commit 0221768

Please sign in to comment.