Dan Willemsen | 29f8827 | 2017-02-18 18:12:41 -0800 | [diff] [blame] | 1 | // Copyright 2017 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package build |
| 16 | |
Dan Willemsen | fe8b645 | 2018-05-12 18:34:24 -0700 | [diff] [blame] | 17 | import ( |
| 18 | "io/ioutil" |
| 19 | "os" |
| 20 | "path/filepath" |
| 21 | "testing" |
| 22 | |
| 23 | "android/soong/ui/logger" |
| 24 | ) |
| 25 | |
| 26 | func TestEnsureEmptyDirs(t *testing.T) { |
| 27 | ctx := testContext() |
| 28 | defer logger.Recover(func(err error) { |
| 29 | t.Error(err) |
| 30 | }) |
| 31 | |
| 32 | tmpDir, err := ioutil.TempDir("", "") |
| 33 | if err != nil { |
| 34 | t.Fatal(err) |
| 35 | } |
| 36 | defer func() { |
| 37 | err := os.RemoveAll(tmpDir) |
| 38 | if err != nil { |
| 39 | t.Errorf("Error removing tmpDir: %v", err) |
| 40 | } |
| 41 | }() |
| 42 | |
| 43 | ensureEmptyDirectoriesExist(ctx, filepath.Join(tmpDir, "a/b")) |
| 44 | |
| 45 | err = os.Chmod(filepath.Join(tmpDir, "a"), 0555) |
| 46 | if err != nil { |
| 47 | t.Fatalf("Failed to chown: %v", err) |
| 48 | } |
| 49 | |
| 50 | ensureEmptyDirectoriesExist(ctx, filepath.Join(tmpDir, "a")) |
| 51 | } |