spiffe/spire
Ver no GitHubMaking code involving syscalls testable in `peertracker`
Open
#5.755 aberto em 1 de jan. de 2025
help wantedpriority/backlog
Métricas do repositório
- Stars
- (2.443 stars)
- Métricas de merge de PR
- (Métricas PR pendentes)
Description
- Version: v1.11.1
- Platform: N/A
- Subsystem: Windows syscalls in
peertracker
Relates to https://github.com/spiffe/spire/pull/5749
Some code which makes direct syscalls is hard to test, e.g. compareObjectHandles which behaves differently on different Windows systems.
One way might be to change these sorts of funcs into methods on a type that allows swapping out syscall.SyscallN and other currently global variables for something that can be overridden at test time, so that surrounding logic can be tested (example in https://github.com/spiffe/spire/pull/5749#discussion_r1898703413)
func (s syscaller) compareObjectHandles(firstHandle, secondHandle windows.Handle) error {
if s.procCompareObjectHandlesErr != nil {
return s.procCompareObjectHandlesErr
}
r1, _, e1 := s.syscallN(*s.procCompareObjectHandlesAddr, uintptr(firstHandle), uintptr(secondHandle))
if r1 == 0 {
return e1
}
return nil
}