go.mod and test hygiene · Entire

go.mod and test hygiene

6b45fb8→main·

Soph·1mo ago·4 files·+28 added/-32 removed

Four small hygiene fixes flagged in review:

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

Sessions

3456387d7a8aView transcript

Changes

4

func (r SyncRequest) Validate() error {
 if r.Source.URL == "" {
 return errors.New("source URL is required")
 }
 if r.Target.URL == "" {
 return errors.New("target URL is required")
 }
 if err := validateOperationMode(r.Policy.Mode); err != nil {
 return err
 }
 if err := r.Policy.Validate(); err != nil {
 return err
 }
 if _, err := validation.NormalizeProtocolMode(string(r.Policy.Protocol)); err != nil {
 return fmt.Errorf("normalize protocol: %w", err)
 }
 if _, err := validation.ValidateMappings(validationMappings(r.Scope.Mappings), r.Scope.AllRefs); err != nil {
 return fmt.Errorf("validate mappings: %w", err)
 }
 return nil
}

func (r PlanRequest) Validate() error {
 if r.Source.URL == "" {
 return validateSyncFields(r.Source, r.Target, r.Scope, r.Policy)
 }
}

// validateSyncFields validates the fields shared by SyncRequest and
// PlanRequest, whose Validate methods are otherwise identical.
func validateSyncFields(source, target Endpoint, scope RefScope, policy SyncPolicy) error {
 if source.URL == "" {
 return errors.New("source URL is required")
 }
 if target.URL == "" {
 return errors.New("target URL is required")
 }
 if err := validateOperationMode(policy.Mode); err != nil {
 return err
 }
 if err := policy.Validate(); err != nil {
 return err
 }
 if _, err := validation.NormalizeProtocolMode(string(policy.Protocol)); err != nil {
 return fmt.Errorf("normalize protocol: %w", err)
 }
 if _, err := validation.ValidateMappings(validationMappings(scope.Mappings), scope.AllRefs); err != nil {
 return fmt.Errorf("validate mappings: %w", err)
 }
 return nil
}

Mclient.go+13/-25

w.Header().Set("Content-Type", fmt.Sprintf("application/x-%s-advertisement", service))
 if _, err := w.Write(buf.Bytes()); err != nil {
 s.tb.Fatalf("write advertised refs: %v", err)
 s.tb.Errorf("write advertised refs: %v", err)
 }
}

Mclient_test.go+4/-4

import (
 "context"
 "net/http"
 "time"

"entire.io/entire/git-sync"
)

if _, err := client.Sync(context.Background(), gitsync.SyncRequest{
 // Bound the call with a context deadline so it can't hang on network I/O
 // when go test runs this example. The hosts below are RFC 2606 reserved
 // names that don't resolve, so the call fails fast and prints nothing.
 ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
 defer cancel()

if _, err := client.Sync(ctx, gitsync.SyncRequest{
 Source: gitsync.Endpoint{URL: "https://github.example/source/repo.git"},
 Target: gitsync.Endpoint{URL: "https://git.example/target/repo.git"},
 Scope:  gitsync.RefScope{Branches: []string{"main"}},
 }); err != nil {
 return // network error expected in example environment
 }

// Output:
}

Mexample_test.go+8/-2

module entire.io/entire/git-sync

go 1.26.2
go 1.26

toolchain go1.26.2

require (
 github.com/go-git/go-billy/v6 v6.0.0-alpha.1
)

Mgo.mod+3/-1