Allow uploading a directory of metrics files.
The upload functionality now supports directories to be uploaded
for metrics purpose.
Bug: b/174479728
Test: Wrote unit test case.
Change-Id: I6906be4c1b7fd76ddf6ff7b94e48fe1c4209c59d
diff --git a/ui/build/upload_test.go b/ui/build/upload_test.go
index 768b031..b740c11 100644
--- a/ui/build/upload_test.go
+++ b/ui/build/upload_test.go
@@ -19,6 +19,8 @@
"io/ioutil"
"os"
"path/filepath"
+ "reflect"
+ "sort"
"strconv"
"strings"
"testing"
@@ -27,6 +29,49 @@
"android/soong/ui/logger"
)
+func TestPruneMetricsFiles(t *testing.T) {
+ rootDir := t.TempDir()
+
+ dirs := []string{
+ filepath.Join(rootDir, "d1"),
+ filepath.Join(rootDir, "d1", "d2"),
+ filepath.Join(rootDir, "d1", "d2", "d3"),
+ }
+
+ files := []string{
+ filepath.Join(rootDir, "d1", "f1"),
+ filepath.Join(rootDir, "d1", "d2", "f1"),
+ filepath.Join(rootDir, "d1", "d2", "d3", "f1"),
+ }
+
+ for _, d := range dirs {
+ if err := os.MkdirAll(d, 0777); err != nil {
+ t.Fatalf("got %v, expecting nil error for making directory %q", err, d)
+ }
+ }
+
+ for _, f := range files {
+ if err := ioutil.WriteFile(f, []byte{}, 0777); err != nil {
+ t.Fatalf("got %v, expecting nil error on writing file %q", err, f)
+ }
+ }
+
+ want := []string{
+ filepath.Join(rootDir, "d1", "f1"),
+ filepath.Join(rootDir, "d1", "d2", "f1"),
+ filepath.Join(rootDir, "d1", "d2", "d3", "f1"),
+ }
+
+ got := pruneMetricsFiles([]string{rootDir})
+
+ sort.Strings(got)
+ sort.Strings(want)
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("got %q, want %q after pruning metrics files", got, want)
+ }
+}
+
func TestUploadMetrics(t *testing.T) {
ctx := testContext()
tests := []struct {