Skip to content

Commit

Permalink
review changes:
Browse files Browse the repository at this point in the history
* changed errors formatting with less details
* regenerated mocks
  • Loading branch information
tulzke committed Sep 24, 2024
1 parent 6ac4347 commit c630751
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 56 deletions.
6 changes: 3 additions & 3 deletions mockgen/import_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (p *importModeParser) extractInterfacesFromPackage(pkg *packages.Package, i

modelIface, err := p.parseInterface(obj)
if err != nil {
return nil, newParseTypeError("parse interface", obj.String(), err)
return nil, newParseTypeError("parse interface", obj.Name(), err)
}

interfaces[i] = modelIface
Expand All @@ -92,12 +92,12 @@ func (p *importModeParser) extractInterfacesFromPackage(pkg *packages.Package, i
func (p *importModeParser) parseInterface(obj types.Object) (*model.Interface, error) {
named, ok := types.Unalias(obj.Type()).(*types.Named)
if !ok {
return nil, fmt.Errorf("%s is not an interface. it is a %s", obj.Name(), obj.Type().Underlying().String())
return nil, fmt.Errorf("%s is not an interface. it is a %T", obj.Name(), obj.Type().Underlying())
}

iface, ok := named.Underlying().(*types.Interface)
if !ok {
return nil, fmt.Errorf("%s is not an interface. it is a %s", obj.Name(), obj.Type().Underlying().String())
return nil, fmt.Errorf("%s is not an interface. it is a %T", obj.Name(), obj.Type().Underlying())
}

if p.isConstraint(iface) {
Expand Down
6 changes: 3 additions & 3 deletions mockgen/import_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func Test_importModeParser_parsePackage(t *testing.T) {
ifaces: []string{"Work"},
},
expectedErr: "extract interfaces from package: parse interface: " +
"error parsing type go.uber.org/mock/mockgen/internal/tests/import_mode.Work struct{Name string}: " +
"Work is not an interface. it is a struct{Name string}",
"error parsing Work: " +
"Work is not an interface. it is a *types.Struct",
},
{
name: "error: search for constraint instead of interface",
Expand All @@ -51,7 +51,7 @@ func Test_importModeParser_parsePackage(t *testing.T) {
ifaces: []string{"Counter"},
},
expectedErr: "extract interfaces from package: parse interface: " +
"error parsing type go.uber.org/mock/mockgen/internal/tests/import_mode.Counter interface{int}: " +
"error parsing Counter: " +
"interface Counter is a constraint",
},
{
Expand Down
60 changes: 10 additions & 50 deletions mockgen/internal/tests/import_mode/mock/interfaces.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c630751

Please sign in to comment.