Skip to content

Commit 2f12594

Browse files
authored
Merge pull request #110 from heetch/sixstone-001/add-parse-compat
Add avro.ParseCompatMode
2 parents 34be94a + 1d4e183 commit 2f12594

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

compat.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,25 @@ func (m CompatMode) String() string {
3737
}
3838
return s
3939
}
40+
41+
// ParseCompatMode returns the CompatMode from a string.
42+
// It returns -1 if no matches are found.
43+
func ParseCompatMode(s string) CompatMode {
44+
switch s {
45+
case "BACKWARD":
46+
return Backward
47+
case "FORWARD":
48+
return Forward
49+
case "FULL":
50+
return Full
51+
case "BACKWARD_TRANSITIVE":
52+
return BackwardTransitive
53+
case "FORWARD_TRANSITIVE":
54+
return ForwardTransitive
55+
case "FULL_TRANSITIVE":
56+
return FullTransitive
57+
case "NONE":
58+
return 0
59+
}
60+
return -1
61+
}

compat_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,17 @@ func TestCompatString(t *testing.T) {
3030
})
3131
}
3232
}
33+
34+
func TestCompatParse(t *testing.T) {
35+
c := qt.New(t)
36+
for _, test := range compatStringTests {
37+
c.Run(test.s, func(c *qt.C) {
38+
if test.s == "UNKNOWN" {
39+
// We can't return same data we don't know
40+
c.Assert(avro.ParseCompatMode(test.s), qt.Equals, avro.CompatMode(-1))
41+
} else {
42+
c.Assert(avro.ParseCompatMode(test.s), qt.Equals, test.m)
43+
}
44+
})
45+
}
46+
}

0 commit comments

Comments
 (0)