Skip to content

Commit

Permalink
Allow any set if flag sets in config is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Zamora committed Sep 27, 2023
1 parent 2d9a3a9 commit 925d552
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
29 changes: 29 additions & 0 deletions src/utils/settingsValidation/__tests__/splitFilters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,35 @@ describe('validateSplitFilters', () => {
expect(flagSetsAreValid(loggerMock, 'test_method', ['set_3'], flagSetsFilter)).toEqual([]);
expect(loggerMock.warn.mock.calls[7]).toEqual([WARN_FLAGSET_NOT_CONFIGURED, ['set_3']]);

// empty config


// must start with a letter or number
expect(flagSetsAreValid(loggerMock, 'test_method', ['_set_1'], [])).toEqual([]);
expect(loggerMock.warn.mock.calls[8]).toEqual([WARN_SPLITS_FILTER_INVALID_SET, ['_set_1', regexp, '_set_1']]);

// can contain _a-z0-9
expect(flagSetsAreValid(loggerMock, 'test_method', ['set*1'], [])).toEqual([]);
expect(loggerMock.warn.mock.calls[9]).toEqual([WARN_SPLITS_FILTER_INVALID_SET, ['set*1', regexp, 'set*1']]);

// have a max length of 50 characters
expect(flagSetsAreValid(loggerMock, 'test_method', [longName], [])).toEqual([]);
expect(loggerMock.warn.mock.calls[10]).toEqual([WARN_SPLITS_FILTER_INVALID_SET, [longName, regexp, longName]]);

// both set names invalid -> empty list & warn
expect(flagSetsAreValid(loggerMock, 'test_method', ['set*1','set*3'], [])).toEqual([]);
expect(loggerMock.warn.mock.calls[11]).toEqual([WARN_SPLITS_FILTER_INVALID_SET, ['set*1', regexp, 'set*1']]);
expect(loggerMock.warn.mock.calls[12]).toEqual([WARN_SPLITS_FILTER_INVALID_SET, ['set*3', regexp, 'set*3']]);

// only set_1 is valid => [set_1] & warn
expect(flagSetsAreValid(loggerMock, 'test_method', ['set_1','set*3'], [])).toEqual(['set_1']);
expect(loggerMock.warn.mock.calls[13]).toEqual([WARN_SPLITS_FILTER_INVALID_SET, ['set*3', regexp, 'set*3']]);

// any set should be returned if there isn't flag sets in filter
expect(flagSetsAreValid(loggerMock, 'test_method', ['set_1'], [])).toEqual(['set_1']);
expect(flagSetsAreValid(loggerMock, 'test_method', ['set_1','set_2'], [])).toEqual(['set_1','set_2']);
expect(flagSetsAreValid(loggerMock, 'test_method', ['set_3'], [])).toEqual(['set_3']);

});

});
17 changes: 10 additions & 7 deletions src/utils/settingsValidation/splitFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,15 @@ export function flagSetsAreValid(log: ILogger, method: string, flagSets: string[
}
const sets = validateSplits(log, flagSets, method, 'flag sets', 'flag set');
toReturn = sets ? sanitizeFlagSets(log, sets) : [];
return toReturn.filter(flagSet => {
if (flagSetsInConfig.indexOf(flagSet) > -1) {
return true;
}
log.warn(WARN_FLAGSET_NOT_CONFIGURED, [flagSet]);
return false;
});
if (flagSetsInConfig.length > 0) {
toReturn = toReturn.filter(flagSet => {
if (flagSetsInConfig.indexOf(flagSet) > -1) {
return true;
}
log.warn(WARN_FLAGSET_NOT_CONFIGURED, [flagSet]);
return false;
});
}

return toReturn;
}

0 comments on commit 925d552

Please sign in to comment.