blob: 750762815473ddeb17b367773c217346de31d7a9 [file] [log] [blame]
Colin Crossaede88c2020-08-11 12:17:01 -07001// 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
15package android
16
17import (
18 "reflect"
19 "testing"
20)
21
22func Test_mergeApexVariations(t *testing.T) {
Colin Cross323dc602020-09-18 14:25:31 -070023 t.Parallel()
Colin Crossaede88c2020-08-11 12:17:01 -070024 tests := []struct {
25 name string
26 in []ApexInfo
27 wantMerged []ApexInfo
28 wantAliases [][2]string
29 }{
30 {
31 name: "single",
32 in: []ApexInfo{
Colin Cross56a83212020-09-15 18:30:11 -070033 {"foo", "current", false, nil, []string{"foo"}, nil},
Colin Crossaede88c2020-08-11 12:17:01 -070034 },
35 wantMerged: []ApexInfo{
Colin Cross56a83212020-09-15 18:30:11 -070036 {"apex10000", "current", false, nil, []string{"foo"}, nil},
Colin Crossaede88c2020-08-11 12:17:01 -070037 },
38 wantAliases: [][2]string{
39 {"foo", "apex10000"},
40 },
41 },
42 {
43 name: "merge",
44 in: []ApexInfo{
Colin Cross56a83212020-09-15 18:30:11 -070045 {"foo", "current", false, SdkRefs{{"baz", "1"}}, []string{"foo"}, nil},
46 {"bar", "current", false, SdkRefs{{"baz", "1"}}, []string{"bar"}, nil},
Colin Crossaede88c2020-08-11 12:17:01 -070047 },
48 wantMerged: []ApexInfo{
Colin Cross56a83212020-09-15 18:30:11 -070049 {"apex10000_baz_1", "current", false, SdkRefs{{"baz", "1"}}, []string{"bar", "foo"}, nil}},
Colin Crossaede88c2020-08-11 12:17:01 -070050 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{
Colin Cross56a83212020-09-15 18:30:11 -070058 {"foo", "current", false, nil, []string{"foo"}, nil},
59 {"bar", "30", false, nil, []string{"bar"}, nil},
Colin Crossaede88c2020-08-11 12:17:01 -070060 },
61 wantMerged: []ApexInfo{
Colin Cross56a83212020-09-15 18:30:11 -070062 {"apex30", "30", false, nil, []string{"bar"}, nil},
63 {"apex10000", "current", false, nil, []string{"foo"}, nil},
Colin Crossaede88c2020-08-11 12:17:01 -070064 },
65 wantAliases: [][2]string{
66 {"bar", "apex30"},
67 {"foo", "apex10000"},
68 },
69 },
70 {
71 name: "merge updatable",
72 in: []ApexInfo{
Colin Cross56a83212020-09-15 18:30:11 -070073 {"foo", "current", false, nil, []string{"foo"}, nil},
74 {"bar", "current", true, nil, []string{"bar"}, nil},
Colin Crossaede88c2020-08-11 12:17:01 -070075 },
76 wantMerged: []ApexInfo{
Colin Cross56a83212020-09-15 18:30:11 -070077 {"apex10000", "current", true, nil, []string{"bar", "foo"}, nil},
Colin Crossaede88c2020-08-11 12:17:01 -070078 },
79 wantAliases: [][2]string{
80 {"bar", "apex10000"},
81 {"foo", "apex10000"},
82 },
83 },
84 {
85 name: "don't merge sdks",
86 in: []ApexInfo{
Colin Cross56a83212020-09-15 18:30:11 -070087 {"foo", "current", false, SdkRefs{{"baz", "1"}}, []string{"foo"}, nil},
88 {"bar", "current", false, SdkRefs{{"baz", "2"}}, []string{"bar"}, nil},
Colin Crossaede88c2020-08-11 12:17:01 -070089 },
90 wantMerged: []ApexInfo{
Colin Cross56a83212020-09-15 18:30:11 -070091 {"apex10000_baz_2", "current", false, SdkRefs{{"baz", "2"}}, []string{"bar"}, nil},
92 {"apex10000_baz_1", "current", false, SdkRefs{{"baz", "1"}}, []string{"foo"}, nil},
Colin Crossaede88c2020-08-11 12:17:01 -070093 },
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) {
Colin Cross9f720ce2020-10-02 10:26:04 -0700102 config := TestConfig(buildDir, nil, "", nil)
103 ctx := &configErrorWrapper{config: config}
104 gotMerged, gotAliases := mergeApexVariations(ctx, tt.in)
Colin Crossaede88c2020-08-11 12:17:01 -0700105 if !reflect.DeepEqual(gotMerged, tt.wantMerged) {
106 t.Errorf("mergeApexVariations() gotMerged = %v, want %v", gotMerged, tt.wantMerged)
107 }
108 if !reflect.DeepEqual(gotAliases, tt.wantAliases) {
109 t.Errorf("mergeApexVariations() gotAliases = %v, want %v", gotAliases, tt.wantAliases)
110 }
111 })
112 }
113}