Skip to content

Commit 8979e90

Browse files
committed
Add minimal test for AndroidBuildApi
Exercises FileReader directly using FakeHttpClient and verifies that the download URL fetch targets the correct V4 API endpoint. Assisted-by: Jetski:Gemini Next
1 parent 47e6453 commit 8979e90

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

base/cvd/cuttlefish/host/libs/web/BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@ cf_cc_test(
8383
],
8484
)
8585

86+
cf_cc_test(
87+
name = "android_build_api_test",
88+
srcs = ["android_build_api_test.cpp"],
89+
deps = [
90+
"//cuttlefish/host/libs/web:android_build",
91+
"//cuttlefish/host/libs/web:android_build_api",
92+
"//cuttlefish/host/libs/web:android_build_url",
93+
"//cuttlefish/host/libs/web/http_client",
94+
"//cuttlefish/host/libs/web/http_client:fake_http_client",
95+
"//cuttlefish/host/libs/zip/libzip_cc:seekable_source",
96+
"//cuttlefish/result",
97+
"//cuttlefish/result:result_matchers",
98+
],
99+
)
100+
86101
cf_cc_library(
87102
name = "android_build_url",
88103
srcs = ["android_build_url.cpp"],
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//
2+
// Copyright (C) 2026 The Android Open Source Project
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#include "cuttlefish/host/libs/web/android_build_api.h"
17+
18+
#include <string>
19+
20+
#include "gmock/gmock.h"
21+
#include "gtest/gtest.h"
22+
23+
#include "cuttlefish/host/libs/web/android_build.h"
24+
#include "cuttlefish/host/libs/web/android_build_url.h"
25+
#include "cuttlefish/host/libs/web/http_client/fake_http_client.h"
26+
#include "cuttlefish/host/libs/web/http_client/http_client.h"
27+
#include "cuttlefish/host/libs/zip/libzip_cc/seekable_source.h"
28+
#include "cuttlefish/result/result.h"
29+
#include "cuttlefish/result/result_matchers.h"
30+
31+
namespace cuttlefish {
32+
namespace {
33+
34+
TEST(AndroidBuildApiTest, FileReader) {
35+
FakeHttpClient http_client;
36+
AndroidBuildUrl build_url("https://androidbuild-pa.googleapis.com/v4", "",
37+
"");
38+
AndroidBuildApi api(http_client, build_url);
39+
40+
http_client.SetResponse("{\"signedUrl\": \"http://zip-url\"}", "/url");
41+
42+
HttpResponse<std::string> res = {
43+
.data = "abc",
44+
.http_code = 200,
45+
.headers =
46+
{
47+
{"accept-ranges", "bytes"},
48+
{"content-length", "3"},
49+
},
50+
};
51+
http_client.SetResponse(res, "http://zip-url");
52+
53+
Build build = DeviceBuild{.id = "123", .target = "test"};
54+
Result<SeekableZipSource> source = api.FileReader(build, "a.zip");
55+
ASSERT_THAT(source, IsOk());
56+
57+
Result<SeekingZipSourceReader> reader = source->Reader();
58+
ASSERT_THAT(reader, IsOk());
59+
60+
char buf[4] = {};
61+
ASSERT_THAT(reader->Read(buf, 3), IsOkAndValue(3));
62+
EXPECT_STREQ(buf, "abc");
63+
64+
EXPECT_TRUE(http_client.RequestMade(
65+
"https://androidbuild-pa.googleapis.com/v4/builds/123/test/attempts/"
66+
"latest/artifacts/a.zip/url"));
67+
}
68+
69+
} // namespace
70+
} // namespace cuttlefish

0 commit comments

Comments
 (0)