-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds Orbstack Container Runtime Engine #1761
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,17 @@ import ( | |
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
// mockFileChecker is a mock implementation of FileChecker for tests in this file. | ||
type mockFileChecker struct { | ||
ExistingFiles map[string]bool | ||
} | ||
|
||
// FileExists is just a mock for os.Stat(). In our test implementation, we just check | ||
// if the file exists in the list of mocked files for a given test. | ||
func (m mockFileChecker) FileExists(path string) bool { | ||
return m.ExistingFiles[path] | ||
} | ||
|
||
Comment on lines
+14
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this special mock here to live with its specific tests. I've also configured mockery to now generate a more standard mock under |
||
type ContainerRuntimeSuite struct { | ||
suite.Suite | ||
} | ||
|
@@ -142,8 +153,9 @@ func (s *ContainerRuntimeSuite) TestGetContainerRuntimeBinary() { | |
|
||
for _, tt := range tests { | ||
s.Run(tt.name, func() { | ||
mockChecker := mocks.FileChecker{ExistingFiles: tt.mockFiles} | ||
result := FindBinary(tt.pathEnv, tt.binary, mockChecker, new(osChecker)) | ||
mockChecker := mockFileChecker{ExistingFiles: tt.mockFiles} | ||
inspector := CreateHostInspector(CreateOSChecker(), mockChecker, CreateEnvChecker()) | ||
result := FindBinary(tt.pathEnv, tt.binary, inspector) | ||
s.Equal(tt.expected, result) | ||
}) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package runtimes | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
type EnvChecker interface { | ||
GetEnvVar(string) string | ||
} | ||
|
||
type envChecker struct{} | ||
|
||
func CreateEnvChecker() EnvChecker { | ||
return new(envChecker) | ||
} | ||
|
||
// GetEnvVar returns the value of the specified environment variable. | ||
func (o envChecker) GetEnvVar(string) string { | ||
return os.Getenv("PATH") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package runtimes | ||
|
||
type HostInterrogator interface { | ||
IsMac() bool | ||
IsWindows() bool | ||
FileExists(string) bool | ||
GetEnvVar(string) string | ||
} | ||
|
||
type hostInterrogator struct { | ||
OSChecker | ||
FileChecker | ||
EnvChecker | ||
} | ||
|
||
func CreateHostInspector(osChecker OSChecker, fileChecker FileChecker, envChecker EnvChecker) HostInterrogator { | ||
return hostInterrogator{ | ||
osChecker, | ||
fileChecker, | ||
envChecker, | ||
} | ||
} | ||
|
||
func CreateHostInspectorWithDefaults() HostInterrogator { | ||
return hostInterrogator{ | ||
CreateOSChecker(), | ||
CreateFileChecker(), | ||
CreateEnvChecker(), | ||
} | ||
} | ||
Comment on lines
+1
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of passing all 3 of these implementations around, I've consolidated them into a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of specifying these concrete implementations out here, we've added new constructor functions to construct with the default concrete implementations. This lets us encapsulate the new logic to determine the specific
Engine
to plug in.