mirror of
https://github.com/navidrome/navidrome.git
synced 2025-12-23 23:18:05 -05:00
* chore: .gitignore any navidrome binary Signed-off-by: Deluan <deluan@navidrome.org> * feat: implement internal authentication handling in middleware Signed-off-by: Deluan <deluan@navidrome.org> * feat(manager): add SubsonicRouter to Manager for API routing Signed-off-by: Deluan <deluan@navidrome.org> * feat(plugins): add SubsonicAPI Host service for plugins and an example plugin Signed-off-by: Deluan <deluan@navidrome.org> * fix lint Signed-off-by: Deluan <deluan@navidrome.org> * feat(plugins): refactor path handling in SubsonicAPI to extract endpoint correctly Signed-off-by: Deluan <deluan@navidrome.org> * docs(plugins): add SubsonicAPI service documentation to README Signed-off-by: Deluan <deluan@navidrome.org> * feat(plugins): implement permission checks for SubsonicAPI service Signed-off-by: Deluan <deluan@navidrome.org> * feat(plugins): enhance SubsonicAPI service initialization with atomic router handling Signed-off-by: Deluan <deluan@navidrome.org> * refactor(plugins): better encapsulated dependency injection Signed-off-by: Deluan <deluan@navidrome.org> * refactor(plugins): rename parameter in WithInternalAuth for clarity Signed-off-by: Deluan <deluan@navidrome.org> * docs(plugins): update SubsonicAPI permissions section in README for clarity and detail Signed-off-by: Deluan <deluan@navidrome.org> * feat(plugins): enhance SubsonicAPI permissions output with allowed usernames and admin flag Signed-off-by: Deluan <deluan@navidrome.org> * feat(plugins): add schema reference to example plugins Signed-off-by: Deluan <deluan@navidrome.org> * remove import alias Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org>
167 lines
5.3 KiB
Go
167 lines
5.3 KiB
Go
package plugins
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/navidrome/navidrome/plugins/host/scheduler"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("SchedulerService", func() {
|
|
var (
|
|
ss *schedulerService
|
|
manager *Manager
|
|
pluginName = "test_plugin"
|
|
)
|
|
|
|
BeforeEach(func() {
|
|
manager = createManager(nil)
|
|
ss = manager.schedulerService
|
|
})
|
|
|
|
Describe("One-time scheduling", func() {
|
|
It("schedules one-time jobs successfully", func() {
|
|
req := &scheduler.ScheduleOneTimeRequest{
|
|
DelaySeconds: 1,
|
|
Payload: []byte("test payload"),
|
|
ScheduleId: "test-job",
|
|
}
|
|
|
|
resp, err := ss.scheduleOneTime(context.Background(), pluginName, req)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(resp.ScheduleId).To(Equal("test-job"))
|
|
Expect(ss.hasSchedule(pluginName + ":" + "test-job")).To(BeTrue())
|
|
Expect(ss.getScheduleType(pluginName + ":" + "test-job")).To(Equal(ScheduleTypeOneTime))
|
|
|
|
// Test auto-generated ID
|
|
req.ScheduleId = ""
|
|
resp, err = ss.scheduleOneTime(context.Background(), pluginName, req)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(resp.ScheduleId).ToNot(BeEmpty())
|
|
})
|
|
|
|
It("cancels one-time jobs successfully", func() {
|
|
req := &scheduler.ScheduleOneTimeRequest{
|
|
DelaySeconds: 10,
|
|
ScheduleId: "test-job",
|
|
}
|
|
|
|
_, err := ss.scheduleOneTime(context.Background(), pluginName, req)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
cancelReq := &scheduler.CancelRequest{
|
|
ScheduleId: "test-job",
|
|
}
|
|
|
|
resp, err := ss.cancelSchedule(context.Background(), pluginName, cancelReq)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(resp.Success).To(BeTrue())
|
|
Expect(ss.hasSchedule(pluginName + ":" + "test-job")).To(BeFalse())
|
|
})
|
|
})
|
|
|
|
Describe("Recurring scheduling", func() {
|
|
It("schedules recurring jobs successfully", func() {
|
|
req := &scheduler.ScheduleRecurringRequest{
|
|
CronExpression: "* * * * *", // Every minute
|
|
Payload: []byte("test payload"),
|
|
ScheduleId: "test-cron",
|
|
}
|
|
|
|
resp, err := ss.scheduleRecurring(context.Background(), pluginName, req)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(resp.ScheduleId).To(Equal("test-cron"))
|
|
Expect(ss.hasSchedule(pluginName + ":" + "test-cron")).To(BeTrue())
|
|
Expect(ss.getScheduleType(pluginName + ":" + "test-cron")).To(Equal(ScheduleTypeRecurring))
|
|
|
|
// Test auto-generated ID
|
|
req.ScheduleId = ""
|
|
resp, err = ss.scheduleRecurring(context.Background(), pluginName, req)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(resp.ScheduleId).ToNot(BeEmpty())
|
|
})
|
|
|
|
It("cancels recurring jobs successfully", func() {
|
|
req := &scheduler.ScheduleRecurringRequest{
|
|
CronExpression: "* * * * *", // Every minute
|
|
ScheduleId: "test-cron",
|
|
}
|
|
|
|
_, err := ss.scheduleRecurring(context.Background(), pluginName, req)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
cancelReq := &scheduler.CancelRequest{
|
|
ScheduleId: "test-cron",
|
|
}
|
|
|
|
resp, err := ss.cancelSchedule(context.Background(), pluginName, cancelReq)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(resp.Success).To(BeTrue())
|
|
Expect(ss.hasSchedule(pluginName + ":" + "test-cron")).To(BeFalse())
|
|
})
|
|
})
|
|
|
|
Describe("Replace existing schedules", func() {
|
|
It("replaces one-time jobs with new ones", func() {
|
|
// Create first job
|
|
req1 := &scheduler.ScheduleOneTimeRequest{
|
|
DelaySeconds: 10,
|
|
Payload: []byte("test payload 1"),
|
|
ScheduleId: "replace-job",
|
|
}
|
|
_, err := ss.scheduleOneTime(context.Background(), pluginName, req1)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
// Verify that the initial job exists
|
|
scheduleId := pluginName + ":" + "replace-job"
|
|
Expect(ss.hasSchedule(scheduleId)).To(BeTrue(), "Initial schedule should exist")
|
|
|
|
beforeCount := ss.scheduleCount()
|
|
|
|
// Replace with second job using same ID
|
|
req2 := &scheduler.ScheduleOneTimeRequest{
|
|
DelaySeconds: 60, // Use a longer delay to ensure it doesn't execute during the test
|
|
Payload: []byte("test payload 2"),
|
|
ScheduleId: "replace-job",
|
|
}
|
|
|
|
_, err = ss.scheduleOneTime(context.Background(), pluginName, req2)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Eventually(func() bool {
|
|
return ss.hasSchedule(scheduleId)
|
|
}).Should(BeTrue(), "Schedule should exist after replacement")
|
|
Expect(ss.scheduleCount()).To(Equal(beforeCount), "Job count should remain the same after replacement")
|
|
})
|
|
|
|
It("replaces recurring jobs with new ones", func() {
|
|
// Create first job
|
|
req1 := &scheduler.ScheduleRecurringRequest{
|
|
CronExpression: "0 * * * *",
|
|
Payload: []byte("test payload 1"),
|
|
ScheduleId: "replace-cron",
|
|
}
|
|
_, err := ss.scheduleRecurring(context.Background(), pluginName, req1)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
beforeCount := ss.scheduleCount()
|
|
|
|
// Replace with second job using same ID
|
|
req2 := &scheduler.ScheduleRecurringRequest{
|
|
CronExpression: "*/5 * * * *",
|
|
Payload: []byte("test payload 2"),
|
|
ScheduleId: "replace-cron",
|
|
}
|
|
|
|
_, err = ss.scheduleRecurring(context.Background(), pluginName, req2)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Eventually(func() bool {
|
|
return ss.hasSchedule(pluginName + ":" + "replace-cron")
|
|
}).Should(BeTrue(), "Schedule should exist after replacement")
|
|
Expect(ss.scheduleCount()).To(Equal(beforeCount), "Job count should remain the same after replacement")
|
|
})
|
|
})
|
|
})
|