mirror of
https://github.com/luxfi/cli.git
synced 2026-10-30 17:01:20 +00:00
74 lines
1.9 KiB
Go
74 lines
1.9 KiB
Go
// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package version
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/luxfi/cli/internal/mocks"
|
|
"github.com/luxfi/cli/pkg/application"
|
|
"github.com/luxfi/constants"
|
|
"github.com/stretchr/testify/mock"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCheckMinDependencyVersion(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
cliVersion string
|
|
expectedError bool
|
|
cliDependencyData []byte
|
|
}{
|
|
{
|
|
name: "cli version equal to minimum version",
|
|
cliVersion: "1.8.10",
|
|
cliDependencyData: []byte(`{"min-version":"1.8.10"}`),
|
|
expectedError: false,
|
|
},
|
|
{
|
|
name: "cli version higher than minimum version",
|
|
cliVersion: "1.8.11",
|
|
cliDependencyData: []byte(`{"min-version":"1.8.10"}`),
|
|
expectedError: false,
|
|
},
|
|
{
|
|
name: "cli version lower than minimum version",
|
|
cliVersion: "1.8.9",
|
|
cliDependencyData: []byte(`{"min-version":"1.8.10"}`),
|
|
expectedError: true,
|
|
},
|
|
{
|
|
name: "cli version much higher than minimum version",
|
|
cliVersion: "1.13.0",
|
|
cliDependencyData: []byte(`{"min-version":"1.8.10"}`),
|
|
expectedError: false,
|
|
},
|
|
{
|
|
name: "cli version much lower than minimum version",
|
|
cliVersion: "1.7.0",
|
|
cliDependencyData: []byte(`{"min-version":"1.8.10"}`),
|
|
expectedError: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
mockDownloader := &mocks.Downloader{}
|
|
mockDownloader.On("Download", mock.MatchedBy(func(url string) bool {
|
|
return url == constants.CLIMinVersionURL
|
|
})).Return(tt.cliDependencyData, nil)
|
|
|
|
app := application.New()
|
|
app.Downloader = mockDownloader
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := CheckCLIVersionIsOverMin(app, tt.cliVersion)
|
|
if tt.expectedError {
|
|
require.Error(t, err)
|
|
} else {
|
|
require.NoError(t, err)
|
|
}
|
|
})
|
|
}
|
|
}
|