krz/hutch
an ios client for sourcehut
clone: git clone https://gitbay.org/krz/hutch.git
v3.11.0: HutchTests/RepositoryDeployKeyTests.swift · raw
1import Foundation
2import Testing
3@testable import Hutch
4
5struct RepositoryDeployKeyTests {
6 @Test
7 func decodesDeployKey() throws {
8 let json = """
9 { "rid": "k1", "keyType": "ssh-ed25519", "fingerprintSHA256": "SHA256:abc", "comment": "laptop", "access": "RW" }
10 """
11 let key = try JSONDecoder().decode(RepositoryDeployKey.self, from: Data(json.utf8))
12 #expect(key.rid == "k1")
13 #expect(key.id == "k1")
14 #expect(key.access == .rw)
15 #expect(key.comment == "laptop")
16 }
17
18 @Test
19 func decodesDeployKeyWithNullComment() throws {
20 let json = """
21 { "rid": "k2", "keyType": "ssh-rsa", "fingerprintSHA256": "SHA256:def", "comment": null, "access": "RO" }
22 """
23 let key = try JSONDecoder().decode(RepositoryDeployKey.self, from: Data(json.utf8))
24 #expect(key.comment == nil)
25 #expect(key.access == .ro)
26 }
27}