Skip to content

Commit 6833fc3

Browse files
arnaucubep4u
authored andcommitted
Census Manager.LoadTree set default CensusType
Ensure backwards compatibility to CensusTrees created before the Protobuf CensusTypes implementation. When TreeType is set to 0, uses the 'default' tree type.
1 parent 0f68228 commit 6833fc3

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

census/census.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ func (m *Manager) LoadTree(name string, treeType models.Census_Type) (censustree
134134
if _, exist := m.Trees[name]; exist {
135135
return m.Trees[name], nil
136136
}
137+
138+
// ensure backwards compatibility to CensusTrees created before the
139+
// Protobuf CensusTypes implementation. When TreeType is set to 0, uses
140+
// the 'default' tree type
141+
if treeType == models.Census_UNKNOWN {
142+
treeType = censusDefaultType
143+
}
144+
137145
tr, err := censustreefactory.NewCensusTree(treeType, name, m.StorageDir)
138146
if err != nil {
139147
return nil, err

census/census_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,14 @@ func TestCompressor(t *testing.T) {
2525
// Decompressing should give us the original input back.
2626
qt.Assert(t, comp.decompressBytes(compressed), qt.DeepEquals, input)
2727
}
28+
29+
func TestLoadTreeDefaultCensusType(t *testing.T) {
30+
m := &Manager{}
31+
err := m.Init(t.TempDir(), "")
32+
qt.Assert(t, err, qt.IsNil)
33+
34+
// ensure that when TreeType is set to 0, uses the 'default' tree type
35+
tree, err := m.LoadTree("testtree", 0)
36+
qt.Assert(t, err, qt.IsNil)
37+
qt.Assert(t, censusDefaultType, qt.Equals, tree.Type())
38+
}

0 commit comments

Comments
 (0)