@@ -818,6 +818,78 @@ func TestFindConfigFile(t *testing.T) {
818818 }
819819 })
820820
821+ t .Run ("finds XDG profile-specific config" , func (t * testing.T ) {
822+ xdgDir := filepath .Join (tmpHome , ".config" , "tokendiff" )
823+ if err := os .MkdirAll (xdgDir , 0755 ); err != nil {
824+ t .Fatalf ("failed to create XDG dir: %v" , err )
825+ }
826+ profileConfig := filepath .Join (xdgDir , "config.xdgprofile" )
827+ if err := os .WriteFile (profileConfig , []byte ("# xdg profile config" ), 0644 ); err != nil {
828+ t .Fatalf ("failed to create XDG profile config: %v" , err )
829+ }
830+ defer os .RemoveAll (filepath .Join (tmpHome , ".config" ))
831+
832+ result , err := findConfigFile ("xdgprofile" )
833+ if err != nil {
834+ t .Errorf ("unexpected error: %v" , err )
835+ }
836+ if result != profileConfig {
837+ t .Errorf ("expected %q, got %q" , profileConfig , result )
838+ }
839+ })
840+
841+ t .Run ("prefers home profile over XDG profile" , func (t * testing.T ) {
842+ // Create home profile config
843+ homeProfile := filepath .Join (tmpHome , ".tokendiffrc.bothprofile" )
844+ if err := os .WriteFile (homeProfile , []byte ("# home profile config" ), 0644 ); err != nil {
845+ t .Fatalf ("failed to create home profile config: %v" , err )
846+ }
847+ defer os .Remove (homeProfile )
848+
849+ // Create XDG profile config
850+ xdgDir := filepath .Join (tmpHome , ".config" , "tokendiff" )
851+ if err := os .MkdirAll (xdgDir , 0755 ); err != nil {
852+ t .Fatalf ("failed to create XDG dir: %v" , err )
853+ }
854+ xdgProfile := filepath .Join (xdgDir , "config.bothprofile" )
855+ if err := os .WriteFile (xdgProfile , []byte ("# xdg profile config" ), 0644 ); err != nil {
856+ t .Fatalf ("failed to create XDG profile config: %v" , err )
857+ }
858+ defer os .RemoveAll (filepath .Join (tmpHome , ".config" ))
859+
860+ result , err := findConfigFile ("bothprofile" )
861+ if err != nil {
862+ t .Errorf ("unexpected error: %v" , err )
863+ }
864+ if result != homeProfile {
865+ t .Errorf ("expected home profile %q, got %q" , homeProfile , result )
866+ }
867+ })
868+
869+ t .Run ("respects XDG_CONFIG_HOME for profiles" , func (t * testing.T ) {
870+ customXDG := filepath .Join (tmpHome , "custom-xdg-profile" )
871+ xdgDir := filepath .Join (customXDG , "tokendiff" )
872+ if err := os .MkdirAll (xdgDir , 0755 ); err != nil {
873+ t .Fatalf ("failed to create custom XDG dir: %v" , err )
874+ }
875+ profileConfig := filepath .Join (xdgDir , "config.customprofile" )
876+ if err := os .WriteFile (profileConfig , []byte ("# custom xdg profile config" ), 0644 ); err != nil {
877+ t .Fatalf ("failed to create profile config: %v" , err )
878+ }
879+ defer os .RemoveAll (customXDG )
880+
881+ os .Setenv ("XDG_CONFIG_HOME" , customXDG )
882+ defer os .Unsetenv ("XDG_CONFIG_HOME" )
883+
884+ result , err := findConfigFile ("customprofile" )
885+ if err != nil {
886+ t .Errorf ("unexpected error: %v" , err )
887+ }
888+ if result != profileConfig {
889+ t .Errorf ("expected %q, got %q" , profileConfig , result )
890+ }
891+ })
892+
821893 t .Run ("respects XDG_CONFIG_HOME" , func (t * testing.T ) {
822894 customXDG := filepath .Join (tmpHome , "custom-xdg" )
823895 xdgDir := filepath .Join (customXDG , "tokendiff" )
0 commit comments