about summary refs log tree commit diff
path: root/third_party/nix/src/tests
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2020-11-28T00·24-0500
committerglittershark <grfn@gws.fyi>2020-11-28T00·47+0000
commit6f38ac6657cabcee067a6299551d280680be16ff (patch)
tree6da8f6990253bf59b1bee706b71a3bb3a008e191 /third_party/nix/src/tests
parent49024be05644d4fac252e2191e9de74e0ffd4fe3 (diff)
fix(tvix): Add missing break;s to BuildResult::FromProto r/1947
Add missing break statements to the big switch block in
BuildResult::FromProto, and cover the whole thing with a rapidcheck
round-trip test.

Change-Id: I7a07ca398cc5f02ca4fd8e6256fd563c6f3aea9d
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2178
Tested-by: BuildkiteCI
Reviewed-by: kanepyork <rikingcoding@gmail.com>
Diffstat (limited to 'third_party/nix/src/tests')
-rw-r--r--third_party/nix/src/tests/CMakeLists.txt10
-rw-r--r--third_party/nix/src/tests/store-api-test.cc49
2 files changed, 59 insertions, 0 deletions
diff --git a/third_party/nix/src/tests/CMakeLists.txt b/third_party/nix/src/tests/CMakeLists.txt
index cda8f5da8483..f8158d06c306 100644
--- a/third_party/nix/src/tests/CMakeLists.txt
+++ b/third_party/nix/src/tests/CMakeLists.txt
@@ -66,3 +66,13 @@ target_link_libraries(language-tests
 )
 
 gtest_discover_tests(language-tests)
+
+add_executable(store-api-test store-api-test.cc)
+target_link_libraries(store-api-test
+  nixstore
+  rapidcheck
+  rapidcheck_gtest
+  GTest::gtest_main
+)
+
+gtest_discover_tests(store-api-test)
diff --git a/third_party/nix/src/tests/store-api-test.cc b/third_party/nix/src/tests/store-api-test.cc
new file mode 100644
index 000000000000..515613b799ee
--- /dev/null
+++ b/third_party/nix/src/tests/store-api-test.cc
@@ -0,0 +1,49 @@
+#include "libstore/store-api.hh"
+
+#include <gtest/gtest.h>
+#include <rapidcheck/Assertions.h>
+#include <rapidcheck/Gen.h>
+#include <rapidcheck/gtest.h>
+
+#include "libproto/worker.pb.h"
+
+namespace rc {
+template <>
+struct Arbitrary<nix::BuildResult::Status> {
+  static Gen<nix::BuildResult::Status> arbitrary() {
+    return gen::element(nix::BuildResult::Status::Built,
+                        nix::BuildResult::Status::Substituted,
+                        nix::BuildResult::Status::AlreadyValid,
+                        nix::BuildResult::Status::PermanentFailure,
+                        nix::BuildResult::Status::InputRejected,
+                        nix::BuildResult::Status::OutputRejected,
+                        nix::BuildResult::Status::TransientFailure,
+                        nix::BuildResult::Status::CachedFailure,
+                        nix::BuildResult::Status::TimedOut,
+                        nix::BuildResult::Status::MiscFailure,
+                        nix::BuildResult::Status::DependencyFailed,
+                        nix::BuildResult::Status::LogLimitExceeded,
+                        nix::BuildResult::Status::NotDeterministic);
+  }
+};
+}  // namespace rc
+
+namespace nix {
+
+class BuildResultTest : public ::testing::Test {};
+
+RC_GTEST_PROP(BuildResultTest, StatusToFromProtoRoundTrip,
+              (BuildResult::Status && status)) {
+  BuildResult br;
+  br.status = status;
+
+  auto proto_status = br.status_to_proto();
+  nix::proto::BuildResult br_proto;
+  br_proto.set_status(proto_status);
+
+  auto result = BuildResult::FromProto(br_proto);
+
+  RC_ASSERT(result.value().status == status);
+}
+
+}  // namespace nix