Skip to content

Commit

Permalink
Merge pull request #110 from heetch/sixstone-001/add-parse-compat
Browse files Browse the repository at this point in the history
Add avro.ParseCompatMode
  • Loading branch information
sixstone-qq authored May 25, 2022
2 parents 34be94a + 1d4e183 commit 2f12594
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
22 changes: 22 additions & 0 deletions compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,25 @@ func (m CompatMode) String() string {
}
return s
}

// ParseCompatMode returns the CompatMode from a string.
// It returns -1 if no matches are found.
func ParseCompatMode(s string) CompatMode {
switch s {
case "BACKWARD":
return Backward
case "FORWARD":
return Forward
case "FULL":
return Full
case "BACKWARD_TRANSITIVE":
return BackwardTransitive
case "FORWARD_TRANSITIVE":
return ForwardTransitive
case "FULL_TRANSITIVE":
return FullTransitive
case "NONE":
return 0
}
return -1
}
14 changes: 14 additions & 0 deletions compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,17 @@ func TestCompatString(t *testing.T) {
})
}
}

func TestCompatParse(t *testing.T) {
c := qt.New(t)
for _, test := range compatStringTests {
c.Run(test.s, func(c *qt.C) {
if test.s == "UNKNOWN" {
// We can't return same data we don't know
c.Assert(avro.ParseCompatMode(test.s), qt.Equals, avro.CompatMode(-1))
} else {
c.Assert(avro.ParseCompatMode(test.s), qt.Equals, test.m)
}
})
}
}

0 comments on commit 2f12594

Please sign in to comment.