Skip to content

Commit

Permalink
Fix cassandraVersion.Before() call (apache#1202)
Browse files Browse the repository at this point in the history
* Fixes the Before() call

Signed-off-by: Alex Lourie <alex@instaclustr.com>

* Review comments

Signed-off-by: Alex Lourie <alex@instaclustr.com>
  • Loading branch information
alourie authored and Zariel committed Sep 29, 2018
1 parent 843d9a6 commit a16518d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2834,7 +2834,7 @@ func TestUnmarshallNestedTypes(t *testing.T) {
}

func TestSchemaReset(t *testing.T) {
if flagCassVersion.Major == 0 || (flagCassVersion.Before(2, 1, 3)) {
if flagCassVersion.Major == 0 || flagCassVersion.Before(2, 1, 3) {
t.Skipf("skipping TestSchemaReset due to CASSANDRA-7910 in Cassandra <2.1.3 version=%v", flagCassVersion)
}

Expand Down
15 changes: 10 additions & 5 deletions host_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,17 @@ func (c *cassVersion) unmarshal(data []byte) error {
}

func (c cassVersion) Before(major, minor, patch int) bool {
if c.Major > major {
return true
} else if c.Minor > minor {
return true
} else if c.Patch > patch {
// We're comparing us (cassVersion) with the provided version (major, minor, patch)
// We return true if our version is lower (comes before) than the provided one.
if c.Major < major {
return true
} else if c.Major == major {
if c.Minor < minor {
return true
} else if c.Minor == minor && c.Patch < patch {
return true
}

}
return false
}
Expand Down
3 changes: 2 additions & 1 deletion host_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ func TestCassVersionBefore(t *testing.T) {

{cassVersion{1, 0, 0}, 0, 1, 0},
{cassVersion{0, 1, 0}, 0, 0, 1},
{cassVersion{4, 1, 0}, 3, 1, 2},
}

for i, test := range tests {
if !test.version.Before(test.major, test.minor, test.patch) {
if test.version.Before(test.major, test.minor, test.patch) {
t.Errorf("%d: expected v%d.%d.%d to be before %v", i, test.major, test.minor, test.patch, test.version)
}
}
Expand Down

0 comments on commit a16518d

Please sign in to comment.