test: extract common code to keep only important thing in test function