-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test pkg and mock server for traceectl
- Loading branch information
Showing
7 changed files
with
41 additions
and
235 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package test | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net" | ||
"os" | ||
) | ||
|
||
const DefaultSocket = "/tmp/tracee.sock" | ||
|
||
type Server struct { | ||
addr string | ||
listener net.Listener | ||
} | ||
|
||
func SetupMockSocket() (*Server, error) { | ||
listener, err := net.Listen("unix", DefaultSocket) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &Server{ | ||
addr: DefaultSocket, | ||
listener: listener, | ||
}, nil | ||
} | ||
|
||
func (s *Server) TeardownMockSocket() error { | ||
if s.listener != nil { | ||
if err := s.listener.Close(); err != nil { | ||
return fmt.Errorf("failed to close mock socket: %w", err) // Wrap the error | ||
} | ||
} | ||
// Check if the socket file still exists and remove it | ||
if _, err := os.Stat(DefaultSocket); err == nil { | ||
if err := os.Remove(DefaultSocket); err != nil { | ||
log.Printf("Warning: failed to remove mock socket file: %v", err) | ||
} | ||
} | ||
return nil | ||
} |