@@ -26,25 +26,43 @@ class BaseTestCase: XCTestCase {
2626 let key : String
2727 let serverURL : String
2828 let testableServerURL : String
29+ let masterKey : String
2930 }
3031
3132 static let cnApp = AppInfo (
3233 id: " S5vDI3IeCk1NLLiM1aFg3262-gzGzoHsz " ,
3334 key: " 7g5pPsI55piz2PRLPWK5MPz0 " ,
3435 serverURL: " https://s5vdi3ie.lc-cn-n1-shared.com " ,
35- testableServerURL: " https://beta.leancloud.cn " )
36+ testableServerURL: " https://beta.leancloud.cn " ,
37+ masterKey: " Q26gTodbyi1Ki7lM9vtncF6U " )
38+
39+ static let tds1App = AppInfo (
40+ id: " 7DY3DVgOQogGnYMMUajgvPRq-TjsS5DXC " ,
41+ key: " RJOLaAvGiF7mQguXp68W9Mv5 " ,
42+ serverURL: " https://7DY3DVgO.cloud.tds1.tapapis.cn " ,
43+ testableServerURL: " " ,
44+ masterKey: " 3PSWpjByenawCVo0FpnXfNgx " )
3645
3746 static let ceApp = AppInfo (
3847 id: " skhiVsqIk7NLVdtHaUiWn0No-9Nh9j0Va " ,
3948 key: " T3TEAIcL8Ls5XGPsGz41B1bz " ,
4049 serverURL: " https://skhivsqi.lc-cn-e1-shared.com " ,
41- testableServerURL: " https://beta-tab.leancloud.cn " )
50+ testableServerURL: " https://beta-tab.leancloud.cn " ,
51+ masterKey: " FTPdEcG7vLKxNqKxYhTFdK4g " )
4252
4353 static let usApp = AppInfo (
4454 id: " jenSt9nvWtuJtmurdE28eg5M-MdYXbMMI " ,
4555 key: " 8VLPsDlskJi8KsKppED4xKS0 " ,
4656 serverURL: " " ,
47- testableServerURL: " https://beta-us.leancloud.cn " )
57+ testableServerURL: " https://beta-us.leancloud.cn " ,
58+ masterKey: " fasiJXz8jvSwn3G2B2QeraRe " )
59+
60+ static let appInfoTable = [
61+ cnApp. id : cnApp,
62+ tds1App. id : tds1App,
63+ ceApp. id : ceApp,
64+ usApp. id : usApp,
65+ ]
4866
4967 static var config : LCApplication . Configuration {
5068 var config = LCApplication . Configuration ( )
@@ -58,6 +76,7 @@ class BaseTestCase: XCTestCase {
5876 override class func setUp( ) {
5977 super. setUp ( )
6078 let app = BaseTestCase . cnApp
79+ // let app = BaseTestCase.tds1App
6180// let app = BaseTestCase.ceApp
6281// let app = BaseTestCase.usApp
6382 TestObject . register ( )
@@ -70,17 +89,27 @@ class BaseTestCase: XCTestCase {
7089 configuration: BaseTestCase . config)
7190 }
7291
92+ override func setUp( ) {
93+ super. setUp ( )
94+ BaseTestCase . cleanPersistentCache ( )
95+ }
96+
7397 override class func tearDown( ) {
74- [ LCApplication . default. applicationSupportDirectoryURL,
75- LCApplication . default. cachesDirectoryURL]
76- . forEach { ( url) in
77- if FileManager . default. fileExists ( atPath: url. path) {
78- try ! FileManager . default. removeItem ( at: url)
79- }
80- }
98+ cleanPersistentCache ( )
8199 LCApplication . default. unregister ( )
82100 super. tearDown ( )
83101 }
102+
103+ static func cleanPersistentCache( ) {
104+ [
105+ LCApplication . default. applicationSupportDirectoryURL,
106+ LCApplication . default. cachesDirectoryURL,
107+ ] . forEach { ( url) in
108+ if FileManager . default. fileExists ( atPath: url. path) {
109+ try ! FileManager . default. removeItem ( at: url)
110+ }
111+ }
112+ }
84113}
85114
86115extension BaseTestCase {
@@ -167,18 +196,10 @@ extension BaseTestCase {
167196extension LCApplication {
168197
169198 var masterKey : String {
170- let key : String
171- switch self . id {
172- case BaseTestCase . cnApp. id:
173- key = " Q26gTodbyi1Ki7lM9vtncF6U "
174- case BaseTestCase . ceApp. id:
175- key = " FTPdEcG7vLKxNqKxYhTFdK4g "
176- case BaseTestCase . usApp. id:
177- key = " fasiJXz8jvSwn3G2B2QeraRe "
178- default :
199+ guard let key = BaseTestCase . appInfoTable [ self . id] ? . masterKey else {
179200 fatalError ( )
180201 }
181- return key + " ,master "
202+ return " \( key ) ,master "
182203 }
183204
184205 var v2router : AppRouter {
@@ -189,11 +210,11 @@ extension LCApplication {
189210
190211 var applicationSupportDirectoryURL : URL {
191212 return ( try !
192- FileManager . default. url (
193- for: . applicationSupportDirectory,
194- in: . userDomainMask,
195- appropriateFor: nil ,
196- create: false ) )
213+ FileManager . default. url (
214+ for: . applicationSupportDirectory,
215+ in: . userDomainMask,
216+ appropriateFor: nil ,
217+ create: false ) )
197218 . appendingPathComponent (
198219 LocalStorageContext . domain,
199220 isDirectory: true )
@@ -204,11 +225,11 @@ extension LCApplication {
204225
205226 var cachesDirectoryURL : URL {
206227 return ( try !
207- FileManager . default. url (
208- for: . cachesDirectory,
209- in: . userDomainMask,
210- appropriateFor: nil ,
211- create: false ) )
228+ FileManager . default. url (
229+ for: . cachesDirectory,
230+ in: . userDomainMask,
231+ appropriateFor: nil ,
232+ create: false ) )
212233 . appendingPathComponent (
213234 LocalStorageContext . domain,
214235 isDirectory: true )
0 commit comments