Repository navigation
Expand file tree
/
Copy pathasync_test.cpp
More file actions
74 lines (59 loc) · 2.01 KB
/
Copy pathasync_test.cpp
File metadata and controls
74 lines (59 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2026 Bontal LLC
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
#include <gtest/gtest.h>
#include <future>
#include <memory>
#include "typesafe/client.h"
#include "typesafe/testing.h"
namespace
{
using namespace typesafe;
using typesafe::testing::BasicRequest;
using typesafe::testing::ModelsResponse;
using typesafe::testing::RecordingTransport;
using typesafe::testing::ValidResponse;
TEST(AsyncTest, ReturnsTheParsedResponse)
{
auto transport = std::make_unique<RecordingTransport>();
transport->responses.push_back(
ValidResponse({{"safe", {{"type", "noul"}, {"noul", 0.75}}}}));
auto client = TypeSafeClient::builder()
.api_key("test-key")
.transport(std::move(transport))
.build();
EXPECT_DOUBLE_EQ(
client.systemOneAsync(BasicRequest()).get().nouls.at("safe").noul,
0.75);
}
TEST(AsyncTest, TheFutureOutlivesTheClientThatMadeIt)
{
std::future<SystemOneResponse> future;
{
auto transport = std::make_unique<RecordingTransport>();
transport->delay = true;
transport->responses.push_back(
ValidResponse({{"safe", {{"type", "noul"}, {"noul", 0.75}}}}));
auto client = TypeSafeClient::builder()
.api_key("test-key")
.transport(std::move(transport))
.build();
future = client.systemOneAsync(BasicRequest());
}
EXPECT_DOUBLE_EQ(future.get().nouls.at("safe").noul, 0.75);
}
TEST(ListModelsAsyncTest, ReturnsTheParsedList)
{
auto transport = std::make_unique<RecordingTransport>();
transport->responses.push_back(ModelsResponse());
auto client = TypeSafeClient::builder()
.api_key("test-key")
.transport(std::move(transport))
.build();
const ListModelsResponse listed = client.listModelsAsync().get();
ASSERT_EQ(listed.models.size(), 2u);
EXPECT_EQ(listed.models.front().name, "jev-latest");
}
} // namespace