apex_test.go 3.3 KB

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