mirror of
https://github.com/navidrome/navidrome.git
synced 2025-08-10 00:52:20 +00:00
Some checks failed
Close stale issues and PRs / stale (push) Has been cancelled
Pipeline: Test, Lint, Build / Get version info (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test JS code (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint i18n files (push) Has been cancelled
Pipeline: Test, Lint, Build / Check Docker configuration (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (darwin/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (darwin/arm64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/386) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v5) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v6) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v7) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (windows/386) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (windows/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Push Docker manifest (push) Has been cancelled
Pipeline: Test, Lint, Build / Build Windows installers (push) Has been cancelled
Pipeline: Test, Lint, Build / Package/Release (push) Has been cancelled
Pipeline: Test, Lint, Build / Upload Linux PKG (push) Has been cancelled
POEditor import / update-translations (push) Has been cancelled
Added Ginkgo/Gomega tests for userName and AbsolutePath functions in core/common.go. Tests cover normal and error cases, using existing mocks and helpers. This improves coverage and ensures correct behavior for user context extraction and library path resolution.
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package core
|
|
|
|
import (
|
|
"context"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
|
|
"github.com/navidrome/navidrome/model"
|
|
"github.com/navidrome/navidrome/model/request"
|
|
"github.com/navidrome/navidrome/tests"
|
|
)
|
|
|
|
var _ = Describe("common.go", func() {
|
|
Describe("userName", func() {
|
|
It("returns the username from context", func() {
|
|
ctx := request.WithUser(context.Background(), model.User{UserName: "testuser"})
|
|
Expect(userName(ctx)).To(Equal("testuser"))
|
|
})
|
|
|
|
It("returns 'UNKNOWN' if no user in context", func() {
|
|
ctx := context.Background()
|
|
Expect(userName(ctx)).To(Equal("UNKNOWN"))
|
|
})
|
|
})
|
|
|
|
Describe("AbsolutePath", func() {
|
|
var (
|
|
ds *tests.MockDataStore
|
|
libId int
|
|
path string
|
|
)
|
|
|
|
BeforeEach(func() {
|
|
ds = &tests.MockDataStore{}
|
|
libId = 1
|
|
path = "music/file.mp3"
|
|
mockLib := &tests.MockLibraryRepo{}
|
|
mockLib.SetData(model.Libraries{{ID: libId, Path: "/library/root"}})
|
|
ds.MockedLibrary = mockLib
|
|
})
|
|
|
|
It("returns the absolute path when library exists", func() {
|
|
ctx := context.Background()
|
|
abs := AbsolutePath(ctx, ds, libId, path)
|
|
Expect(abs).To(Equal("/library/root/music/file.mp3"))
|
|
})
|
|
|
|
It("returns the original path if library not found", func() {
|
|
ctx := context.Background()
|
|
abs := AbsolutePath(ctx, ds, 999, path)
|
|
Expect(abs).To(Equal(path))
|
|
})
|
|
})
|
|
})
|