Skip to content

Commit

Permalink
added a couple of tests to gameserverallocationpolicy (googleforgames…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-kremsa-globant authored and ilkercelikyilmaz committed Oct 23, 2020
1 parent abdd098 commit 1049974
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions pkg/apis/multicluster/v1/gameserverallocationpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,34 @@ func TestConnectionInfoIterator(t *testing.T) {
in: nil,
want: nil,
},
{
name: "Same clusters and same priorities",
in: []*GameServerAllocationPolicy{
{
Spec: GameServerAllocationPolicySpec{
Priority: 1,
Weight: 100,
ConnectionInfo: ClusterConnectionInfo{
ClusterName: "cluster-name",
},
},
},
{
Spec: GameServerAllocationPolicySpec{
Priority: 1,
Weight: 300,
ConnectionInfo: ClusterConnectionInfo{
ClusterName: "cluster-name",
},
},
},
},
want: []ClusterConnectionInfo{
{
ClusterName: "cluster-name",
},
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand All @@ -277,3 +305,37 @@ func TestConnectionInfoIterator(t *testing.T) {
})
}
}

func TestConnectionInfoIterator_SameClustersAndPriorities(t *testing.T) {
in := []*GameServerAllocationPolicy{
{
Spec: GameServerAllocationPolicySpec{
Priority: 444,
Weight: 100,
ConnectionInfo: ClusterConnectionInfo{
ClusterName: "cluster-name",
},
},
},
{
Spec: GameServerAllocationPolicySpec{
Priority: 444,
Weight: 300,
ConnectionInfo: ClusterConnectionInfo{
ClusterName: "cluster-name",
},
},
},
}

iterator := NewConnectionInfoIterator(in)
res := iterator.priorityToCluster[444]["cluster-name"]

// check an internal slice of policies
if assert.Equal(t, 2, len(res)) {
assert.Equal(t, "cluster-name", res[0].Spec.ConnectionInfo.ClusterName)
assert.Equal(t, int32(444), res[0].Spec.Priority)
assert.Equal(t, "cluster-name", res[1].Spec.ConnectionInfo.ClusterName)
assert.Equal(t, int32(444), res[1].Spec.Priority)
}
}

0 comments on commit 1049974

Please sign in to comment.