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>
54 lines
1015 B
Go
54 lines
1015 B
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package resource
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
type dummyDownloader struct {
|
|
typ string
|
|
}
|
|
|
|
func (d *dummyDownloader) Download(ctx context.Context, url, destPath string) error {
|
|
return nil
|
|
}
|
|
|
|
func (d *dummyDownloader) Type() string {
|
|
return d.typ
|
|
}
|
|
|
|
func TestRegistry(t *testing.T) {
|
|
reg := NewRegistry()
|
|
|
|
// Initially empty
|
|
if len(reg.SupportedTypes()) != 0 {
|
|
t.Fatalf("expected 0 supported types, got %d", len(reg.SupportedTypes()))
|
|
}
|
|
|
|
// Register a downloader
|
|
d1 := &dummyDownloader{typ: "test1"}
|
|
reg.Register(d1)
|
|
|
|
if len(reg.SupportedTypes()) != 1 {
|
|
t.Fatalf("expected 1 supported type, got %d", len(reg.SupportedTypes()))
|
|
}
|
|
|
|
// Get the downloader
|
|
got, err := reg.Get("test1")
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if got != d1 {
|
|
t.Fatalf("expected to get identical downloader")
|
|
}
|
|
|
|
// Unknown type
|
|
_, err = reg.Get("test2")
|
|
if err == nil {
|
|
t.Fatalf("expected error for unknown type")
|
|
}
|
|
}
|