Skip to content

Commit 426bbd3

Browse files
authored
Merge pull request #539 from data-catering/clean-lakekeeper
Clean lakekeeper
2 parents 032578a + 2419009 commit 426bbd3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3199
-3011
lines changed

cmd/insta/app_test.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,23 @@ import (
1010
// MockRuntime for testing App
1111
type MockRuntime struct {
1212
name string
13-
available bool
1413
composeUpCalled bool
1514
composeDownCalled bool
1615
execCalled bool
1716
composeFiles []string
1817
services []string
1918
lastContainer string
2019
lastCmd string
20+
portMappings map[string]map[string]string // Map service name to its port mappings
21+
dependencies map[string][]string // Map service name to its dependencies
22+
}
23+
24+
func NewMockRuntime() *MockRuntime {
25+
return &MockRuntime{
26+
name: "mock-runtime",
27+
portMappings: make(map[string]map[string]string),
28+
dependencies: make(map[string][]string),
29+
}
2130
}
2231

2332
func (m *MockRuntime) Name() string {
@@ -49,6 +58,21 @@ func (m *MockRuntime) ExecInContainer(containerName string, cmd string, interact
4958
return nil
5059
}
5160

61+
func (m *MockRuntime) GetPortMappings(containerName string) (map[string]string, error) {
62+
if mappings, ok := m.portMappings[containerName]; ok {
63+
return mappings, nil
64+
}
65+
// Return empty map for services without specific mappings or ports
66+
return map[string]string{}, nil
67+
}
68+
69+
func (m *MockRuntime) GetDependencies(service string, composeFiles []string) ([]string, error) {
70+
if deps, ok := m.dependencies[service]; ok {
71+
return deps, nil
72+
}
73+
return []string{}, nil
74+
}
75+
5276
func TestAppWithMockRuntime(t *testing.T) {
5377
// Create a temporary directory
5478
tempDir, err := os.MkdirTemp("", "app-test-*")
@@ -58,7 +82,12 @@ func TestAppWithMockRuntime(t *testing.T) {
5882
defer os.RemoveAll(tempDir)
5983

6084
// Setup App with mock runtime
61-
mockRuntime := &MockRuntime{name: "mock-runtime"}
85+
mockRuntime := NewMockRuntime()
86+
87+
// Add some port mappings to the mock runtime
88+
mockRuntime.portMappings["postgres"] = map[string]string{"5432/tcp": "5432"}
89+
mockRuntime.portMappings["mysql"] = map[string]string{"3306/tcp": "3306"} // Example for mysql
90+
6291
app := &App{
6392
dataDir: filepath.Join(tempDir, "data"),
6493
instaDir: tempDir,
@@ -67,6 +96,10 @@ func TestAppWithMockRuntime(t *testing.T) {
6796

6897
// Test starting services
6998
t.Run("start services", func(t *testing.T) {
99+
// Clear existing mock data for this subtest if needed
100+
mockRuntime.composeUpCalled = false
101+
mockRuntime.services = nil
102+
70103
err := app.startServices([]string{"postgres", "mysql"}, false)
71104
if err != nil {
72105
t.Errorf("startServices failed: %v", err)

0 commit comments

Comments
 (0)