Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 1 | // Copyright 2021 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 | package android |
| 15 | |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame^] | 16 | import ( |
| 17 | "android/soong/android/allowlists" |
| 18 | "testing" |
| 19 | ) |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 20 | |
| 21 | func TestConvertAllModulesInPackage(t *testing.T) { |
| 22 | testCases := []struct { |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame^] | 23 | prefixes allowlists.Bp2BuildConfig |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 24 | packageDir string |
| 25 | }{ |
| 26 | { |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame^] | 27 | prefixes: allowlists.Bp2BuildConfig{ |
| 28 | "a": allowlists.Bp2BuildDefaultTrueRecursively, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 29 | }, |
| 30 | packageDir: "a", |
| 31 | }, |
| 32 | { |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame^] | 33 | prefixes: allowlists.Bp2BuildConfig{ |
| 34 | "a/b": allowlists.Bp2BuildDefaultTrueRecursively, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 35 | }, |
| 36 | packageDir: "a/b", |
| 37 | }, |
| 38 | { |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame^] | 39 | prefixes: allowlists.Bp2BuildConfig{ |
| 40 | "a/b": allowlists.Bp2BuildDefaultTrueRecursively, |
| 41 | "a/b/c": allowlists.Bp2BuildDefaultTrueRecursively, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 42 | }, |
| 43 | packageDir: "a/b", |
| 44 | }, |
| 45 | { |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame^] | 46 | prefixes: allowlists.Bp2BuildConfig{ |
| 47 | "a": allowlists.Bp2BuildDefaultTrueRecursively, |
| 48 | "d/e/f": allowlists.Bp2BuildDefaultTrueRecursively, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 49 | }, |
| 50 | packageDir: "a/b", |
| 51 | }, |
| 52 | { |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame^] | 53 | prefixes: allowlists.Bp2BuildConfig{ |
| 54 | "a": allowlists.Bp2BuildDefaultFalse, |
| 55 | "a/b": allowlists.Bp2BuildDefaultTrueRecursively, |
| 56 | "a/b/c": allowlists.Bp2BuildDefaultFalse, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 57 | }, |
| 58 | packageDir: "a/b", |
| 59 | }, |
| 60 | { |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame^] | 61 | prefixes: allowlists.Bp2BuildConfig{ |
| 62 | "a": allowlists.Bp2BuildDefaultTrueRecursively, |
| 63 | "a/b": allowlists.Bp2BuildDefaultFalse, |
| 64 | "a/b/c": allowlists.Bp2BuildDefaultTrueRecursively, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 65 | }, |
| 66 | packageDir: "a", |
| 67 | }, |
| 68 | } |
| 69 | |
| 70 | for _, test := range testCases { |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame^] | 71 | if ok, _ := bp2buildDefaultTrueRecursively(test.packageDir, test.prefixes); !ok { |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 72 | t.Errorf("Expected to convert all modules in %s based on %v, but failed.", test.packageDir, test.prefixes) |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | func TestModuleOptIn(t *testing.T) { |
| 78 | testCases := []struct { |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame^] | 79 | prefixes allowlists.Bp2BuildConfig |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 80 | packageDir string |
| 81 | }{ |
| 82 | { |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame^] | 83 | prefixes: allowlists.Bp2BuildConfig{ |
| 84 | "a/b": allowlists.Bp2BuildDefaultFalse, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 85 | }, |
| 86 | packageDir: "a/b", |
| 87 | }, |
| 88 | { |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame^] | 89 | prefixes: allowlists.Bp2BuildConfig{ |
| 90 | "a": allowlists.Bp2BuildDefaultFalse, |
| 91 | "a/b": allowlists.Bp2BuildDefaultTrueRecursively, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 92 | }, |
| 93 | packageDir: "a", |
| 94 | }, |
| 95 | { |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame^] | 96 | prefixes: allowlists.Bp2BuildConfig{ |
| 97 | "a/b": allowlists.Bp2BuildDefaultTrueRecursively, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 98 | }, |
| 99 | packageDir: "a", // opt-in by default |
| 100 | }, |
| 101 | { |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame^] | 102 | prefixes: allowlists.Bp2BuildConfig{ |
| 103 | "a/b/c": allowlists.Bp2BuildDefaultTrueRecursively, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 104 | }, |
| 105 | packageDir: "a/b", |
| 106 | }, |
| 107 | { |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame^] | 108 | prefixes: allowlists.Bp2BuildConfig{ |
| 109 | "a": allowlists.Bp2BuildDefaultTrueRecursively, |
| 110 | "d/e/f": allowlists.Bp2BuildDefaultTrueRecursively, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 111 | }, |
| 112 | packageDir: "foo/bar", |
| 113 | }, |
| 114 | { |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame^] | 115 | prefixes: allowlists.Bp2BuildConfig{ |
| 116 | "a": allowlists.Bp2BuildDefaultTrueRecursively, |
| 117 | "a/b": allowlists.Bp2BuildDefaultFalse, |
| 118 | "a/b/c": allowlists.Bp2BuildDefaultTrueRecursively, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 119 | }, |
| 120 | packageDir: "a/b", |
| 121 | }, |
| 122 | { |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame^] | 123 | prefixes: allowlists.Bp2BuildConfig{ |
| 124 | "a": allowlists.Bp2BuildDefaultFalse, |
| 125 | "a/b": allowlists.Bp2BuildDefaultTrueRecursively, |
| 126 | "a/b/c": allowlists.Bp2BuildDefaultFalse, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 127 | }, |
| 128 | packageDir: "a", |
| 129 | }, |
| 130 | } |
| 131 | |
| 132 | for _, test := range testCases { |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame^] | 133 | if ok, _ := bp2buildDefaultTrueRecursively(test.packageDir, test.prefixes); ok { |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 134 | t.Errorf("Expected to allow module opt-in in %s based on %v, but failed.", test.packageDir, test.prefixes) |
| 135 | } |
| 136 | } |
| 137 | } |