2023-03-28 22:48:58 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 22:48:58 +00:00
|
|
|
|
2023-02-06 17:14:35 +00:00
|
|
|
package xdscommon
|
2022-12-20 17:58:19 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/go-version"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestProxySupportOrder(t *testing.T) {
|
|
|
|
versions := make([]*version.Version, len(EnvoyVersions))
|
|
|
|
beforeSort := make([]*version.Version, len(EnvoyVersions))
|
|
|
|
for i, raw := range EnvoyVersions {
|
|
|
|
v, _ := version.NewVersion(raw)
|
|
|
|
versions[i] = v
|
|
|
|
beforeSort[i] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
// After this, the versions are properly sorted
|
|
|
|
// go-version has a collection container, but it only allows for sorting in ascending order
|
|
|
|
sort.Slice(versions, func(i, j int) bool {
|
|
|
|
return versions[j].LessThan(versions[i])
|
|
|
|
})
|
|
|
|
|
|
|
|
// Check that we already have a sorted list
|
|
|
|
for i := range EnvoyVersions {
|
|
|
|
assert.True(t, versions[i].Equal(beforeSort[i]))
|
|
|
|
}
|
|
|
|
}
|