This test tests the functionality of the docker's interfaces.
| 141 | |
| 142 | // This test tests the functionality of the docker's interfaces. |
| 143 | TEST_F(DockerTest, ROOT_DOCKER_interface) |
| 144 | { |
| 145 | const string containerName = NAME_PREFIX + "-test"; |
| 146 | Resources resources = Resources::parse("cpus:1;mem:512").get(); |
| 147 | |
| 148 | Owned<Docker> docker = Docker::create( |
| 149 | tests::flags.docker, |
| 150 | tests::flags.docker_socket, |
| 151 | false).get(); |
| 152 | |
| 153 | // Verify that we do not see the container. |
| 154 | Future<vector<Docker::Container>> containers = |
| 155 | docker->ps(true, containerName); |
| 156 | AWAIT_READY(containers); |
| 157 | |
| 158 | foreach (const Docker::Container& container, containers.get()) { |
| 159 | EXPECT_NE("/" + containerName, container.name); |
| 160 | } |
| 161 | |
| 162 | Try<string> directory = environment->mkdtemp(); |
| 163 | ASSERT_SOME(directory); |
| 164 | |
| 165 | ContainerInfo containerInfo; |
| 166 | containerInfo.set_type(ContainerInfo::DOCKER); |
| 167 | |
| 168 | ContainerInfo::DockerInfo dockerInfo; |
| 169 | dockerInfo.set_image(DOCKER_TEST_IMAGE); |
| 170 | |
| 171 | containerInfo.mutable_docker()->CopyFrom(dockerInfo); |
| 172 | |
| 173 | CommandInfo commandInfo; |
| 174 | commandInfo.set_value(SLEEP_COMMAND(120)); |
| 175 | |
| 176 | Try<Docker::RunOptions> runOptions = Docker::RunOptions::create( |
| 177 | containerInfo, |
| 178 | commandInfo, |
| 179 | containerName, |
| 180 | directory.get(), |
| 181 | DOCKER_MAPPED_DIR_PATH, |
| 182 | resources); |
| 183 | |
| 184 | ASSERT_SOME(runOptions); |
| 185 | |
| 186 | // Start the container. |
| 187 | Future<Option<int>> status = docker->run(runOptions.get()); |
| 188 | |
| 189 | Future<Docker::Container> inspect = |
| 190 | docker->inspect(containerName, Seconds(1)); |
| 191 | |
| 192 | AWAIT_READY(inspect); |
| 193 | |
| 194 | // Should be able to see the container now. |
| 195 | containers = docker->ps(); |
| 196 | AWAIT_READY(containers); |
| 197 | bool found = false; |
| 198 | foreach (const Docker::Container& container, containers.get()) { |
| 199 | if ("/" + containerName == container.name) { |
| 200 | found = true; |
nothing calls this directly
no test coverage detected