From d54f46d6250bda90566340637f4fc2d80505e0b6 Mon Sep 17 00:00:00 2001 From: Bo Xu Date: Tue, 8 Mar 2022 17:08:06 -0800 Subject: [PATCH] Handle empty line when parse bigtable group version file (#775) --- internal/util/util.go | 5 ++++- internal/util/util_test.go | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/internal/util/util.go b/internal/util/util.go index 71c257c06..9167836fd 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -431,7 +431,10 @@ func ParseBigtableGroup(s string) []string { if err == io.EOF { break } - tables = append(tables, strings.TrimSpace(string(line))) + t := strings.TrimSpace(string(line)) + if t != "" { + tables = append(tables, t) + } } return tables } diff --git a/internal/util/util_test.go b/internal/util/util_test.go index 4b4e89c4d..383ec6cd6 100644 --- a/internal/util/util_test.go +++ b/internal/util/util_test.go @@ -212,3 +212,18 @@ func TestKeysToSlice(t *testing.T) { t.Errorf("places.keysToSlice(%v) = %v; expected %v", m, result, expected) } } + +func TestParseBigtableGroup(t *testing.T) { + for _, c := range []struct { + input string + want []string + }{ + {"table1\ntable2\n\n", []string{"table1", "table2"}}, + {"table1 \n table2\n", []string{"table1", "table2"}}, + } { + got := ParseBigtableGroup(c.input) + if diff := cmp.Diff(got, c.want); diff != "" { + t.Errorf("ParseBigtableGroup got diff %+v", diff) + } + } +}