MCPcopy
hub / github.com/vektra/mockery / Append

Method Append

internal/cmd/mockery.go:144–179  ·  view source on GitHub ↗
(ctx context.Context, iface *internal.Interface)

Source from the content-addressed store, hash-verified

142}
143
144func (i *InterfaceCollection) Append(ctx context.Context, iface *internal.Interface) error {
145 collectionFilepath := i.config.OutFilePath
146 interfaceFilepath := iface.Config.FilePath()
147 log := zerolog.Ctx(ctx).With().
148 Str(logging.LogKeyInterface, iface.Name).
149 Str("collection-pkgname", i.config.OutPkgName).
150 Str("interface-pkgname", *iface.Config.PkgName).
151 Str("collection-pkgpath", i.config.SrcPkgPath).
152 Str("interface-pkgpath", iface.Pkg.PkgPath).
153 Str("collection-filepath", collectionFilepath).
154 Str("interface-filepath", interfaceFilepath).
155 Logger()
156
157 if collectionFilepath != interfaceFilepath {
158 msg := "all mocks in an InterfaceCollection must have the same output file path"
159 log.Error().Msg(msg)
160 return errors.New(msg)
161 }
162 if i.config.OutPkgName != *iface.Config.PkgName {
163 msg := "all mocks in an output file must have the same pkgname"
164 log.Error().Str("interface-pkgname", *iface.Config.PkgName).Msg(msg)
165 return errors.New(msg)
166 }
167 if i.config.SrcPkgPath != iface.Pkg.PkgPath {
168 msg := "all mocks in an output file must come from the same source package"
169 log.Error().Msg(msg)
170 return errors.New(msg)
171 }
172 if i.config.Template != *iface.Config.Template {
173 msg := "all mocks in an output file must use the same template"
174 log.Error().Str("expected-template", i.config.Template).Str("interface-template", *iface.Config.Template).Msg(msg)
175 return errors.New(msg)
176 }
177 i.interfaces = append(i.interfaces, iface)
178 return nil
179}
180
181func writeFile(path string, data []byte) error {
182 f, err := os.Create(path)

Callers 1

RunMethod · 0.45

Calls 2

FilePathMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected