golang.org/x/build@v0.0.0-20240506185731-218518f32b70/cmd/makemac/macservice.go (about)

     1  // Copyright 2024 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"log"
     9  
    10  	"golang.org/x/build/internal/macservice"
    11  )
    12  
    13  // Interface matching macservice.Client to use for test mocking.
    14  type macServiceClient interface {
    15  	Lease(macservice.LeaseRequest) (macservice.LeaseResponse, error)
    16  	Renew(macservice.RenewRequest) (macservice.RenewResponse, error)
    17  	Vacate(macservice.VacateRequest) error
    18  	Find(macservice.FindRequest) (macservice.FindResponse, error)
    19  }
    20  
    21  // readOnlyMacServiceClient wraps a macServiceClient, logging instead of
    22  // performing mutating actions. Used for dry run mode.
    23  type readOnlyMacServiceClient struct {
    24  	mc macServiceClient
    25  }
    26  
    27  func (r readOnlyMacServiceClient) Lease(req macservice.LeaseRequest) (macservice.LeaseResponse, error) {
    28  	log.Printf("DRY RUN: Create lease with image %s", req.InstanceSpecification.DiskSelection.ImageHashes.BootSHA256)
    29  	return macservice.LeaseResponse{
    30  		PendingLease: macservice.Lease{LeaseID: "dry-run-lease"},
    31  	}, nil
    32  }
    33  
    34  func (r readOnlyMacServiceClient) Renew(req macservice.RenewRequest) (macservice.RenewResponse, error) {
    35  	log.Printf("DRY RUN: Renew lease %s with duration %s", req.LeaseID, req.Duration)
    36  	return macservice.RenewResponse{}, nil // Perhaps fake RenewResponse.Expires?
    37  }
    38  
    39  func (r readOnlyMacServiceClient) Vacate(req macservice.VacateRequest) error {
    40  	log.Printf("DRY RUN: Vacate lease %s", req.LeaseID)
    41  	return nil
    42  }
    43  
    44  func (r readOnlyMacServiceClient) Find(req macservice.FindRequest) (macservice.FindResponse, error) {
    45  	return r.mc.Find(req)
    46  }