From 05d9bee4a5155758aec3c3807c0e342b9f253522 Mon Sep 17 00:00:00 2001 From: Tomo Date: Sat, 26 Oct 2024 23:45:32 -0700 Subject: [PATCH] git-credential-oauth: fix use of mkIf and add tests Closes #6005 --- modules/programs/git-credential-oauth.nix | 3 ++- tests/default.nix | 1 + .../programs/git-credential-oauth/basic.nix | 16 ++++++++++++++++ .../programs/git-credential-oauth/default.nix | 4 ++++ .../git-credential-oauth/extra-flags.nix | 19 +++++++++++++++++++ 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/modules/programs/git-credential-oauth/basic.nix create mode 100644 tests/modules/programs/git-credential-oauth/default.nix create mode 100644 tests/modules/programs/git-credential-oauth/extra-flags.nix diff --git a/modules/programs/git-credential-oauth.nix b/modules/programs/git-credential-oauth.nix index 1f4b99247b48..5fa54276cf5d 100644 --- a/modules/programs/git-credential-oauth.nix +++ b/modules/programs/git-credential-oauth.nix @@ -30,7 +30,8 @@ in { home.packages = [ cfg.package ]; programs.git.extraConfig.credential.helper = [ - ("${cfg.package}/bin/git-credential-oauth" + lib.mkIf cfg.extraFlags + ("${cfg.package}/bin/git-credential-oauth" + + lib.optionalString (cfg.extraFlags != [ ]) " ${lib.strings.concatStringsSep " " cfg.extraFlags}") ]; }; diff --git a/tests/default.nix b/tests/default.nix index f4b03275b7d7..3271d3052301 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -81,6 +81,7 @@ in import nmtSrc { ./modules/programs/gh-dash ./modules/programs/git ./modules/programs/git-cliff + ./modules/programs/git-credential-oauth ./modules/programs/gpg ./modules/programs/gradle ./modules/programs/granted diff --git a/tests/modules/programs/git-credential-oauth/basic.nix b/tests/modules/programs/git-credential-oauth/basic.nix new file mode 100644 index 000000000000..741adfbfb524 --- /dev/null +++ b/tests/modules/programs/git-credential-oauth/basic.nix @@ -0,0 +1,16 @@ +{ config, pkgs, ... }: + +{ + programs.git-credential-oauth = { enable = true; }; + + programs.git = { enable = true; }; + + test.stubs.git-credential-oauth = { }; + + nmt.script = '' + assertFileExists home-files/.config/git/config + assertFileContains \ + home-files/.config/git/config \ + "${config.programs.git-credential-oauth.package}/bin/git-credential-oauth" + ''; +} diff --git a/tests/modules/programs/git-credential-oauth/default.nix b/tests/modules/programs/git-credential-oauth/default.nix new file mode 100644 index 000000000000..63ecb183acb8 --- /dev/null +++ b/tests/modules/programs/git-credential-oauth/default.nix @@ -0,0 +1,4 @@ +{ + git-credential-oauth-basic = ./basic.nix; + git-credential-oauth-extra-flags = ./extra-flags.nix; +} diff --git a/tests/modules/programs/git-credential-oauth/extra-flags.nix b/tests/modules/programs/git-credential-oauth/extra-flags.nix new file mode 100644 index 000000000000..7a586ede69c4 --- /dev/null +++ b/tests/modules/programs/git-credential-oauth/extra-flags.nix @@ -0,0 +1,19 @@ +{ config, pkgs, ... }: + +{ + programs.git-credential-oauth = { + enable = true; + extraFlags = [ "-device" ]; + }; + + programs.git = { enable = true; }; + + test.stubs.git-credential-oauth = { }; + + nmt.script = '' + assertFileExists home-files/.config/git/config + assertFileContains \ + home-files/.config/git/config \ + "${config.programs.git-credential-oauth.package}/bin/git-credential-oauth -device" + ''; +}