Skip to content

When iterating a data file, loop back to the beginning...#1218

Open
ThePieBandit wants to merge 1 commit intopostmanlabs:developfrom
ThePieBandit:develop
Open

When iterating a data file, loop back to the beginning...#1218
ThePieBandit wants to merge 1 commit intopostmanlabs:developfrom
ThePieBandit:develop

Conversation

@ThePieBandit
Copy link
Copy Markdown

rather than repeat the last element. For example, take the following data file:

[
    {"inputData":"foo"},
    {"inputData":"bar"}
]

If I were to run a collection with the following GET API: https://postman-echo.com/get?foo1={{inputData}} using the runner, several things happen:

  1. When uploading the data file, it sets the iteration count to the length of the data array, in this case, 2.
  2. If the collection is run like that, it will run once with foo and once with bar.
  3. After setting the data file, the iteration count can be changed. This can be useful for data seeding into an environment. For example, it can be set to 5.

the current behavior is to run once with foo and 4 times with bar. For data seeding, this is not ideal. this enhancement causes the iteration count, if greater than the number of rows in the data, to return to the first index of the data file and continue to invoke the APIs in the collection.

image

@ThePieBandit
Copy link
Copy Markdown
Author

Note: I tried to write a test, but was unsuccessful. I wasn't sure how I could just unit test the getIterationData method without exposing it. I tried

var expect = require('chai').expect,
    Waterfall = require('../../lib/runner/extensions/waterfall.command.js');

describe('runner extensions', function () {
    describe('Waterfall', function () {

        describe('getIterationData', function () {
            describe('when iteration count is less than the size of the data', function () {
                it('should return the index of the data', function () {
                    var data = [
                        { a: 'b' },
                        { c: 'd' },
                        { e: 'f' }
                    ];

                    expect(Waterfall.getIterationData(data, 1)).to.eql({ c: 'd' });
                });
            });
            describe('when iteration count is more than the size of the data', function () {
                it('should loop back around to the beginning of the data', function () {
                    var data = [
                        { a: 'b' },
                        { c: 'd' },
                        { e: 'f' }
                    ];

                    expect(Waterfall.getIterationData(data, 2)).to.eql({ e: 'f' });
                    expect(Waterfall.getIterationData(data, 3)).to.eql({ a: 'b' });
                    expect(Waterfall.getIterationData(data, 5)).to.eql({ e: 'f' });
                    expect(Waterfall.getIterationData(data, 7)).to.eql({ c: 'd' });
                });
            });
        });
    });
});

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 29, 2022

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.56%. Comparing base (946ee96) to head (f420be6).
⚠️ Report is 269 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1218      +/-   ##
===========================================
- Coverage    79.57%   79.56%   -0.02%     
===========================================
  Files           42       42              
  Lines         2972     2970       -2     
  Branches       856      855       -1     
===========================================
- Hits          2365     2363       -2     
  Misses         607      607              
Flag Coverage Δ
integration 69.46% <100.00%> (-0.03%) ⬇️
legacy 48.48% <100.00%> (-0.04%) ⬇️
unit 43.26% <0.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant