@@ -24,23 +24,26 @@ import 'util.dart';
24
24
void main () {
25
25
final String flutterCommand = getFlutterCommand (const LocalPlatform ());
26
26
27
+ late MockPlatform platform;
27
28
late Directory packagesDir;
28
29
late MockGitDir gitDir;
29
30
late TestProcessRunner processRunner;
31
+ late PublishCommand command;
30
32
late CommandRunner <void > commandRunner;
31
33
late MockStdin mockStdin;
32
34
late FileSystem fileSystem;
33
35
// Map of package name to mock response.
34
36
late Map <String , Map <String , dynamic >> mockHttpResponses;
35
37
36
38
void createMockCredentialFile () {
37
- final String credentialPath = PublishCommand .getCredentialPath ();
38
- fileSystem.file (credentialPath)
39
+ fileSystem.file (command.credentialsPath)
39
40
..createSync (recursive: true )
40
41
..writeAsStringSync ('some credential' );
41
42
}
42
43
43
44
setUp (() async {
45
+ platform = MockPlatform (isLinux: true );
46
+ platform.environment['HOME' ] = '/home' ;
44
47
fileSystem = MemoryFileSystem ();
45
48
packagesDir = createPackagesDirectory (fileSystem: fileSystem);
46
49
processRunner = TestProcessRunner ();
@@ -71,14 +74,15 @@ void main() {
71
74
});
72
75
73
76
mockStdin = MockStdin ();
74
- commandRunner = CommandRunner <void >('tester' , '' )
75
- ..addCommand (PublishCommand (
76
- packagesDir,
77
- processRunner: processRunner,
78
- stdinput: mockStdin,
79
- gitDir: gitDir,
80
- httpClient: mockClient,
81
- ));
77
+ command = PublishCommand (
78
+ packagesDir,
79
+ platform: platform,
80
+ processRunner: processRunner,
81
+ stdinput: mockStdin,
82
+ gitDir: gitDir,
83
+ httpClient: mockClient,
84
+ );
85
+ commandRunner = CommandRunner <void >('tester' , '' )..addCommand (command);
82
86
});
83
87
84
88
group ('Initial validation' , () {
@@ -880,6 +884,44 @@ void main() {
880
884
isNot (contains ('git-push' )));
881
885
});
882
886
});
887
+
888
+ group ('credential location' , () {
889
+ test ('Linux with XDG' , () async {
890
+ platform = MockPlatform (isLinux: true );
891
+ platform.environment['XDG_CONFIG_HOME' ] = '/xdghome/config' ;
892
+ command = PublishCommand (packagesDir, platform: platform);
893
+
894
+ expect (
895
+ command.credentialsPath, '/xdghome/config/dart/pub-credentials.json' );
896
+ });
897
+
898
+ test ('Linux without XDG' , () async {
899
+ platform = MockPlatform (isLinux: true );
900
+ platform.environment['HOME' ] = '/home' ;
901
+ command = PublishCommand (packagesDir, platform: platform);
902
+
903
+ expect (
904
+ command.credentialsPath, '/home/.config/dart/pub-credentials.json' );
905
+ });
906
+
907
+ test ('macOS' , () async {
908
+ platform = MockPlatform (isMacOS: true );
909
+ platform.environment['HOME' ] = '/Users/someuser' ;
910
+ command = PublishCommand (packagesDir, platform: platform);
911
+
912
+ expect (command.credentialsPath,
913
+ '/Users/someuser/Library/Application Support/dart/pub-credentials.json' );
914
+ });
915
+
916
+ test ('Windows' , () async {
917
+ platform = MockPlatform (isWindows: true );
918
+ platform.environment['APPDATA' ] = r'C:\Users\SomeUser\AppData' ;
919
+ command = PublishCommand (packagesDir, platform: platform);
920
+
921
+ expect (command.credentialsPath,
922
+ r'C:\Users\SomeUser\AppData\dart\pub-credentials.json' );
923
+ });
924
+ });
883
925
}
884
926
885
927
/// An extension of [RecordingProcessRunner] that stores 'flutter pub publish'
0 commit comments