1// Copyright 2022 The Bazel Authors. 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 extractaar 16 17import ( 18 "testing" 19 20 "github.com/google/go-cmp/cmp" 21) 22 23func TestGroupAARFiles(t *testing.T) { 24 tests := []struct { 25 name string 26 files []*aarFile 27 expectedMap map[int][]*aarFile 28 }{ 29 { 30 name: "empty aar", 31 files: []*aarFile{}, 32 expectedMap: map[int][]*aarFile{ 33 manifest: []*aarFile{}, 34 res: []*aarFile{}, 35 assets: []*aarFile{}, 36 }, 37 }, 38 { 39 name: "simple aar", 40 files: []*aarFile{ 41 &aarFile{relPath: "AndroidManifest.xml"}, 42 &aarFile{relPath: "res/values/strings.xml"}, 43 &aarFile{relPath: "lint.jar"}, 44 &aarFile{relPath: "proguard.txt"}, 45 &aarFile{relPath: "classes.jar"}, 46 &aarFile{relPath: "assetsdir/values.txt"}, 47 &aarFile{relPath: "libs/foo.jar"}, 48 &aarFile{relPath: "resource/some/file.txt"}, 49 &aarFile{relPath: "assets/some/asset.png"}, 50 }, 51 expectedMap: map[int][]*aarFile{ 52 manifest: []*aarFile{ 53 &aarFile{relPath: "AndroidManifest.xml"}, 54 }, 55 res: []*aarFile{ 56 &aarFile{relPath: "res/values/strings.xml"}, 57 }, 58 assets: []*aarFile{ 59 &aarFile{relPath: "assets/some/asset.png"}, 60 }, 61 }, 62 }, 63 } 64 65 for _, tc := range tests { 66 t.Run(tc.name, func(t *testing.T) { 67 filesMap := groupAARFiles(tc.files) 68 if diff := cmp.Diff(tc.expectedMap, filesMap, cmp.AllowUnexported(aarFile{})); diff != "" { 69 t.Errorf("groupAARFiles(%v) returned diff (-want, +got):\n%v", tc.files, diff) 70 } 71 }) 72 } 73} 74