Files
cozystack/pkg/cmd/server/start_test.go
Andrei Kvapil 440c4f2a6b Fix go depdendencies
ref: a1232016a0

Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
2025-06-12 06:44:47 +02:00

69 lines
2.1 KiB
Go

/*
Copyright 2024 The Cozystack Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package server
import (
"testing"
"k8s.io/apimachinery/pkg/util/version"
"k8s.io/apiserver/pkg/util/compatibility"
"github.com/stretchr/testify/assert"
)
func TestAppsEmulationVersionToKubeEmulationVersion(t *testing.T) {
defaultKubeEffectiveVersion := compatibility.DefaultKubeEffectiveVersionForTest()
testCases := []struct {
desc string
appsEmulationVer *version.Version
expectedKubeEmulationVer *version.Version
}{
{
desc: "same version as than kube binary",
appsEmulationVer: version.MajorMinor(1, 2),
expectedKubeEmulationVer: defaultKubeEffectiveVersion.BinaryVersion(),
},
{
desc: "1 version lower than kube binary",
appsEmulationVer: version.MajorMinor(1, 1),
expectedKubeEmulationVer: defaultKubeEffectiveVersion.BinaryVersion().OffsetMinor(-1),
},
{
desc: "2 versions lower than kube binary",
appsEmulationVer: version.MajorMinor(1, 0),
expectedKubeEmulationVer: defaultKubeEffectiveVersion.BinaryVersion().OffsetMinor(-2),
},
{
desc: "capped at kube binary",
appsEmulationVer: version.MajorMinor(1, 3),
expectedKubeEmulationVer: defaultKubeEffectiveVersion.BinaryVersion(),
},
{
desc: "no mapping",
appsEmulationVer: version.MajorMinor(2, 10),
},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
mappedKubeEmulationVer := AppsVersionToKubeVersion(tc.appsEmulationVer)
assert.True(t, mappedKubeEmulationVer.EqualTo(tc.expectedKubeEmulationVer))
})
}
}