Skip to content

Commit

Permalink
Add preflight tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dangra committed May 16, 2023
1 parent 9934f78 commit b623186
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/command/machine/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ func determineServices(ctx context.Context, services []api.MachineService) ([]ap

// Remove any service without exposed ports
services = lo.FilterMap(servicesRef, func(s *api.MachineService, _ int) (api.MachineService, bool) {
if s != nil && len(s.Ports) >= 0 {
if s != nil && len(s.Ports) > 0 {
return *s, true
}
return api.MachineService{}, false
Expand Down
54 changes: 54 additions & 0 deletions test/preflight/fly_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,57 @@ func TestFlyMachineRun_standbyFor(t *testing.T) {
require.Equal(f, "stopped", s2.State)
require.Equal(f, []string{s1.ID}, s2.Config.Standbys)
}

// test --port (add, update, remove services and ports)
func TestFlyMachineRun_port(t *testing.T) {
f := testlib.NewTestEnvFromEnv(t)
appName := f.CreateRandomAppMachines()

f.Fly("machine run -a %s nginx --port 443:80/tcp:http:tls", appName)
ml := f.MachinesList(appName)
require.Equal(f, 1, len(ml))

m := ml[0]
want := []api.MachineService{{
Protocol: "tcp",
InternalPort: 80,
Ports: []api.MachinePort{{
Port: api.Pointer(443),
Handlers: []string{"http", "tls"},
}},
}}
require.Equal(f, want, m.Config.Services)

f.Fly("machine update -a %s %s -y --port 80/tcp:http --port 1001/udp", appName, m.ID)
m = f.MachinesList(appName)[0]
want = []api.MachineService{{
Protocol: "tcp",
InternalPort: 80,
Ports: []api.MachinePort{{
Port: api.Pointer(443),
Handlers: []string{"http", "tls"},
}, {
Port: api.Pointer(80),
Handlers: []string{"http"},
}},
}, {
Protocol: "udp",
InternalPort: 1001,
Ports: []api.MachinePort{{
Port: api.Pointer(1001),
}},
}}
require.Equal(f, want, m.Config.Services)

f.Fly("machine update -a %s %s -y --port 80/tcp:- --port 1001/udp:tls", appName, m.ID)
m = f.MachinesList(appName)[0]
want = []api.MachineService{{
Protocol: "udp",
InternalPort: 1001,
Ports: []api.MachinePort{{
Port: api.Pointer(1001),
Handlers: []string{"tls"},
}},
}}
require.Equal(f, want, m.Config.Services)
}

0 comments on commit b623186

Please sign in to comment.