move shared test logic into function