Tests/KeycaskCLITests/GenerateTests.swift
32 lines · 1127 bytes
1import Foundation
2import Testing
3
4@Suite struct GenerateTests {
5 @Test func defaultIs24Characters() throws {
6 let cli = try CLI()
7 let r = try cli.run(["generate"], passphrase: nil)
8 #expect(r.status == 0)
9 #expect(r.stdout.count == 25)
10 }
11
12 @Test func lengthAndWords() throws {
13 let cli = try CLI()
14 let lenResult = try cli.run(["generate", "--length", "12"], passphrase: nil)
15 #expect(lenResult.stdout.count == 13)
16 let wordsOutput = try cli.run(["generate", "--words", "6"], passphrase: nil).stdout
17 let w = wordsOutput.trimmingCharacters(in: .newlines).split(separator: "-")
18 #expect(w.count == 6)
19 }
20
21 @Test func doesNotNeedAVault() throws {
22 let cli = try CLI()
23 #expect(!FileManager.default.fileExists(atPath: cli.vault.path))
24 #expect(try cli.run(["generate"], passphrase: nil).status == 0)
25 }
26
27 @Test func lengthAndWordsTogetherIsUsageError() throws {
28 let cli = try CLI()
29 #expect(
30 try cli.run(["generate", "--length", "3", "--words", "3"], passphrase: nil).status == 2)
31 }
32}