mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-01 19:41:57 +00:00
39 lines
1.5 KiB
Go
39 lines
1.5 KiB
Go
package jsplugin
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestPluginCLI(t *testing.T) {
|
|
tempDir := t.TempDir()
|
|
pluginPath := filepath.Join(tempDir, "fixture.js")
|
|
fixturePath := filepath.Join(tempDir, "fixture.json")
|
|
require.NoError(t, os.WriteFile(pluginPath, []byte(cliFixturePluginSource), 0o600))
|
|
require.NoError(t, os.WriteFile(fixturePath, []byte(`{"unixNow":42,"cases":[{"hook":"value","args":[],"expected":42}]}`), 0o600))
|
|
|
|
var stdout bytes.Buffer
|
|
var stderr bytes.Buffer
|
|
assert.Equal(t, 0, RunCLI([]string{"lint", pluginPath}, &stdout, &stderr))
|
|
assert.Contains(t, stdout.String(), "plugin cli-fixture@1.0.0 is valid")
|
|
assert.Empty(t, stderr.String())
|
|
|
|
stdout.Reset()
|
|
assert.Equal(t, 0, RunCLI([]string{"test", pluginPath, "--fixture", fixturePath}, &stdout, &stderr))
|
|
assert.Contains(t, stdout.String(), "1/1 cases")
|
|
}
|
|
|
|
const cliFixturePluginSource = `
|
|
export const meta = { apiVersion: 1, key: "cli-fixture", name: "CLI Fixture", version: "1.0.0", author: {name: "Test"}, channelTypes: [1003], models: ["fixture-model"], fetchMode: "per_task" };
|
|
export function buildSubmitRequest(ctx) { return {url: ctx.baseUrl}; }
|
|
export function parseSubmitResponse(ctx, resp) { return {taskId: "task"}; }
|
|
export function buildQueryRequest(ctx) { return {url: ctx.baseUrl}; }
|
|
export function parseTaskResult(ctx, body) { return body; }
|
|
export function value() { return utils.unixNow(); }
|
|
`
|