Skip to content

Commit

Permalink
add version tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Schmidt committed Aug 6, 2024
1 parent 67d5082 commit fcf06e4
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
2 changes: 1 addition & 1 deletion admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ func (c *AdminClient) ListRoles(ctx context.Context) (*protos.ListRolesResponse,
}

// NodeIds returns a list of all the node ids that the client is connected to.
// If a node is accessible but not apart of the cluster it will not be returned.
// If a node is accessible but not a part of the cluster it will not be returned.
func (c *AdminClient) NodeIDs(ctx context.Context) []*protos.NodeId {
c.logger.InfoContext(ctx, "getting cluster info")

Expand Down
77 changes: 77 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package avs

import "testing"

func TestVersionLTGT(t *testing.T) {
testCases := []struct {
name string
v1 version
v2 version
wantLT bool
wantGT bool
}{
{
name: "v1 is less than v2",
v1: newVersion("1.0.0"),
v2: newVersion("2.0.0"),
wantLT: true,
wantGT: false,
},
{
name: "v1 is greater than v2",
v1: newVersion("2.0.0"),
v2: newVersion("1.0.0"),
wantLT: false,
wantGT: true,
},
{
name: "v1 is less than v2",
v1: newVersion("1.0.0"),
v2: newVersion("1.0.1"),
wantLT: true,
wantGT: false,
},
{
name: "v1 is less than v2",
v1: newVersion("1.0.0"),
v2: newVersion("1.0.0.dev0"),
wantLT: true,
wantGT: false,
},
{
name: "v1 is greater than v2",
v1: newVersion("1.0.0.dev0"),
v2: newVersion("1.0.0"),
wantLT: false,
wantGT: true,
},
{
name: "v1 is less than v2",
v1: newVersion("1.0.0.dev0"),
v2: newVersion("1.0.0.dev1"),
wantLT: true,
wantGT: false,
},
{
name: "v1 is equal to v2",
v1: newVersion("1.0.0"),
v2: newVersion("1.0.0"),
wantLT: false,
wantGT: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got := tc.v1.lt(tc.v2)
if got != tc.wantLT {
t.Errorf("expected %v, got %v", tc.wantLT, got)
}

got = tc.v1.gt(tc.v2)
if got != tc.wantGT {
t.Errorf("expected %v, got %v", !tc.wantLT, got)
}
})
}
}

0 comments on commit fcf06e4

Please sign in to comment.