Skip to content

Commit

Permalink
Use test-dir distribution directory
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpryer committed Feb 26, 2024
1 parent 9ad3bd0 commit 9de84f6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 28 deletions.
8 changes: 3 additions & 5 deletions rye/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,21 @@ toolchain = "[email protected]"
r#"
[pypi]
[bad-repo]
repository-url = "bad url"
username = "bad name"
token = "bad token"
[good-repo-bad-token]
repository-url = "https://test.pypi.org/legacy/"
repository-url = "http://localhost:5353"
token = "bad token"
[good-repo-keyring]
repository-url = "https://test.pypi.org/legacy/"
repository-url = "http://localhost:5353"
username = "test-keyring"
[no-repo-username-keyring]
repository-url = "https://test.pypi.org/legacy/"
repository-url = "http://localhost:5353"
"#,
)
.unwrap();
Expand Down
82 changes: 59 additions & 23 deletions rye/tests/test_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ mod common;
#[test]
fn test_publish() {
let space = Space::new();
space.init("my-project");
space.init("test-project");

// Build 'my-project' for distribution
// TODO(cnpryer)
space.rye_cmd().arg("build").status().unwrap();
let credentials_path = space.rye_home().join("credentials");
let credentials = std::fs::read_to_string(&credentials_path).unwrap();

// prompt for token
rye_cmd_snapshot!(space.rye_cmd().arg("publish"), @r###"
success: false
exit_code: 1
Expand All @@ -25,10 +25,42 @@ fn test_publish() {
not a terminal
"###);

// TODO(cnpryer)
// rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--skip-save-credentials"), @r###"
// "###);
rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--skip-save-credentials"), @r###"
success: false
exit_code: 1
----- stdout -----
No access token found, generate one at: https://pypi.org/manage/account/token/
ERROR InvalidDistribution: Cannot find file (or expand pattern):
'[TEMP_PATH]/project/dist/*'
----- stderr -----
Access token: error: failed to publish files
"###);

// invalid auth ('token')
rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--skip-save-credentials").arg("--username").arg("user").arg("--token").arg("token"), @r###"
success: false
exit_code: 1
----- stdout -----
ERROR InvalidDistribution: Cannot find file (or expand pattern):
'[TEMP_PATH]/project/dist/*'
----- stderr -----
error: failed to publish files
"###);

rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--skip-save-credentials").arg("--token").arg("token"), @r###"
success: false
exit_code: 1
----- stdout -----
ERROR InvalidDistribution: Cannot find file (or expand pattern):
'[TEMP_PATH]/project/dist/*'
----- stderr -----
error: failed to publish files
"###);

// invalid credentials file
rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--skip-save-credentials").arg("--repository").arg("no-repo"), @r###"
success: false
exit_code: 1
Expand All @@ -47,39 +79,43 @@ fn test_publish() {
error: relative URL without a base
"###);

// TODO(cnpryer)
// rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--skip-save-credentials").arg("--repository").arg("good-repo-bad-token").arg("-y"), @r###"
// success: false
// exit_code: 1
// ----- stdout -----
// --yes
rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--skip-save-credentials").arg("--repository").arg("good-repo-bad-token").arg("-y"), @r###"
success: false
exit_code: 1
----- stdout -----
ERROR InvalidDistribution: Cannot find file (or expand pattern):
'[TEMP_PATH]/project/dist/*'
// ----- stderr -----
// error: relative URL without a base
// "###);
----- stderr -----
error: failed to publish files
"###);

// TODO(cnpryer)
// fail until keyring setup
// keyring
rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("-r").arg("good-repo-keyring").arg("--skip-save-credentials").arg("-y"), @r###"
success: false
exit_code: 1
----- stdout -----
Uploading distributions to https://test.pypi.org/legacy/
ERROR NonInteractive: Credential not found for password.
ERROR InvalidDistribution: Cannot find file (or expand pattern):
'[TEMP_PATH]/project/dist/*'
----- stderr -----
error: failed to publish files
"###);

// TODO(cnpryer)
// prompt username
// prompt username (keyring fallback)
rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("-r").arg("no-repo-username-keyring"), @r###"
success: false
exit_code: 1
----- stdout -----
Uploading distributions to https://test.pypi.org/legacy/
ERROR NonInteractive: Credential not found for password.
ERROR InvalidDistribution: Cannot find file (or expand pattern):
'[TEMP_PATH]/project/dist/*'
----- stderr -----
Username: error: failed to publish files
"###);

let final_credentials = std::fs::read_to_string(credentials_path).unwrap();

assert_eq!(credentials, final_credentials);
}

0 comments on commit 9de84f6

Please sign in to comment.