From b6231869043c7243666cc859efd98e41a59277e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Tue, 16 May 2023 18:59:22 +0000 Subject: [PATCH] Add preflight tests --- internal/command/machine/run.go | 2 +- test/preflight/fly_machine_test.go | 54 ++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/internal/command/machine/run.go b/internal/command/machine/run.go index 723f6373aa..e85b7572c9 100644 --- a/internal/command/machine/run.go +++ b/internal/command/machine/run.go @@ -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 diff --git a/test/preflight/fly_machine_test.go b/test/preflight/fly_machine_test.go index d7ffc81c17..7a330ca4d8 100644 --- a/test/preflight/fly_machine_test.go +++ b/test/preflight/fly_machine_test.go @@ -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) +}