Rediscover Go settings only when Go work needs them
This commit is contained in:
@@ -53,13 +53,9 @@ func Check(ctx context.Context, request Request) (Candidate, error) {
|
||||
}
|
||||
if request.AfterValidate != nil {
|
||||
callbackErr := request.AfterValidate(ctx, captured, request.ToolOwner)
|
||||
refreshErr := request.ToolOwner.Refresh(ctx)
|
||||
if callbackErr != nil {
|
||||
return captured, fmt.Errorf("after candidate validation: %w", callbackErr)
|
||||
}
|
||||
if refreshErr != nil {
|
||||
return captured, fmt.Errorf("refresh Go settings after candidate callback: %w", refreshErr)
|
||||
}
|
||||
}
|
||||
if err := Recheck(ctx, captured, ""); err != nil {
|
||||
return captured, err
|
||||
@@ -143,13 +139,9 @@ func Validate(ctx context.Context, request Request, captured Candidate) error {
|
||||
}
|
||||
if request.AdditionalChecks != nil {
|
||||
callbackErr := request.AdditionalChecks(ctx, captured)
|
||||
refreshErr := owner.Refresh(ctx)
|
||||
if callbackErr != nil {
|
||||
return fmt.Errorf("validate candidate %s: %w", captured.Commit, callbackErr)
|
||||
}
|
||||
if refreshErr != nil {
|
||||
return fmt.Errorf("refresh Go settings after additional checks: %w", refreshErr)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -304,6 +304,28 @@ func TestCheckRefreshesGoSettingsAfterAdditionalChecks(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckNeedsNoGoDiscoveryAfterFinalCallback(t *testing.T) {
|
||||
repository := newRepository(t, "# Example Product v1.2.3\n\nRelease note.\n")
|
||||
gitPath, err := exec.LookPath("git")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
gitOnly := t.TempDir()
|
||||
if err := os.Symlink(gitPath, filepath.Join(gitOnly, "git")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = Check(context.Background(), Request{
|
||||
RepositoryDir: repository, Product: "Example Product", Version: testVersion,
|
||||
AfterValidate: func(context.Context, Candidate, *gotool.Owner) error {
|
||||
t.Setenv("PATH", gitOnly)
|
||||
return nil
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("completed Go work was rediscovered after final callback: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckSharesGoDiscoveryWithAfterValidateCallback(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("the controlled Go command fixture uses a POSIX shell")
|
||||
|
||||
Reference in New Issue
Block a user