diff options
Diffstat (limited to 'home-manager/tests/modules/programs/git')
7 files changed, 203 insertions, 0 deletions
diff --git a/home-manager/tests/modules/programs/git/default.nix b/home-manager/tests/modules/programs/git/default.nix new file mode 100644 index 00000000000..45aface8d26 --- /dev/null +++ b/home-manager/tests/modules/programs/git/default.nix @@ -0,0 +1,5 @@ +{ + git-with-email = ./git-with-email.nix; + git-with-most-options = ./git.nix; + git-with-str-extra-config = ./git-with-str-extra-config.nix; +} diff --git a/home-manager/tests/modules/programs/git/git-expected.conf b/home-manager/tests/modules/programs/git/git-expected.conf new file mode 100644 index 00000000000..d02ebf31649 --- /dev/null +++ b/home-manager/tests/modules/programs/git/git-expected.conf @@ -0,0 +1,42 @@ +[alias] +a1=foo +a2=baz + +[commit] +gpgSign=true + +[extra] +boolean=true +integer=38 +multiple=1 +multiple=2 +name=value + +[extra "backcompat.with.dots"] +previously=worked + +[extra "subsection"] +value=test + +[filter "lfs"] +clean=git-lfs clean -- %f +process=git-lfs filter-process +required=true +smudge=git-lfs smudge -- %f + +[gpg] +program=path-to-gpg + +[user] +email=user@example.org +name=John Doe +signingKey=00112233445566778899AABBCCDDEEFF + +[include] +path=~/path/to/config.inc + +[includeIf "gitdir:~/src/dir"] +path=~/path/to/conditional.inc + +[includeIf "gitdir:~/src/dir"] +path=@git_include_path@ diff --git a/home-manager/tests/modules/programs/git/git-with-email-expected.conf b/home-manager/tests/modules/programs/git/git-with-email-expected.conf new file mode 100644 index 00000000000..01c1eec5823 --- /dev/null +++ b/home-manager/tests/modules/programs/git/git-with-email-expected.conf @@ -0,0 +1,15 @@ +[sendemail "hm-account"] +from=hm@example.org +smtpEncryption=tls +smtpServer=smtp.example.org +smtpUser=home.manager.jr + +[sendemail "hm@example.com"] +from=hm@example.com +smtpEncryption=tls +smtpServer=smtp.example.com +smtpUser=home.manager + +[user] +email=hm@example.com +name=H. M. Test diff --git a/home-manager/tests/modules/programs/git/git-with-email.nix b/home-manager/tests/modules/programs/git/git-with-email.nix new file mode 100644 index 00000000000..ca577eef4d3 --- /dev/null +++ b/home-manager/tests/modules/programs/git/git-with-email.nix @@ -0,0 +1,36 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + imports = [ ../../accounts/email-test-accounts.nix ]; + + config = { + programs.git = { + enable = true; + package = pkgs.gitMinimal; + userEmail = "hm@example.com"; + userName = "H. M. Test"; + }; + + nmt.script = '' + function assertGitConfig() { + local value + value=$(${pkgs.git}/bin/git config \ + --file $TESTED/home-files/.config/git/config \ + --get $1) + if [[ $value != $2 ]]; then + fail "Expected option '$1' to have value '$2' but it was '$value'" + fi + } + + assertFileExists home-files/.config/git/config + assertFileContent home-files/.config/git/config ${ + ./git-with-email-expected.conf + } + + assertGitConfig "sendemail.hm@example.com.from" "hm@example.com" + assertGitConfig "sendemail.hm-account.from" "hm@example.org" + ''; + }; +} diff --git a/home-manager/tests/modules/programs/git/git-with-str-extra-config-expected.conf b/home-manager/tests/modules/programs/git/git-with-str-extra-config-expected.conf new file mode 100644 index 00000000000..957438de13a --- /dev/null +++ b/home-manager/tests/modules/programs/git/git-with-str-extra-config-expected.conf @@ -0,0 +1,5 @@ +This can be anything. + +[user] +email=user@example.org +name=John Doe diff --git a/home-manager/tests/modules/programs/git/git-with-str-extra-config.nix b/home-manager/tests/modules/programs/git/git-with-str-extra-config.nix new file mode 100644 index 00000000000..3dbc497a5ea --- /dev/null +++ b/home-manager/tests/modules/programs/git/git-with-str-extra-config.nix @@ -0,0 +1,23 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.git = { + enable = true; + package = pkgs.gitMinimal; + extraConfig = '' + This can be anything. + ''; + userEmail = "user@example.org"; + userName = "John Doe"; + }; + + nmt.script = '' + assertFileExists home-files/.config/git/config + assertFileContent home-files/.config/git/config \ + ${./git-with-str-extra-config-expected.conf} + ''; + }; +} diff --git a/home-manager/tests/modules/programs/git/git.nix b/home-manager/tests/modules/programs/git/git.nix new file mode 100644 index 00000000000..7c0bf52de55 --- /dev/null +++ b/home-manager/tests/modules/programs/git/git.nix @@ -0,0 +1,77 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + gitInclude = { + user = { + name = "John Doe"; + email = "user@example.org"; + }; + }; + + substituteExpected = path: + pkgs.substituteAll { + src = path; + + git_include_path = + pkgs.writeText "contents" (generators.toINI { } gitInclude); + }; + +in { + config = { + programs.git = mkMerge [ + { + enable = true; + package = pkgs.gitMinimal; + aliases = { + a1 = "foo"; + a2 = "bar"; + }; + extraConfig = { + extra = { + name = "value"; + multiple = [ 1 ]; + }; + }; + ignores = [ "*~" "*.swp" ]; + includes = [ + { path = "~/path/to/config.inc"; } + { + path = "~/path/to/conditional.inc"; + condition = "gitdir:~/src/dir"; + } + { + condition = "gitdir:~/src/dir"; + contents = gitInclude; + } + ]; + signing = { + gpgPath = "path-to-gpg"; + key = "00112233445566778899AABBCCDDEEFF"; + signByDefault = true; + }; + userEmail = "user@example.org"; + userName = "John Doe"; + lfs.enable = true; + } + + { + aliases.a2 = mkForce "baz"; + extraConfig."extra \"backcompat.with.dots\"".previously = "worked"; + extraConfig.extra.boolean = true; + extraConfig.extra.integer = 38; + extraConfig.extra.multiple = [ 2 ]; + extraConfig.extra.subsection.value = "test"; + } + ]; + + nmt.script = '' + assertFileExists home-files/.config/git/config + assertFileContent home-files/.config/git/config ${ + substituteExpected ./git-expected.conf + } + ''; + }; +} |