diff options
author | Justin Tobler <jtobler@gitlab.com> | 2022-08-04 01:53:52 +0300 |
---|---|---|
committer | Justin Tobler <jtobler@gitlab.com> | 2022-08-12 00:41:58 +0300 |
commit | b55885d92c1ea09b0ac7599d1333ab095ecbc257 (patch) | |
tree | 9df273ff099624e6c7ffafd1d2bd6d9bb02e78a6 | |
parent | 09146540d0023506b06da85ffe7ed0764ed4c789 (diff) |
fsck: Test ignore rules configurationjt-update-git-fsck-config
Added tests to ensure correct configuration of git-fsck(1) is generated
and applied to the command when executed.
-rw-r--r-- | internal/git/command_description_test.go | 45 | ||||
-rw-r--r-- | internal/git/command_factory_test.go | 71 |
2 files changed, 116 insertions, 0 deletions
diff --git a/internal/git/command_description_test.go b/internal/git/command_description_test.go index 574fa5592..f5895492b 100644 --- a/internal/git/command_description_test.go +++ b/internal/git/command_description_test.go @@ -69,3 +69,48 @@ func TestThreadsConfigValue(t *testing.T) { require.Equal(t, tt.threads, actualThreads) } } + +func TestFsckConfiguration_prefix(t *testing.T) { + t.Parallel() + + for _, tc := range []struct { + prefix string + expected []ConfigPair + }{ + { + prefix: "fsck", + expected: []ConfigPair{ + {Key: "transfer.fsckObjects", Value: "true"}, + {Key: "fsck.badTimezone", Value: "ignore"}, + {Key: "fsck.missingSpaceBeforeDate", Value: "ignore"}, + {Key: "fsck.zeroPaddedFilemode", Value: "ignore"}, + }, + }, + { + prefix: "fetch.fsck", + expected: []ConfigPair{ + {Key: "transfer.fsckObjects", Value: "true"}, + {Key: "fetch.fsck.badTimezone", Value: "ignore"}, + {Key: "fetch.fsck.missingSpaceBeforeDate", Value: "ignore"}, + {Key: "fetch.fsck.zeroPaddedFilemode", Value: "ignore"}, + }, + }, + { + prefix: "receive.fsck", + expected: []ConfigPair{ + {Key: "transfer.fsckObjects", Value: "true"}, + {Key: "receive.fsck.badTimezone", Value: "ignore"}, + {Key: "receive.fsck.missingSpaceBeforeDate", Value: "ignore"}, + {Key: "receive.fsck.zeroPaddedFilemode", Value: "ignore"}, + }, + }, + } { + t.Run(tc.prefix, func(t *testing.T) { + opts := templateFsckConfiguration(tc.prefix) + + for _, config := range tc.expected { + require.Containsf(t, opts, config, fmt.Sprintf("missing %s", config.Key)) + } + }) + } +} diff --git a/internal/git/command_factory_test.go b/internal/git/command_factory_test.go index 5cff2406f..76dccbb7d 100644 --- a/internal/git/command_factory_test.go +++ b/internal/git/command_factory_test.go @@ -589,3 +589,74 @@ func TestExecCommandFactory_SidecarGitConfiguration(t *testing.T) { }) } } + +// TestFsckConfiguration tests the hardcoded configuration of the +// git fsck subcommand generated through the command factory. +func TestFsckConfiguration(t *testing.T) { + t.Parallel() + + for _, tc := range []struct { + desc string + data string + }{ + { + desc: "with valid commit", + data: strings.Join([]string{ + "tree " + gittest.DefaultObjectHash.EmptyTreeOID.String(), + "author " + gittest.DefaultCommitterSignature, + "committer " + gittest.DefaultCommitterSignature, + "", + "message", + }, "\n"), + }, + { + desc: "with missing space", + data: strings.Join([]string{ + "tree " + gittest.DefaultObjectHash.EmptyTreeOID.String(), + "author Scrooge McDuck <scrooge@mcduck.com>1659043074 -0500", + "committer Scrooge McDuck <scrooge@mcduck.com>1659975573 -0500", + "", + "message", + }, "\n"), + }, + { + desc: "with bad timezone", + data: strings.Join([]string{ + "tree " + gittest.DefaultObjectHash.EmptyTreeOID.String(), + "author Scrooge McDuck <scrooge@mcduck.com> 1659043074 -0500BAD", + "committer Scrooge McDuck <scrooge@mcduck.com> 1659975573 -0500BAD", + "", + "message", + }, "\n"), + }, + } { + t.Run(tc.desc, func(t *testing.T) { + ctx := testhelper.Context(t) + cfg := testcfg.Build(t) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, + gittest.CreateRepositoryConfig{SkipCreationViaService: true}, + ) + + // Create commit object. + commitOut := gittest.ExecOpts(t, cfg, gittest.ExecConfig{Stdin: bytes.NewBufferString(tc.data)}, + "-C", repoPath, "hash-object", "-w", "-t", "commit", "--stdin", "--literally", + ) + _, err := gittest.DefaultObjectHash.FromHex(text.ChompBytes(commitOut)) + require.NoError(t, err) + + gitCmdFactory, cleanup, err := git.NewExecCommandFactory(cfg) + require.NoError(t, err) + defer cleanup() + + // Create fsck command with configured ignore rules options. + cmd, err := gitCmdFactory.New(ctx, repoProto, + git.SubCmd{Name: "fsck"}, + ) + require.NoError(t, err) + + // Execute git fsck command. + err = cmd.Wait() + require.NoError(t, err) + }) + } +} |