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

Tests fail with realistic inputs #312

Closed
misterikkit opened this issue Feb 24, 2023 · 2 comments
Closed

Tests fail with realistic inputs #312

misterikkit opened this issue Feb 24, 2023 · 2 comments
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity, has become stale and will be auto-closed. question Further information is requested

Comments

@misterikkit
Copy link

I tried to add some tests to some working filters, and the tests consistently fail. I was able to reduce it to a minimal config that reproduces the problem. The filters are matching specific "noreply" addresses, but these services often include someone's display name, e.g. From: "Michele Bertasi (Google Docs)" <comments-noreply@docs.google.com>

I assumed the best test would be one that has a real from header in the from field, but the rule is not matching in gmailctl test.

$ gmailctl version
0.10.6

My config

// Import the standard library
local lib = import 'gmailctl.libsonnet';

// Some useful variables on top
// TODO: Put your email here
local me = 'YOUR.EMAIL@gmail.com';
local toMe = { to: me };


// The actual configuration
{
  // Mandatory header
  version: 'v1alpha3',
  author: {
    name: 'YOUR NAME HERE',
    email: me,
  },

  rules: [
    {
      filter: {
        or: [
          { from: 'noreply+foo@example.com' },
          { from: 'noreply@foo.dev.example.com' },
        ],
      },
      actions: {
        labels: ['foo'],
      },
    },
  ],
  tests: [
    {
      name: 'test the test',
      messages: [
        { from: '"Person One" <noreply@foo.dev.example.com>' },
        { from: '"Person Two" <noreply+foo@example.com>' },
      ],
      actions: {
        labels: ['foo'],
      },
    },
  ],
}

Expected: gmailctl test should pass
Actual:

$ gmailctl --config . test
Test results: Failed: 1/1

Failed test "test the test":
multiple errors (2):
- message #0 is going to get unexpected actions: {}
  Note:
  - Message: {
      "from": "\"Person One\" \u003cnoreply@foo.dev.example.com\u003e"
    }
  - Actions:
    --- want
    +++ got
    @@ -1,5 +1 @@
    -{
    -  "labels": [
    -    "foo"
    -  ]
    -}
    +{}
- message #1 is going to get unexpected actions: {}
  Note:
  - Message: {
      "from": "\"Person Two\" \u003cnoreply+foo@example.com\u003e"
    }
  - Actions:
    --- want
    +++ got
    @@ -1,5 +1 @@
    -{
    -  "labels": [
    -    "foo"
    -  ]
    -}
    +{}

Error: 1/1 config tests failed
@mbrt
Copy link
Owner

mbrt commented Mar 3, 2023

Just out of curiosity, why not using the email only instead of the full name + email?

noreply@foo.dev.example.com instead of "Person One" <noreply@foo.dev.example.com>.

gmailctl doesn't parse the address and just uses a simple string comparison.

@mbrt mbrt added the question Further information is requested label Mar 3, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Apr 3, 2023

This issue is stale because it has been open for 30 days without activity.
This will be closed in 7 days, unless you add the 'lifecycle/keep-alive' label or comment.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity, has become stale and will be auto-closed. label Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity, has become stale and will be auto-closed. question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants