Teach stubmaker how to work with methods, not just funcs. (#23634)

Teach stubmaker how to work with methods, not just funcs.  Fix some stubs defined in #23557 which either had the wrong signature or needed to be public.
This commit is contained in:
Nick Cabatoff
2023-10-12 14:38:28 -04:00
committed by GitHub
parent 7872338ec1
commit e232da5ffa
4 changed files with 19 additions and 12 deletions

View File

@@ -5,6 +5,7 @@ package http
import (
"net/http"
"github.com/hashicorp/vault/sdk/logical"
"github.com/hashicorp/vault/vault"
)
@@ -18,4 +19,5 @@ func entWrapGenericHandler(core *vault.Core, in http.Handler, props *vault.Handl
func entAdditionalRoutes(mux *http.ServeMux, core *vault.Core) {}
func entAdjustResponse() {}
func entAdjustResponse(core *vault.Core, w http.ResponseWriter, req *logical.Request) {
}

View File

@@ -12,11 +12,14 @@ import (
"io"
"os"
"path/filepath"
"regexp"
"sort"
"strings"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/go-hclog"
"golang.org/x/tools/go/packages"
)
@@ -225,21 +228,23 @@ func isStubNeeded(funcs []string) (bool, error) {
case len(found) == len(funcs):
return false, nil
case len(found) != 0:
return false, fmt.Errorf("funcs partially defined: need=%v, found=%v", funcs, found)
sort.Strings(found)
sort.Strings(funcs)
delta := cmp.Diff(found, funcs)
return false, fmt.Errorf("funcs partially defined, delta=%s", delta)
}
return true, nil
}
var funcRE = regexp.MustCompile("^func *(?:[(][^)]+[)])? *([^(]+)")
func getFuncs(inputLines []string) []string {
var funcs []string
for _, line := range inputLines {
trimmed := strings.TrimSpace(line)
if strings.HasPrefix(trimmed, "func ") {
i := strings.Index(trimmed, "(")
if i != -1 {
funcs = append(funcs, trimmed[5:i])
}
matches := funcRE.FindStringSubmatch(line)
if len(matches) > 1 {
funcs = append(funcs, matches[1])
}
}
return funcs

View File

@@ -191,9 +191,9 @@ var (
LicenseAutoloaded = func(*Core) bool { return false }
// TODO remove once entCheckLicenseInit is implemented in ENT
LicenseInitCheck = func(*Core) error { return nil }
// TODO remove once entGetLicenseState is implemented in ENT
// TODO remove once EntGetLicenseState is implemented in ENT
LicenseSummary = func(*Core) (*LicenseState, error) { return nil, nil }
// TODO remove once entReloadLicense is implemented in ENT
// TODO remove once EntReloadLicense is implemented in ENT
LicenseReload = func(*Core) error { return nil }
)

View File

@@ -22,11 +22,11 @@ func (c *Core) entCheckLicenseInit() error {
return nil
}
func (c *Core) entGetLicenseState() (*LicenseState, error) {
func (c *Core) EntGetLicenseState() (*LicenseState, error) {
return nil, nil
}
func (c *Core) entReloadLicense() error {
func (c *Core) EntReloadLicense() error {
return nil
}