AccessGroupTests.swift 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import XCTest
  2. @testable import KeychainSwift
  3. class AccessGroupTests: XCTestCase {
  4. var obj: KeychainSwift!
  5. override func setUp() {
  6. super.setUp()
  7. obj = KeychainSwift()
  8. obj.clear()
  9. obj.lastQueryParameters = nil
  10. obj.accessGroup = nil
  11. }
  12. // MARK: - Add access group
  13. func testAddAccessGroup() {
  14. let items: [String: Any] = [
  15. "one": "two"
  16. ]
  17. obj.accessGroup = "123.my.test.group"
  18. let result = obj.addAccessGroupWhenPresent(items)
  19. XCTAssertEqual(2, result.count)
  20. XCTAssertEqual("two", result["one"] as! String)
  21. XCTAssertEqual("123.my.test.group", result["agrp"] as! String)
  22. }
  23. func testAddAccessGroup_nil() {
  24. let items: [String: Any] = [
  25. "one": "two"
  26. ]
  27. let result = obj.addAccessGroupWhenPresent(items)
  28. XCTAssertEqual(1, result.count)
  29. XCTAssertEqual("two", result["one"] as! String)
  30. }
  31. func testSet() {
  32. obj.accessGroup = "123.my.test.group"
  33. obj.set("hello :)", forKey: "key 1")
  34. XCTAssertEqual("123.my.test.group", obj.lastQueryParameters?["agrp"] as! String)
  35. }
  36. func testGet() {
  37. obj.accessGroup = "123.my.test.group"
  38. _ = obj.get("key 1")
  39. XCTAssertEqual("123.my.test.group", obj.lastQueryParameters?["agrp"] as! String)
  40. }
  41. func testDelete() {
  42. obj.accessGroup = "123.my.test.group"
  43. obj.delete("key 1")
  44. XCTAssertEqual("123.my.test.group", obj.lastQueryParameters?["agrp"] as! String)
  45. }
  46. func testClear() {
  47. obj.accessGroup = "123.my.test.group"
  48. obj.clear()
  49. XCTAssertEqual("123.my.test.group", obj.lastQueryParameters?["agrp"] as! String)
  50. }
  51. }