mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +00:00
c59a413765
CI / lint (push) Has been cancelled
CI / test (agent) (push) Has been cancelled
CI / test (cli) (push) Has been cancelled
CI / test (cmd) (push) Has been cancelled
CI / test (internal) (push) Has been cancelled
CI / test (manager, true) (push) Has been cancelled
CI / test (pkg) (push) Has been cancelled
CI / upload-coverage (push) Has been cancelled
* feat: implement extensible resource downloader framework with support for S3, GCS, and OCI sources Signed-off-by: SammyOina <sammyoina@gmail.com> * refactor: improve resource URL parsing and add support for bare OCI image references Signed-off-by: Sammy Oina <sammyoina@gmail.com> * fix: add empty string check and slash requirement for OCI image inference, and update python unit tests with event mock expectations Signed-off-by: Sammy Oina <sammyoina@gmail.com> * refactor: introduce OCIClient interface, add test coverage for decryption, and improve resource download error handling Signed-off-by: Sammy Oina <sammyoina@gmail.com> * chore: remove trailing whitespace in OCI downloader and HTTP tests Signed-off-by: Sammy Oina <sammyoina@gmail.com> --------- Signed-off-by: SammyOina <sammyoina@gmail.com> Signed-off-by: Sammy Oina <sammyoina@gmail.com>
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package resource
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/mock"
|
|
"github.com/ultravioletrs/cocos/pkg/oci"
|
|
)
|
|
|
|
type MockOCIClient struct {
|
|
mock.Mock
|
|
}
|
|
|
|
func (m *MockOCIClient) PullAndDecrypt(ctx context.Context, source oci.ResourceSource, destDir string) error {
|
|
args := m.Called(ctx, source, destDir)
|
|
return args.Error(0)
|
|
}
|
|
|
|
func (m *MockOCIClient) ToDockerArchive(ctx context.Context, ociDir, destFile string) error {
|
|
args := m.Called(ctx, ociDir, destFile)
|
|
return args.Error(0)
|
|
}
|
|
|
|
func TestOCIDownloader(t *testing.T) {
|
|
mockClient := new(MockOCIClient)
|
|
downloader := NewOCIDownloader(mockClient)
|
|
|
|
ctx := context.Background()
|
|
url := "docker://example.com/image:latest"
|
|
destDir := "/tmp/oci"
|
|
|
|
t.Run("Download", func(t *testing.T) {
|
|
expectedSource := oci.ResourceSource{
|
|
Type: oci.ResourceTypeOCIImage,
|
|
URI: url,
|
|
Encrypted: false,
|
|
}
|
|
mockClient.On("PullAndDecrypt", ctx, expectedSource, destDir).Return(nil).Once()
|
|
|
|
err := downloader.Download(ctx, url, destDir)
|
|
assert.NoError(t, err)
|
|
mockClient.AssertExpectations(t)
|
|
})
|
|
|
|
t.Run("Type", func(t *testing.T) {
|
|
assert.Equal(t, SourceTypeOCIImage, downloader.Type())
|
|
})
|
|
|
|
t.Run("Client", func(t *testing.T) {
|
|
assert.Equal(t, mockClient, downloader.Client())
|
|
})
|
|
}
|