Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame^] | 1 | // Copyright 2020 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 android |
| 16 | |
| 17 | import ( |
| 18 | "reflect" |
| 19 | "testing" |
| 20 | ) |
| 21 | |
| 22 | func Test_mergeApexVariations(t *testing.T) { |
| 23 | tests := []struct { |
| 24 | name string |
| 25 | in []ApexInfo |
| 26 | wantMerged []ApexInfo |
| 27 | wantAliases [][2]string |
| 28 | }{ |
| 29 | { |
| 30 | name: "single", |
| 31 | in: []ApexInfo{ |
| 32 | {"foo", 10000, false, nil, []string{"foo"}}, |
| 33 | }, |
| 34 | wantMerged: []ApexInfo{ |
| 35 | {"apex10000", 10000, false, nil, []string{"foo"}}, |
| 36 | }, |
| 37 | wantAliases: [][2]string{ |
| 38 | {"foo", "apex10000"}, |
| 39 | }, |
| 40 | }, |
| 41 | { |
| 42 | name: "merge", |
| 43 | in: []ApexInfo{ |
| 44 | {"foo", 10000, false, SdkRefs{{"baz", "1"}}, []string{"foo"}}, |
| 45 | {"bar", 10000, false, SdkRefs{{"baz", "1"}}, []string{"bar"}}, |
| 46 | }, |
| 47 | wantMerged: []ApexInfo{ |
| 48 | {"apex10000_baz_1", 10000, false, SdkRefs{{"baz", "1"}}, []string{"bar", "foo"}}, |
| 49 | }, |
| 50 | wantAliases: [][2]string{ |
| 51 | {"bar", "apex10000_baz_1"}, |
| 52 | {"foo", "apex10000_baz_1"}, |
| 53 | }, |
| 54 | }, |
| 55 | { |
| 56 | name: "don't merge version", |
| 57 | in: []ApexInfo{ |
| 58 | {"foo", 10000, false, nil, []string{"foo"}}, |
| 59 | {"bar", 30, false, nil, []string{"bar"}}, |
| 60 | }, |
| 61 | wantMerged: []ApexInfo{ |
| 62 | {"apex30", 30, false, nil, []string{"bar"}}, |
| 63 | {"apex10000", 10000, false, nil, []string{"foo"}}, |
| 64 | }, |
| 65 | wantAliases: [][2]string{ |
| 66 | {"bar", "apex30"}, |
| 67 | {"foo", "apex10000"}, |
| 68 | }, |
| 69 | }, |
| 70 | { |
| 71 | name: "merge updatable", |
| 72 | in: []ApexInfo{ |
| 73 | {"foo", 10000, false, nil, []string{"foo"}}, |
| 74 | {"bar", 10000, true, nil, []string{"bar"}}, |
| 75 | }, |
| 76 | wantMerged: []ApexInfo{ |
| 77 | {"apex10000", 10000, true, nil, []string{"bar", "foo"}}, |
| 78 | }, |
| 79 | wantAliases: [][2]string{ |
| 80 | {"bar", "apex10000"}, |
| 81 | {"foo", "apex10000"}, |
| 82 | }, |
| 83 | }, |
| 84 | { |
| 85 | name: "don't merge sdks", |
| 86 | in: []ApexInfo{ |
| 87 | {"foo", 10000, false, SdkRefs{{"baz", "1"}}, []string{"foo"}}, |
| 88 | {"bar", 10000, false, SdkRefs{{"baz", "2"}}, []string{"bar"}}, |
| 89 | }, |
| 90 | wantMerged: []ApexInfo{ |
| 91 | {"apex10000_baz_2", 10000, false, SdkRefs{{"baz", "2"}}, []string{"bar"}}, |
| 92 | {"apex10000_baz_1", 10000, false, SdkRefs{{"baz", "1"}}, []string{"foo"}}, |
| 93 | }, |
| 94 | wantAliases: [][2]string{ |
| 95 | {"bar", "apex10000_baz_2"}, |
| 96 | {"foo", "apex10000_baz_1"}, |
| 97 | }, |
| 98 | }, |
| 99 | } |
| 100 | for _, tt := range tests { |
| 101 | t.Run(tt.name, func(t *testing.T) { |
| 102 | gotMerged, gotAliases := mergeApexVariations(tt.in) |
| 103 | if !reflect.DeepEqual(gotMerged, tt.wantMerged) { |
| 104 | t.Errorf("mergeApexVariations() gotMerged = %v, want %v", gotMerged, tt.wantMerged) |
| 105 | } |
| 106 | if !reflect.DeepEqual(gotAliases, tt.wantAliases) { |
| 107 | t.Errorf("mergeApexVariations() gotAliases = %v, want %v", gotAliases, tt.wantAliases) |
| 108 | } |
| 109 | }) |
| 110 | } |
| 111 | } |