src/tests/persistent_volume_endpoints_tests.cpp
// This tests that an attempt to create or destroy a volume with no
// 'slaveId' results in a 'BadRequest' HTTP error.
This tests that an attempt to create or destroy a volume with no
'slaveId' results in a 'BadRequest' HTTP error.
This tests that an attempt to create or destroy a volume with no ' slaveId ' results in a ' BadRequest ' HTTP error .
TEST_F(PersistentVolumeEndpointsTest, NoSlaveId)
{
  TestAllocator<> allocator;
  EXPECT_CALL(allocator, initialize(_, _, _, _));
  Try<Owned<cluster::Master>> master = StartMaster(&allocator);
  ASSERT_SOME(master);
  slave::Flags slaveFlags = CreateSlaveFlags();
  slaveFlags.resources = "disk(role1):1024";
  Future<SlaveID> slaveId;
  EXPECT_CALL(allocator, addSlave(_, _, _, _, _))
    .WillOnce(DoAll(InvokeAddSlave(&allocator),
                    FutureArg<0>(&slaveId)));
  Owned<MasterDetector> detector = master.get()->createDetector();
  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), slaveFlags);
  ASSERT_SOME(slave);
  Resources volume = createPersistentVolume(
      Megabytes(64),
      "role1",
      "id1",
      "path1");
  process::http::Headers headers = createBasicAuthHeaders(DEFAULT_CREDENTIAL);
  string body =
    "volumes=" +
    stringify(JSON::protobuf(
        static_cast<const RepeatedPtrField<Resource>&>(volume)));
  Future<Response> response =
    process::http::post(master.get()->pid, "create-volumes", headers, body);
  AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response);
  response = process::http::post(
      master.get()->pid,
      "create-volumes",
      createBasicAuthHeaders(DEFAULT_CREDENTIAL),
      createRequestBody(slaveId.get(), "volumes", volume));
  AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response);
  response =
    process::http::post(master.get()->pid, "destroy-volumes", headers, body);
  AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response);
}
TEST_F ( PersistentVolumeEndpointsTest , NoSlaveId ) { TestAllocator < > allocator ; EXPECT_CALL ( allocator , initialize ( _ , _ , _ , _ ) ) ; Try < Owned < cluster :: Master > > master = StartMaster ( & allocator ) ; ASSERT_SOME ( master ) ; slave :: Flags slaveFlags = CreateSlaveFlags ( ) ; slaveFlags . resources = " " ; Future < SlaveID > slaveId ; EXPECT_CALL ( allocator , addSlave ( _ , _ , _ , _ , _ ) ) . WillOnce ( DoAll ( InvokeAddSlave ( & allocator ) , FutureArg < 0 > ( & slaveId ) ) ) ; Owned < MasterDetector > detector = master . get ( ) -> createDetector ( ) ; Try < Owned < cluster :: Slave > > slave = StartSlave ( detector . get ( ) , slaveFlags ) ; ASSERT_SOME ( slave ) ; Resources volume = createPersistentVolume ( Megabytes ( 64 ) , " " , " " , " " ) ; process :: http :: Headers headers = createBasicAuthHeaders ( DEFAULT_CREDENTIAL ) ; string body = " " + stringify ( JSON :: protobuf ( static_cast < const RepeatedPtrField < Resource > & > ( volume ) ) ) ; Future < Response > response = process :: http :: post ( master . get ( ) -> pid , " " , headers , body ) ; AWAIT_EXPECT_RESPONSE_STATUS_EQ ( BadRequest ( ) . status , response ) ; response = process :: http :: post ( master . get ( ) -> pid , " " , createBasicAuthHeaders ( DEFAULT_CREDENTIAL ) , createRequestBody ( slaveId . get ( ) , " " , volume ) ) ; AWAIT_EXPECT_RESPONSE_STATUS_EQ ( OK ( ) . status , response ) ; response = process :: http :: post ( master . get ( ) -> pid , " " , headers , body ) ; AWAIT_EXPECT_RESPONSE_STATUS_EQ ( BadRequest ( ) . status , response ) ; }
This tests that an attempt to create or destroy a volume with no
'slaveId' results in a 'BadRequest' HTTP error.
This tests that an attempt to create or destroy a volume with no ' slaveId ' results in a ' BadRequest ' HTTP error .
// Create a volume so that a well-formed destroy attempt would succeed.