mirror of
https://github.com/luxfi/lpm.git
synced 2026-10-30 16:20:57 +00:00
Modules declare go 1.27.1 and the build images follow. go fix applied the modernizers, and the repository lookup is now a generic method on DiskRepository; omitzero is not applied, since it changes what the JSON says. Co-authored-by: Hanzo Dev <[email protected]>
81 lines
1.8 KiB
Go
81 lines
1.8 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package workflow
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/golang/mock/gomock"
|
|
"github.com/spf13/afero"
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/luxfi/lpm/url"
|
|
)
|
|
|
|
func TestTmpInstaller_Download(t *testing.T) {
|
|
dummyErr := fmt.Errorf("something went wrong")
|
|
|
|
type mocks struct {
|
|
fs afero.Fs
|
|
client *url.MockClient
|
|
}
|
|
type args struct {
|
|
url string
|
|
path string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
setup func(mocks)
|
|
args args
|
|
wantErr assert.ErrorAssertionFunc
|
|
}{
|
|
{
|
|
name: "failure",
|
|
setup: func(mocks mocks) {
|
|
mocks.client.EXPECT().Download("tmp/file.tar.gz", "www.url.com/binary.tar.gz").Return(dummyErr)
|
|
},
|
|
args: args{
|
|
url: "www.url.com/binary.tar.gz",
|
|
path: "tmp/file.tar.gz",
|
|
},
|
|
wantErr: func(t assert.TestingT, err error, _ ...any) bool {
|
|
return assert.Equal(t, dummyErr, err)
|
|
},
|
|
},
|
|
{
|
|
name: "success",
|
|
setup: func(mocks mocks) {
|
|
mocks.client.EXPECT().Download("tmp/file.tar.gz", "www.url.com/binary.tar.gz").Return(nil)
|
|
},
|
|
args: args{
|
|
url: "www.url.com/binary.tar.gz",
|
|
path: "tmp/file.tar.gz",
|
|
},
|
|
wantErr: func(t assert.TestingT, err error, _ ...any) bool {
|
|
return assert.Nil(t, err)
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t1 *testing.T) {
|
|
ctrl := gomock.NewController(t)
|
|
fs := afero.NewMemMapFs()
|
|
client := url.NewMockClient(ctrl)
|
|
|
|
tt.setup(mocks{
|
|
fs: fs,
|
|
client: client,
|
|
})
|
|
|
|
installer := NewVMInstaller(VMInstallerConfig{
|
|
Fs: fs,
|
|
URLClient: client,
|
|
})
|
|
|
|
tt.wantErr(t1, installer.Download(tt.args.url, tt.args.path), fmt.Sprintf("Download(%v, %v)", tt.args.url, tt.args.path))
|
|
})
|
|
}
|
|
}
|