File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments