Skip to content

Commit

Permalink
test(config): add basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benpueschel committed Aug 2, 2024
1 parent c97317c commit 11772b2
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,89 @@ impl Default for Config {
}
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_deserialize_secrets_file() {
let config = Config {
secrets: Secrets::SecretsFile {
file: "secrets.toml".to_string(),
},
..Default::default()
};
let toml = toml::to_string(&config).unwrap();
assert_eq!(
toml,
"\
[remotes]
[secrets]
type = \"SecretsFile\"
file = \"secrets.toml\"
"
);
}

#[cfg(feature = "keyring")]
#[test]
fn test_deserialize_keyring() {
let config = Config {
secrets: Secrets::Keyring,
..Default::default()
};
let toml = toml::to_string(&config).unwrap();
assert_eq!(
toml,
"\
[remotes]
[secrets]
type = \"Keyring\"
"
);
}

#[test]
fn test_deserialize_plaintext() {
let mut secrets = InlineSecrets::new();
secrets.insert(
"origin".to_string(),
AuthConfig {
username: Some("user".to_string()),
password: Some("pass".to_string()),
..Default::default()
},
);
secrets.insert(
"upstream".to_string(),
AuthConfig {
token: Some("super-secret-token".to_string()),
..Default::default()
},
);
let config = Config {
secrets: Secrets::Plaintext(secrets),
..Default::default()
};
let toml = toml::to_string(&config).unwrap();
assert_eq!(
toml,
"\
[remotes]
[secrets]
type = \"Plaintext\"
[secrets.origin]
username = \"user\"
password = \"pass\"
[secrets.upstream]
token = \"super-secret-token\"
"
);
}
}

0 comments on commit 11772b2

Please sign in to comment.