• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

endoze / nysm / 6842908510

12 Nov 2023 08:18PM UTC coverage: 90.588% (-0.9%) from 91.463%
6842908510

Pull #6

github

endoze
chore: Add tests for errors

In order to better cover the expected bevahior of errors, this commit
adds a few tests to exercise the crate errors we use.
Pull Request #6: chore: Add tests for errors

2 of 3 new or added lines in 1 file covered. (66.67%)

77 of 85 relevant lines covered (90.59%)

1.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/src/error.rs
1
#![deny(missing_docs)]
2
#[derive(thiserror::Error, Debug)]
3
#[repr(u8)]
4
/// Enum to define all of the possible errors that can occur during normal
5
/// use of Nysm.
6
pub enum NysmError {
7
  /// Error occurs when attempting to parse data as Json fails.
8
  #[error("Unable to parse data as json")]
9
  SerdeJson(#[from] serde_json::Error),
10

11
  /// Error occurs when attempting to parse data as Text fails.
12
  #[error("Unable to parse data as yaml")]
13
  SerdeYaml(#[from] serde_yaml::Error),
14

15
  /// Error occurs when pretty printing the contents of a secret fails.
16
  #[error("Unable to pretty print data")]
17
  BatPrint(#[from] bat::error::Error),
18

19
  /// Error occurs when reading/writing a temporary file for secret
20
  /// editing fails.
21
  #[error("Unable to read/write file caused by: {}", .0)]
22
  IO(#[from] std::io::Error),
23

24
  /// Error occurs when retrieving a list of secrets from a provider fails.
25
  #[error("Unable to retrieve list of secrets from aws response")]
26
  AwsListSecretsNoList,
27

28
  /// Error occurs when a specific secret has no string value.
29
  #[error("Unable to retrieve string value from aws response")]
30
  AwsSecretValueNoValueString,
31

32
  /// Error occurs when updating a secret's string value fails
33
  #[error("Unable to update secret value")]
34
  AwsSecretValueUpdate,
35
}
36

37
impl PartialEq for NysmError {
×
38
  fn eq(&self, other: &Self) -> bool {
1✔
39
    println!("LEFT = {:?}", std::mem::discriminant(self));
1✔
40
    println!("RIGHT = {:?}", std::mem::discriminant(other));
2✔
41
    std::mem::discriminant(self) == std::mem::discriminant(other)
2✔
42
  }
43
}
44

NEW
45
#[cfg(test)]
×
46
mod tests {
47
  use super::*;
48
  use serde::de::Error;
49

50
  #[test]
51
  fn test_serde_json_error() {
52
    let error = NysmError::SerdeJson(serde_json::Error::custom("custom error"));
53
    assert_eq!(error.to_string(), "Unable to parse data as json");
54
  }
55

56
  #[test]
57
  fn test_serde_yaml_error() {
58
    let error = NysmError::SerdeYaml(serde_yaml::Error::custom("custom error"));
59
    assert_eq!(error.to_string(), "Unable to parse data as yaml");
60
  }
61

62
  #[test]
63
  fn test_bat_print_error() {
64
    let error = NysmError::BatPrint(Into::<bat::error::Error>::into("custom error"));
65
    assert_eq!(error.to_string(), "Unable to pretty print data");
66
  }
67

68
  #[test]
69
  fn test_io_error() {
70
    let error = NysmError::IO(std::io::Error::new(
71
      std::io::ErrorKind::Other,
72
      "custom error",
73
    ));
74
    assert_eq!(
75
      error.to_string(),
76
      "Unable to read/write file caused by: custom error"
77
    );
78
  }
79

80
  #[test]
81
  fn test_aws_list_secrets_no_list_error() {
82
    let error = NysmError::AwsListSecretsNoList;
83
    assert_eq!(
84
      error.to_string(),
85
      "Unable to retrieve list of secrets from aws response"
86
    );
87
  }
88

89
  #[test]
90
  fn test_aws_secret_value_no_value_string_error() {
91
    let error = NysmError::AwsSecretValueNoValueString;
92
    assert_eq!(
93
      error.to_string(),
94
      "Unable to retrieve string value from aws response"
95
    );
96
  }
97

98
  #[test]
99
  fn test_aws_secret_value_update_error() {
100
    let error = NysmError::AwsSecretValueUpdate;
101
    assert_eq!(error.to_string(), "Unable to update secret value");
102
  }
103

104
  #[test]
105
  fn test_partial_eq() {
106
    let error1 = NysmError::SerdeJson(serde_json::Error::custom("custom error"));
107
    let error2 = NysmError::SerdeJson(serde_json::Error::custom("custom error"));
108
    let error3 = NysmError::SerdeYaml(serde_yaml::Error::custom("different error"));
109

110
    assert_eq!(error1, error2);
111
    assert_ne!(error1, error3);
112
  }
113
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc