forked from swiftlang/swift-corelibs-foundation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXDGTestHelper.swift
44 lines (41 loc) · 1.46 KB
/
XDGTestHelper.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2017 Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
#if os(Linux)
import Foundation
#else
import SwiftFoundation
#endif
class XDGCheck {
static func run() -> Never {
let storage = HTTPCookieStorage.shared
let properties: [HTTPCookiePropertyKey: String] = [
.name: "TestCookie",
.value: "Test @#$%^$&*99",
.path: "/",
.domain: "example.com",
]
guard let simpleCookie = HTTPCookie(properties: properties) else {
exit(HelperCheckStatus.cookieStorageNil.rawValue)
}
guard let rawValue = getenv("XDG_DATA_HOME") else {
exit(HelperCheckStatus.fail.rawValue)
}
let xdg_data_home = String(utf8String: rawValue)
storage.setCookie(simpleCookie)
let fm = FileManager.default
let destPath = xdg_data_home! + "/xdgTestHelper/.cookies.shared"
var isDir: ObjCBool = false
let exists = fm.fileExists(atPath: destPath, isDirectory: &isDir)
if (!exists) {
print("Expected cookie path: ", destPath)
exit(HelperCheckStatus.cookieStorePathWrong.rawValue)
}
exit(HelperCheckStatus.ok.rawValue)
}
}