Skip to content

Update unit test's result messages#1812

Merged
Ekrekr merged 2 commits intodataform-co:mainfrom
spider-man-tm:update-unit-test
Sep 5, 2024
Merged

Update unit test's result messages#1812
Ekrekr merged 2 commits intodataform-co:mainfrom
spider-man-tm:update-unit-test

Conversation

@spider-man-tm
Copy link
Copy Markdown
Contributor

@spider-man-tm spider-man-tm commented Aug 16, 2024

This PR is linked to the following issue:

close #1791

Current

Prepare the following table and its corresponding unit test.

Test table:

config {
    type: "table",
    schema: "hoge",
    name: "fuga"
}

select
  user_id
from
  ${ref("users")}

Test code:

config {
  type: "test",
  dataset: "fuga",
}

select 1 as user_id union all
select cast(null as int64) as user_id

input "users" {
  select 1 as user_id union all
  select 2 as user_id
}

Given that the expected block includes cast(null as int64), it would be more user-friendly to have the output display as follows:

For row 1 and column "user_id": expected null, but saw "2"

However, the current output is as follows, which can cause confusion for the user:

For row 1 and column "user_id": expected type "object", but saw type "number".

Before Committing

  • Conducted unit testing
  • Checked the behavior of dataform cli

@google-cla
Copy link
Copy Markdown

google-cla bot commented Aug 16, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Comment on lines +86 to +94
// Check if exactly one of the expected or actual values is null (XOR condition)
if ((expectedValue === null) !== (actualValue === null)) {
const expectedText = expectedValue === null ? 'null' : `"${expectedValue}"`;
const actualText = actualValue === null ? 'null' : `"${actualValue}"`;
rowMessages.push(
`For row ${i} and column "${column}": expected ${expectedText}, but saw ${actualText}.`
);
break;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I much preferred your suggestion of

      // Null value check
      if (expectedValue === null && actualValue !== null) {
        rowMessages.push(
          `For row ${i} and column "${column}": expected null, but saw "${actualValue}".`
        );
        break;
      }
      if (expectedValue !== null && actualValue === null) {
        rowMessages.push(
          `For row ${i} and column "${column}": expected "${expectedValue}", but saw null.`
        );
        break;
      }

This is much clearer to follow the logic of!

Copy link
Copy Markdown
Contributor Author

@spider-man-tm spider-man-tm Aug 16, 2024

Choose a reason for hiding this comment

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

You're right, I also think that keeping it simple makes it easier to understand. I've committed.
d40e265

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Ekrekr
Is there a plan to merge this PR?

@spider-man-tm spider-man-tm requested a review from Ekrekr August 16, 2024 15:47
@Ekrekr
Copy link
Copy Markdown
Contributor

Ekrekr commented Sep 5, 2024

I've run the tests, and all pass. Will merge, thanks for doing this!

@Ekrekr Ekrekr merged commit b309aa0 into dataform-co:main Sep 5, 2024
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.

About error messages during unit tests

2 participants