blob: 268a884e232881d9628358c461ddfd5f399a4837 [file] [log] [blame]
# Copyright 2020 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import base64
from google.protobuf import text_format as textpb
from recipe_engine import recipe_test_api
class LuciConfigTestApi(recipe_test_api.RecipeTestApi):
def mock_config(self, config_name, data):
"""Mock a config returned by the luci-config API.
Args:
config_name (str): The name of the config file to mock, e.g.
"commit-queue.cfg".
data (str or protobuf): The mock data that should be returned.
Either a string containing a textproto, or a protobuf object.
"""
if not isinstance(data, str):
data = textpb.MessageToString(data)
response = {"content": base64.b64encode(data)}
return self.m.url.json("fetch %s.get" % config_name, response)