Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

describegpt: add tests #1114

Closed
4 tasks done
rzmk opened this issue Jul 6, 2023 · 2 comments · Fixed by #1115
Closed
4 tasks done

describegpt: add tests #1114

rzmk opened this issue Jul 6, 2023 · 2 comments · Fixed by #1115
Assignees

Comments

@rzmk
Copy link
Collaborator

rzmk commented Jul 6, 2023

🗺 Overview

Add tests to qsv's describegpt command.

📌 Tasks

  • Tests
    • Use an invalid key and get the expected error response
    • If setting the --user-agent option, get the expected user-agent in the header
    • "valid" test with #[ignore] that fetches a successful response (set QSV_OPENAI_KEY in local env var)
      • "valid" tests show users examples of using the command and what to expect
@rzmk rzmk self-assigned this Jul 6, 2023
@rzmk
Copy link
Collaborator Author

rzmk commented Jul 6, 2023

@jqnatividad For the invalid key I set a random value in .env. However, trying to get stderr output includes the status messages, so I'm wondering how I should set up an assertion.

https://github.com/jqnatividad/qsv/blob/3288f8060d0e719f71e0fc61db970227ff9d2b6f/src/cmd/describegpt.rs#L100

test test_describegpt::invalid_api_key ... FAILED

failures:

---- test_describegpt::invalid_api_key stdout ----
thread 'test_describegpt::invalid_api_key' panicked at 'assertion failed: `(left == right)`
  left: `"Generating stats from in.csv using qsv stats --everything...\nGenerating frequency from in.csv using qsv frequency...\nInteracting with OpenAI API...\n\nGenerating tags from OpenAI API...\nOpenAI API Error: {\"message\":\"Incorrect API key provided: asdfasfadssf. You can find your API 
key at https://platform.openai.com/account/api-keys.\",\"type\":\"invalid_request_error\",\"param\":null,\"code\":\"invalid_api_key\"}\n"`,
 right: `""`', tests\test_describegpt.rs:25:5

@jqnatividad
Copy link
Collaborator

jqnatividad commented Jul 7, 2023

Hi @rzmk ,

You can do something like this:

    let mut cmd = wrk.command("describegpt");
    cmd.arg("--all").arg("--json").args(["--openai-key","INVALIDKEY"]).arg("in.csv");

    let output = cmd.output().unwrap();
    let got_stderr= std::str::from_utf8(&output.stderr).unwrap_or_default();

    assert!(
        got_stderr.contains("Incorrect API key provided: INVALIDKEY"))
    );

jqnatividad added a commit that referenced this issue Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants