Deluan Quintão 5a5311a9c0
fix(plugins): make generated mock stubs nil-safe for nilable returns (#5909)
The ndpgen mock accessors asserted return types unconditionally, so a plugin
test using Return(nil, ...) — the natural way to model an empty result or a
pagination terminal page — panicked on the untyped-nil type assertion instead
of returning the zero value. Guard pointer, slice, map and any returns in both
the host-service client stubs and the PDK stub, and regenerate.
2026-08-08 21:57:44 -04:00

65 lines
2.0 KiB
Cheetah

// Code generated by ndpgen. DO NOT EDIT.
//
// This file contains mock implementations for non-WASM builds.
// These mocks allow IDE support, compilation, and unit testing on non-WASM platforms.
// Plugin authors can use the exported mock instances to set expectations in tests.
//
//go:build !wasip1
package {{.Package}}
import (
{{- if .Service.ImportsSharedTypes}}
"github.com/navidrome/navidrome/plugins/pdk/go/types"
{{- end}}
"github.com/stretchr/testify/mock"
)
{{- /* Generate deprecated shared-type aliases */ -}}
{{- range .Service.SharedAliases}}
{{- if .Doc}}
{{formatDoc .Doc}}
{{- end}}
type {{.Name}} = {{.Target}}
{{- end}}
{{- /* Generate struct definitions (same as main file, needed for type references in function signatures) */ -}}
{{- range .Service.Structs}}
// {{.Name}} represents the {{.Name}} data structure.
{{- if .Doc}}
{{formatDoc .Doc}}
{{- end}}
type {{.Name}} struct {
{{- range .Fields}}
{{.Name}} {{.Type}} `json:"{{.JSONTag}}"`
{{- end}}
}
{{- end}}
// mock{{.Service.Name}}Service is the mock implementation for testing.
type mock{{.Service.Name}}Service struct {
mock.Mock
}
// {{.Service.Name}}Mock is the auto-instantiated mock instance for testing.
// Use this to set expectations: host.{{.Service.Name}}Mock.On("MethodName", args...).Return(values...)
var {{.Service.Name}}Mock = &mock{{.Service.Name}}Service{}
{{range .Service.Methods}}
// {{.Name}} is the mock method for {{$.Service.Name}}{{.Name}}.
func (m *mock{{$.Service.Name}}Service) {{.Name}}({{range $i, $p := .Params}}{{if $i}}, {{end}}{{$p.Name}} {{$p.Type}}{{end}}) {{.ReturnSignature}} {
args := m.Called({{range $i, $p := .Params}}{{if $i}}, {{end}}{{$p.Name}}{{end}})
{{mockReturnBody .}}
}
// {{$.Service.Name}}{{.Name}} delegates to the mock instance.
{{- if .Doc}}
{{formatDoc .Doc}}
{{- end}}
func {{$.Service.Name}}{{.Name}}({{range $i, $p := .Params}}{{if $i}}, {{end}}{{$p.Name}} {{$p.Type}}{{end}}) {{.ReturnSignature}} {
return {{$.Service.Name}}Mock.{{.Name}}({{range $i, $p := .Params}}{{if $i}}, {{end}}{{$p.Name}}{{end}})
}
{{- end}}