-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBorgErrorClassifierTests.cs
More file actions
109 lines (98 loc) · 4.56 KB
/
Copy pathBorgErrorClassifierTests.cs
File metadata and controls
109 lines (98 loc) · 4.56 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using BorgMate.Services.Borg;
namespace BorgMate.Tests;
public class BorgErrorClassifierTests
{
[Theory]
[InlineData("Host key verification failed", BorgErrorType.SshHostKeyVerificationFailed)]
[InlineData("Permission denied (publickey)", BorgErrorType.SshPermissionDenied)]
[InlineData("ssh: connect to host example.com: Connection refused", BorgErrorType.SshConnectionRefused)]
[InlineData("ssh: connect to host example.com: Connection timed out", BorgErrorType.SshConnectionTimedOut)]
[InlineData("ssh: Operation timed out", BorgErrorType.SshConnectionTimedOut)]
[InlineData("ssh: connect to host example.com: No route to host", BorgErrorType.SshNoRouteToHost)]
[InlineData("ssh: Could not resolve hostname example.com", BorgErrorType.SshHostnameNotFound)]
[InlineData("ssh: Name or service not known", BorgErrorType.SshHostnameNotFound)]
[InlineData("Connection closed by remote host", BorgErrorType.SshConnectionReset)]
[InlineData("Connection reset by peer", BorgErrorType.SshConnectionReset)]
[InlineData("Write failed: Broken pipe", BorgErrorType.SshConnectionReset)]
[InlineData("ssh: /path/to/key: No such file or directory", BorgErrorType.SshKeyFileNotFound)]
public void Classify_SshErrors(string stderr, BorgErrorType expected)
{
Assert.Equal(expected, BorgErrorClassifier.Classify(stderr));
}
[Theory]
[InlineData("Repository /data/repo does not exist", BorgErrorType.RepositoryNotFound)]
[InlineData("A repository already exists at /data/repo", BorgErrorType.RepositoryAlreadyExists)]
[InlineData("Wrong passphrase for key", BorgErrorType.WrongPassphrase)]
[InlineData("Incorrect passphrase", BorgErrorType.WrongPassphrase)]
[InlineData("passphrase supplied for key is incorrect", BorgErrorType.WrongPassphrase)]
[InlineData("decryption failed", BorgErrorType.WrongPassphrase)]
[InlineData("Failed to create/acquire the lock (exclusive)", BorgErrorType.RepositoryLocked)]
[InlineData("This is not a valid repository", BorgErrorType.InvalidRepository)]
[InlineData("Incompatible repository", BorgErrorType.IncompatibleRepository)]
[InlineData("No space left on device", BorgErrorType.NoSpaceLeftOnDevice)]
[InlineData("borg: command not found", BorgErrorType.BorgBinaryNotFound)]
public void Classify_BorgErrors(string stderr, BorgErrorType expected)
{
Assert.Equal(expected, BorgErrorClassifier.Classify(stderr));
}
[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData("some random output")]
public void Classify_UnknownErrors(string stderr)
{
Assert.Equal(BorgErrorType.Unknown, BorgErrorClassifier.Classify(stderr));
}
[Fact]
public void Classify_Null_ReturnsUnknown()
{
Assert.Equal(BorgErrorType.Unknown, BorgErrorClassifier.Classify(null!));
}
[Fact]
public void IsWrongPassphrase_True()
{
Assert.True(BorgErrorClassifier.IsWrongPassphrase(BorgErrorType.WrongPassphrase));
}
[Fact]
public void IsWrongPassphrase_False()
{
Assert.False(BorgErrorClassifier.IsWrongPassphrase(BorgErrorType.SshConnectionRefused));
}
[Theory]
[InlineData(BorgErrorType.SshConnectionReset)]
[InlineData(BorgErrorType.SshConnectionTimedOut)]
[InlineData(BorgErrorType.SshConnectionRefused)]
[InlineData(BorgErrorType.SshNoRouteToHost)]
public void IsTransientSshError_True(BorgErrorType errorType)
{
Assert.True(BorgErrorClassifier.IsTransientSshError(errorType));
}
[Theory]
[InlineData(BorgErrorType.SshPermissionDenied)]
[InlineData(BorgErrorType.WrongPassphrase)]
[InlineData(BorgErrorType.Unknown)]
[InlineData(BorgErrorType.RepositoryNotFound)]
public void IsTransientSshError_False(BorgErrorType errorType)
{
Assert.False(BorgErrorClassifier.IsTransientSshError(errorType));
}
[Theory]
[InlineData(BorgErrorType.SshConnectionReset)]
[InlineData(BorgErrorType.SshConnectionTimedOut)]
[InlineData(BorgErrorType.SshConnectionRefused)]
[InlineData(BorgErrorType.SshNoRouteToHost)]
[InlineData(BorgErrorType.RepositoryLocked)]
public void IsRetryable_True(BorgErrorType errorType)
{
Assert.True(BorgErrorClassifier.IsRetryable(errorType));
}
[Theory]
[InlineData(BorgErrorType.SshPermissionDenied)]
[InlineData(BorgErrorType.WrongPassphrase)]
[InlineData(BorgErrorType.Unknown)]
[InlineData(BorgErrorType.RepositoryNotFound)]
public void IsRetryable_False(BorgErrorType errorType)
{
Assert.False(BorgErrorClassifier.IsRetryable(errorType));
}
}