Skip to content

bktec upload: upload test results to Test Engine#278

Open
pda wants to merge 1 commit intomainfrom
bktec-upload
Open

bktec upload: upload test results to Test Engine#278
pda wants to merge 1 commit intomainfrom
bktec-upload

Conversation

@pda
Copy link
Member

@pda pda commented Mar 14, 2025

Teach bktec to upload test results to Test Engine.

$ bktec upload junit.xml
+++ Buildkite Test Engine Client: bktec dev


______ ______ _____
___  /____  /___  /____________
__  __ \_  //_/  __/  _ \  ___/
_  /_/ /  ,<  / /_ /  __/ /__
/_.___//_/|_| \__/ \___/\___/

2025/03/14 17:47:47 INFO Uploading key=01959384-2d0d-7318-8af7-4833b6eaff32 format=junit filename=test.xml
2025/03/14 17:47:48 INFO Upload successful upload_id=01959384-2d8a-7dad-9b97-37c1b4a0e67e upload_url=https://buildkite.com/organizations/example/analytics/suites/example/uploads/01959384-2d8a-7dad-9b97-37c1b4a0e67e

@pda pda requested a review from a team March 14, 2025 07:23
printStartUpMessage()

// TODO: proper subcommands
if flag.Arg(0) == "upload" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good for now. IF we have more than 1 subcommands, we might start thinking a better way to manage them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some slightly improved subcommand handling in another upcoming branch

Comment on lines 59 to 63
filename := flag.Arg(1)
if filename == "" {
return fmt.Errorf("expected filename for JUnit XML or JSON file")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is a file path, not necessarily a file name? Should we update the error message to be clear?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah true, there's always a bit of ambiguity re. whether “filename” means “just the basename” or “the full path”. I should clarify.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the error message to say “path” not “filename”.

Comment on lines 93 to 96
var logArgs []interface{}
for k, v := range respData {
logArgs = append(logArgs, k, v)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] What do you think of moving this to the Upload function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the logging belongs in the CLI layer; something else might want to do an Upload and get the response and log it in some other way (e.g. combined with some other information), or not at all.

I also think logging all the key/values in the response is too much (currently it's uuid and url and the latter contains the former)… if I change this to just log the upload URL from the response, then it'll be a one-line log call.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've simplified this.

func Upload(cfg Config, runEnv runEnvMap, format string, filename string) (map[string]string, error) {
body, err := buildUploadData(runEnv, format, filename)
if err != nil {
return nil, fmt.Errorf("Upload: %w", err)
Copy link
Contributor

@nprizal nprizal Mar 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We print upload: %v in main function already, so I think this is redundant. Maybe

Suggested change
return nil, fmt.Errorf("Upload: %w", err)
return nil, fmt.Errorf("building upload data: %w", err)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

Before:

2025/03/20 12:00:46 INFO Uploading key=0195b0a3-49bf-7812-af95-ff7ef0e6ff4d format=junit filename=test.xml
Buildkite Test Engine Client: upload: Upload: opening test.xml for reading: open test.xml: permission denied

After:

2025/03/20 12:00:46 INFO Uploading key=0195b0a3-49bf-7812-af95-ff7ef0e6ff4d format=junit filename=test.xml
Buildkite Test Engine Client: upload: preparing upload data: opening test.xml for reading: open test.xml: permission denied

Copy link
Contributor

@nprizal nprizal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rule them all

Base automatically changed from refactor-env to main March 25, 2025 07:15
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 this pull request may close these issues.

2 participants