ক্লাউড ফাংশন সহ Firebase টেস্ট ল্যাব প্রসারিত করুন


শুরু করতে, Firebase Test Lab ইভেন্টগুলি পরিচালনা করার জন্য প্রয়োজনীয় মডিউলগুলি আমদানি করুন:

Node.js পাইথন
 // The Cloud Functions for Firebase SDK to set up triggers and logging.
const {onTestMatrixCompleted} = require("firebase-functions/v2/testLab");
const {logger} = require("firebase-functions");
 # The Cloud Functions for Firebase SDK to set up triggers and logging.
from firebase_functions import test_lab_fn, params

# The requests library to send web requests to Slack.
import requests

TestMatrix সমাপ্তিতে একটি ফাংশন ট্রিগার করুন

একটি Firebase Test Lab ফাংশন ট্রিগার করতে, টেস্ট ম্যাট্রিক্স সমাপ্তির ইভেন্টের জন্য একটি হ্যান্ডলার সংজ্ঞায়িত করুন। এই উদাহরণে, ফাংশনটি পরীক্ষা সমাপ্তিতে ট্রিগার করে, ক্লাউড ইভেন্ট অবজেক্ট থেকে পরীক্ষার ম্যাট্রিক্স ডেটা পুনরুদ্ধার করে এবং একটি স্ল্যাক চ্যানেলে সংশ্লিষ্ট পরীক্ষার ফলাফল পাঠায়:

Node.js পাইথন
exports.posttestresultstoslack = onTestMatrixCompleted(
    {secrets: ["SLACK_WEBHOOK_URL"]},
    async (event) => {
    // Obtain Test Matrix properties from the CloudEvent
      const {testMatrixId, state, outcomeSummary} = event.data;

      // Create the title of the message
      const title = `${getSlackmoji(state)} ${getSlackmoji(
          outcomeSummary,
      )} ${testMatrixId}`;

      // Create the details of the message
      const details = `Status: *${state}* ${getSlackmoji(
          state,
      )}\nOutcome: *${outcomeSummary}* ${getSlackmoji(outcomeSummary)}
    `;

      // Post the message to slack
      const slackResponse = await postToSlack(title, details);

      // Log the response
      logger.log(slackResponse);
    });
@test_lab_fn.on_test_matrix_completed(secrets=["SLACK_WEBHOOK_URL"])
def posttestresultstoslack(
        event: test_lab_fn.CloudEvent[test_lab_fn.TestMatrixCompletedData]) -> None:
    """Posts a test matrix result to Slack."""

    # Obtain Test Matrix properties from the CloudEvent
    test_matrix_id = event.data.test_matrix_id
    state = event.data.state
    outcome_summary = event.data.outcome_summary

    # Create the title of the message
    title = f"{slackmoji(state)} {slackmoji(outcome_summary)} {test_matrix_id}"

    # Create the details of the message
    details = (f"Status: *{state}* {slackmoji(state)}\n"
               f"Outcome: *{outcome_summary}* {slackmoji(outcome_summary)}")

    # Post the message to Slack
    response = post_to_slack(title, details)

    # Log the response
    print(response.status_code, response.text)

ক্লায়েন্ট বিশদ অ্যাক্সেস করুন

পরীক্ষার ম্যাট্রিক্স বিভিন্ন উত্স বা কর্মপ্রবাহ থেকে তৈরি করা যেতে পারে। তাই প্রায়শই এমন ফাংশন তৈরি করা বাঞ্ছনীয় যা উত্স বা পরীক্ষার অন্যান্য গুরুত্বপূর্ণ প্রসঙ্গের উপর ভিত্তি করে বিভিন্ন ক্রিয়া সম্পাদন করে। এটিতে সাহায্য করার জন্য, gcloud আপনাকে একটি পরীক্ষা শুরু করার সময় নির্বিচারে তথ্য পাস করার অনুমতি দেয় যা আপনার ফাংশনে পরে অ্যাক্সেস করা যেতে পারে। যেমন:

gcloud beta firebase test android run \
    --app=path/to/app.apk \
    --client-details testType=pr,link=<path/to/pull-request>

এবং তারপরে আপনার ফাংশনে তথ্য অ্যাক্সেস করতে:

Node.js পাইথন
const testType = event.data.clientInfo.details.testType;
const link = event.data.clientInfo.details.link;
test_type: str | None = event.data.client_info.details.get("testType")
link: str | None = event.data.client_info.details.get("link")