blob: 512b50f967208b4ce0bedce4aabc2f1d2e724a7c [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) {
23 tests := []struct {
24 name string
25 in []ApexInfo
26 wantMerged []ApexInfo
27 wantAliases [][2]string
28 }{
29 {
30 name: "single",
31 in: []ApexInfo{
Colin Cross56a83212020-09-15 18:30:11 -070032 {"foo", "current", false, nil, []string{"foo"}, nil},
Colin Crossaede88c2020-08-11 12:17:01 -070033 },
34 wantMerged: []ApexInfo{
Colin Cross56a83212020-09-15 18:30:11 -070035 {"apex10000", "current", false, nil, []string{"foo"}, nil},
Colin Crossaede88c2020-08-11 12:17:01 -070036 },
37 wantAliases: [][2]string{
38 {"foo", "apex10000"},
39 },
40 },
41 {
42 name: "merge",
43 in: []ApexInfo{
Colin Cross56a83212020-09-15 18:30:11 -070044 {"foo", "current", false, SdkRefs{{"baz", "1"}}, []string{"foo"}, nil},
45 {"bar", "current", false, SdkRefs{{"baz", "1"}}, []string{"bar"}, nil},
Colin Crossaede88c2020-08-11 12:17:01 -070046 },
47 wantMerged: []ApexInfo{
Colin Cross56a83212020-09-15 18:30:11 -070048 {"apex10000_baz_1", "current", false, SdkRefs{{"baz", "1"}}, []string{"bar", "foo"}, nil}},
Colin Crossaede88c2020-08-11 12:17:01 -070049 wantAliases: [][2]string{
50 {"bar", "apex10000_baz_1"},
51 {"foo", "apex10000_baz_1"},
52 },
53 },
54 {
55 name: "don't merge version",
56 in: []ApexInfo{
Colin Cross56a83212020-09-15 18:30:11 -070057 {"foo", "current", false, nil, []string{"foo"}, nil},
58 {"bar", "30", false, nil, []string{"bar"}, nil},
Colin Crossaede88c2020-08-11 12:17:01 -070059 },
60 wantMerged: []ApexInfo{
Colin Cross56a83212020-09-15 18:30:11 -070061 {"apex30", "30", false, nil, []string{"bar"}, nil},
62 {"apex10000", "current", false, nil, []string{"foo"}, nil},
Colin Crossaede88c2020-08-11 12:17:01 -070063 },
64 wantAliases: [][2]string{
65 {"bar", "apex30"},
66 {"foo", "apex10000"},
67 },
68 },
69 {
70 name: "merge updatable",
71 in: []ApexInfo{
Colin Cross56a83212020-09-15 18:30:11 -070072 {"foo", "current", false, nil, []string{"foo"}, nil},
73 {"bar", "current", true, nil, []string{"bar"}, nil},
Colin Crossaede88c2020-08-11 12:17:01 -070074 },
75 wantMerged: []ApexInfo{
Colin Cross56a83212020-09-15 18:30:11 -070076 {"apex10000", "current", true, nil, []string{"bar", "foo"}, nil},
Colin Crossaede88c2020-08-11 12:17:01 -070077 },
78 wantAliases: [][2]string{
79 {"bar", "apex10000"},
80 {"foo", "apex10000"},
81 },
82 },
83 {
84 name: "don't merge sdks",
85 in: []ApexInfo{
Colin Cross56a83212020-09-15 18:30:11 -070086 {"foo", "current", false, SdkRefs{{"baz", "1"}}, []string{"foo"}, nil},
87 {"bar", "current", false, SdkRefs{{"baz", "2"}}, []string{"bar"}, nil},
Colin Crossaede88c2020-08-11 12:17:01 -070088 },
89 wantMerged: []ApexInfo{
Colin Cross56a83212020-09-15 18:30:11 -070090 {"apex10000_baz_2", "current", false, SdkRefs{{"baz", "2"}}, []string{"bar"}, nil},
91 {"apex10000_baz_1", "current", false, SdkRefs{{"baz", "1"}}, []string{"foo"}, nil},
Colin Crossaede88c2020-08-11 12:17:01 -070092 },
93 wantAliases: [][2]string{
94 {"bar", "apex10000_baz_2"},
95 {"foo", "apex10000_baz_1"},
96 },
97 },
98 }
99 for _, tt := range tests {
100 t.Run(tt.name, func(t *testing.T) {
Colin Cross9f720ce2020-10-02 10:26:04 -0700101 config := TestConfig(buildDir, nil, "", nil)
102 ctx := &configErrorWrapper{config: config}
103 gotMerged, gotAliases := mergeApexVariations(ctx, tt.in)
Colin Crossaede88c2020-08-11 12:17:01 -0700104 if !reflect.DeepEqual(gotMerged, tt.wantMerged) {
105 t.Errorf("mergeApexVariations() gotMerged = %v, want %v", gotMerged, tt.wantMerged)
106 }
107 if !reflect.DeepEqual(gotAliases, tt.wantAliases) {
108 t.Errorf("mergeApexVariations() gotAliases = %v, want %v", gotAliases, tt.wantAliases)
109 }
110 })
111 }
112}