Merge pull request #93 from entireio/fix/gomod-and-test-hygiene · Entire

Merge pull request #93 from entireio/fix/gomod-and-test-hygiene

ad8bcbe→main·

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

Changes

4

143 unmodified lines
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
189 unmodified lines
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)
}
w.Header().Set("Content-Type", "application/x-git-upload-pack-result")
if _, err := w.Write(buf.Bytes()); err != nil {
    s.tb.Fatalf("write upload-pack response: %v", err)
    s.tb.Errorf("write upload-pack response: %v", err)
}
w.Header().Set("Content-Type", "application/x-git-receive-pack-result")
if _, err := w.Write(buf.Bytes()); err != nil {
    s.tb.Fatalf("write receive-pack response: %v", err)
    s.tb.Errorf("write receive-pack response: %v", err)
}
Mclient_test.go+4/-4
2 unmodified lines
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
    }
}
Mexample_test.go+8/-2
1
2
3

module entire.io/entire/git-sync

go 1.26.2

toolchain go1.26.2

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