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

Tags do not apply to included files #164

Closed
michaelsproul opened this issue Feb 1, 2023 · 2 comments
Closed

Tags do not apply to included files #164

michaelsproul opened this issue Feb 1, 2023 · 2 comments

Comments

@michaelsproul
Copy link

I tried defining a top-level file to combine requests from multiple files like this:

# all.yaml
---
base: "http://localhost:3000"
plan:
  - include: ./file1.yaml
  - include: ./file2.yaml
# file1.yaml
---
- name: is_tagged
  request:
    url: /is_tagged
  tags: [example1]
# file1.yaml
---
- name: is_not_tagged
  request:
    url: /is_not_tagged

I found that tags in file1.yaml and file2.yaml are ignored. Running with --tags example1 doesn't include the is_tagged action from file1.yaml (it includes nothing).

I had a play with the code and it's because the tag system operates on the unexpanded YAML and expects tags on top-level items only, here:

drill/src/tags.rs

Lines 29 to 55 in f7627bf

pub fn should_skip_item(&self, item: &Yaml) -> bool {
match item["tags"].as_vec() {
Some(item_tags_raw) => {
let item_tags: HashSet<&str> = item_tags_raw.iter().map(|t| t.as_str().unwrap()).collect();
if let Some(s) = &self.skip_tags {
if !s.is_disjoint(&item_tags) {
return true;
}
}
if let Some(t) = &self.tags {
if item_tags.contains("never") && !t.contains("never") {
return true;
}
if !t.is_disjoint(&item_tags) {
return false;
}
}
if item_tags.contains("always") {
return false;
}
if item_tags.contains("never") {
return true;
}
self.tags.is_some()
}
None => self.tags.is_some(),
}

As a workaround I'm grouping my include files by their tags like this:

# all.yaml
plan:
  - include: ./file1.yaml
    tags: [example1]
  - include: ./file2.yaml

Figured I would document this here so that this behaviour is known. If we wanted to codify it maybe tags on included files could be rejected when loading/parsing? Alternatively, the tag system could be extended to work with recursively included files.

Related: #132

@fcsonline
Copy link
Owner

Thanks for this report! I vote for the recursive approach because it's the most intuitive one. I can work on a fix.

fcsonline added a commit that referenced this issue Feb 1, 2023
It seems that items that were included with the `include` directive and
contains tags, they are ignored.

Trying to fix this.

Issue:
#164
@fcsonline
Copy link
Owner

Not able to battle test this changes but I think it fixes the issue. It would be awesome to add some tests for it.
#167

fcsonline added a commit that referenced this issue Feb 1, 2023
It seems that items that were included with the `include` directive and
contains tags, they are ignored.

Trying to fix this.

Issue:
#164
fcsonline added a commit that referenced this issue Feb 6, 2023
It seems that items that were included with the `include` directive and
contains tags, they are ignored.

Trying to fix this.

Issue:
#164
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

No branches or pull requests

2 participants