|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.elasticsearch.gradle; |
| 20 | + |
| 21 | +import java.io.File; |
| 22 | +import java.io.IOException; |
| 23 | + |
| 24 | +import org.elasticsearch.gradle.test.GradleUnitTestCase; |
| 25 | +import org.gradle.api.Project; |
| 26 | +import org.gradle.testfixtures.ProjectBuilder; |
| 27 | + |
| 28 | +public class EmptyDirTaskTests extends GradleUnitTestCase { |
| 29 | + |
| 30 | + public void testCreateEmptyDir() throws Exception { |
| 31 | + Project project = ProjectBuilder.builder().build(); |
| 32 | + EmptyDirTask emptyDirTask = project.getTasks().create("emptyDirTask", EmptyDirTask.class); |
| 33 | + assertEquals(0755, emptyDirTask.getDirMode()); |
| 34 | + |
| 35 | + // generate a new temporary folder and make sure it does not exists |
| 36 | + File newEmptyFolder = getNewNonExistingTempFolderFile(project); |
| 37 | + |
| 38 | + emptyDirTask.setDir(newEmptyFolder); |
| 39 | + emptyDirTask.create(); |
| 40 | + |
| 41 | + assertTrue(newEmptyFolder.exists()); |
| 42 | + assertTrue(newEmptyFolder.isDirectory()); |
| 43 | + assertTrue(newEmptyFolder.canExecute()); |
| 44 | + assertTrue(newEmptyFolder.canRead()); |
| 45 | + assertTrue(newEmptyFolder.canWrite()); |
| 46 | + |
| 47 | + // cleanup |
| 48 | + newEmptyFolder.delete(); |
| 49 | + } |
| 50 | + |
| 51 | + public void testCreateEmptyDirNoPermissions() throws Exception { |
| 52 | + Project project = ProjectBuilder.builder().build(); |
| 53 | + EmptyDirTask emptyDirTask = project.getTasks().create("emptyDirTask", EmptyDirTask.class); |
| 54 | + emptyDirTask.setDirMode(0000); |
| 55 | + |
| 56 | + // generate a new temporary folder and make sure it does not exists |
| 57 | + File newEmptyFolder = getNewNonExistingTempFolderFile(project); |
| 58 | + |
| 59 | + emptyDirTask.setDir(newEmptyFolder); |
| 60 | + emptyDirTask.create(); |
| 61 | + |
| 62 | + assertTrue(newEmptyFolder.exists()); |
| 63 | + assertTrue(newEmptyFolder.isDirectory()); |
| 64 | + assertFalse(newEmptyFolder.canExecute()); |
| 65 | + assertFalse(newEmptyFolder.canRead()); |
| 66 | + assertFalse(newEmptyFolder.canWrite()); |
| 67 | + |
| 68 | + // cleanup |
| 69 | + newEmptyFolder.delete(); |
| 70 | + } |
| 71 | + |
| 72 | + private File getNewNonExistingTempFolderFile(Project project) throws IOException { |
| 73 | + File newEmptyFolder = new File(project.getBuildDir(), "empty-dir"); |
| 74 | + assertFalse(newEmptyFolder.exists()); |
| 75 | + return newEmptyFolder; |
| 76 | + } |
| 77 | + |
| 78 | +} |
0 commit comments