Files
dify-plugin-daemon/pkg/plugin_packager/decoder/helper_test.go
Yeuoly 280caa3ae0 Fix/windows remap assets (#212)
* refactor(plugin_packager): update Assets method to use OS-independent path separator

- Modified the Assets method in FSPluginDecoder and PluginDecoderHelper to accept a separator argument, ensuring compatibility across different operating systems.
- Updated the Assets method in ZipPluginDecoder to use '/' as the separator for zip files, addressing issue #166.
- Improved code readability by adjusting formatting in the ZipPluginDecoder struct.

* fix: add tests
2025-04-16 17:51:17 +08:00

82 lines
1.9 KiB
Go

package decoder
import (
"testing"
"github.com/langgenius/dify-plugin-daemon/pkg/entities/plugin_entities"
"github.com/stretchr/testify/assert"
)
type UnixPluginDecoder struct {
PluginDecoder
PluginDecoderHelper
}
func (d *UnixPluginDecoder) ReadFile(filename string) ([]byte, error) {
return []byte("test"), nil
}
func (d *UnixPluginDecoder) ReadDir(dirname string) ([]string, error) {
return []string{
"_assets/test.txt",
"_assets/test2.txt",
}, nil
}
func (d *UnixPluginDecoder) Close() error {
return nil
}
func (d *UnixPluginDecoder) Assets() (map[string][]byte, error) {
return d.PluginDecoderHelper.Assets(d, "/")
}
func (d *UnixPluginDecoder) CheckAssetsValid() error {
return nil
}
func (d *UnixPluginDecoder) Checksum() (string, error) {
return "", nil
}
func (d *UnixPluginDecoder) Manifest() (plugin_entities.PluginDeclaration, error) {
return plugin_entities.PluginDeclaration{}, nil
}
func (d *UnixPluginDecoder) UniqueIdentity() (plugin_entities.PluginUniqueIdentifier, error) {
return plugin_entities.PluginUniqueIdentifier(""), nil
}
type WindowsPluginDecoder struct {
UnixPluginDecoder
}
func (d *WindowsPluginDecoder) ReadDir(dirname string) ([]string, error) {
return []string{
"_assets\\test.txt",
"_assets\\test2.txt",
}, nil
}
func (d *WindowsPluginDecoder) Assets() (map[string][]byte, error) {
return d.PluginDecoderHelper.Assets(d, "\\")
}
func TestRemapAssets(t *testing.T) {
decoder := UnixPluginDecoder{}
remappedAssets, err := decoder.Assets()
if err != nil {
t.Fatalf("Failed to remap assets: %v", err)
}
assert.Equal(t, remappedAssets["test.txt"], []byte("test"))
assert.Equal(t, remappedAssets["test2.txt"], []byte("test"))
decoder1 := WindowsPluginDecoder{}
remappedAssets, err = decoder1.Assets()
if err != nil {
t.Fatalf("Failed to remap assets: %v", err)
}
assert.Equal(t, remappedAssets["test.txt"], []byte("test"))
assert.Equal(t, remappedAssets["test2.txt"], []byte("test"))
}