You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by al...@apache.org on 2016/08/13 01:46:08 UTC

[4/6] mesos git commit: Added a test for `HealthCheck` protobuf validation.

Added a test for `HealthCheck` protobuf validation.


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/23aa2f44
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/23aa2f44
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/23aa2f44

Branch: refs/heads/master
Commit: 23aa2f445c7a19dba9d7f8f1211f7a8802284440
Parents: 72efadf
Author: Alexander Rukletsov <al...@apache.org>
Authored: Sat Aug 13 02:59:11 2016 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Sat Aug 13 03:43:19 2016 +0200

----------------------------------------------------------------------
 src/tests/health_check_tests.cpp | 68 +++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/23aa2f44/src/tests/health_check_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/health_check_tests.cpp b/src/tests/health_check_tests.cpp
index 2680274..9de8563 100644
--- a/src/tests/health_check_tests.cpp
+++ b/src/tests/health_check_tests.cpp
@@ -24,6 +24,8 @@
 
 #include "docker/docker.hpp"
 
+#include "health-check/health_checker.hpp"
+
 #include "slave/slave.hpp"
 
 #include "slave/containerizer/docker.hpp"
@@ -159,6 +161,72 @@ public:
 };
 
 
+// This tests ensures `HealthCheck` protobuf is validated correctly.
+TEST_F(HealthCheckTest, HealthCheckProtobufValidation)
+{
+  using namespace mesos::internal;
+
+  // Health check type must be set to a known value.
+  {
+    HealthCheck healthCheckProto;
+
+    Option<Error> validate = validation::healthCheck(healthCheckProto);
+    EXPECT_SOME(validate);
+
+    healthCheckProto.set_type(HealthCheck::UNKNOWN);
+    validate = validation::healthCheck(healthCheckProto);
+    EXPECT_SOME(validate);
+  }
+
+  // The associated with the type health description must be present.
+  {
+    HealthCheck healthCheckProto;
+
+    healthCheckProto.set_type(HealthCheck::COMMAND);
+    Option<Error> validate = validation::healthCheck(healthCheckProto);
+    EXPECT_SOME(validate);
+
+    healthCheckProto.set_type(HealthCheck::HTTP);
+    validate = validation::healthCheck(healthCheckProto);
+    EXPECT_SOME(validate);
+
+    healthCheckProto.set_type(HealthCheck::TCP);
+    validate = validation::healthCheck(healthCheckProto);
+    EXPECT_SOME(validate);
+  }
+
+  // Command health check must specify an actual command in `command.value`.
+  {
+    HealthCheck healthCheckProto;
+
+    healthCheckProto.set_type(HealthCheck::COMMAND);
+    healthCheckProto.mutable_command()->CopyFrom(CommandInfo());
+    Option<Error> validate = validation::healthCheck(healthCheckProto);
+    EXPECT_SOME(validate);
+  }
+
+  // HTTP health check may specify a known scheme and a path starting with '/'.
+  {
+    HealthCheck healthCheckProto;
+
+    healthCheckProto.set_type(HealthCheck::HTTP);
+    healthCheckProto.mutable_http()->set_port(8080);
+
+    Option<Error> validate = validation::healthCheck(healthCheckProto);
+    EXPECT_NONE(validate);
+
+    healthCheckProto.mutable_http()->set_scheme("ftp");
+    validate = validation::healthCheck(healthCheckProto);
+    EXPECT_SOME(validate);
+
+    healthCheckProto.mutable_http()->set_scheme("https");
+    healthCheckProto.mutable_http()->set_path("healthz");
+    validate = validation::healthCheck(healthCheckProto);
+    EXPECT_SOME(validate);
+  }
+}
+
+
 // Testing a healthy task reporting one healthy status to scheduler.
 TEST_F(HealthCheckTest, HealthyTask)
 {