diff --git a/e2e/challenges_test.go b/e2e/challenges_test.go index 9b3812ce56..59930923b7 100644 --- a/e2e/challenges_test.go +++ b/e2e/challenges_test.go @@ -38,7 +38,7 @@ func TestMain(m *testing.M) { } func TestHelp(t *testing.T) { - output, err := load.RunLego("-h") + output, err := load.RunLegoCombinedOutput("-h") if err != nil { fmt.Fprintf(os.Stderr, "%s\n", output) t.Fatal(err) @@ -50,7 +50,7 @@ func TestHelp(t *testing.T) { func TestChallengeHTTP_Run(t *testing.T) { loader.CleanLegoFiles() - output, err := load.RunLego( + err := load.RunLego( "-m", "hubert@hubert.com", "--accept-tos", "-s", "https://localhost:14000/dir", @@ -58,10 +58,6 @@ func TestChallengeHTTP_Run(t *testing.T) { "--http", "--http.port", ":5002", "run") - - if len(output) > 0 { - fmt.Fprintf(os.Stdout, "%s\n", output) - } if err != nil { t.Fatal(err) } @@ -70,7 +66,7 @@ func TestChallengeHTTP_Run(t *testing.T) { func TestChallengeTLS_Run_Domains(t *testing.T) { loader.CleanLegoFiles() - output, err := load.RunLego( + err := load.RunLego( "-m", "hubert@hubert.com", "--accept-tos", "-s", "https://localhost:14000/dir", @@ -78,10 +74,6 @@ func TestChallengeTLS_Run_Domains(t *testing.T) { "--tls", "--tls.port", ":5001", "run") - - if len(output) > 0 { - fmt.Fprintf(os.Stdout, "%s\n", output) - } if err != nil { t.Fatal(err) } @@ -90,7 +82,7 @@ func TestChallengeTLS_Run_Domains(t *testing.T) { func TestChallengeTLS_Run_IP(t *testing.T) { loader.CleanLegoFiles() - output, err := load.RunLego( + err := load.RunLego( "-m", "hubert@hubert.com", "--accept-tos", "-s", "https://localhost:14000/dir", @@ -98,10 +90,6 @@ func TestChallengeTLS_Run_IP(t *testing.T) { "--tls", "--tls.port", ":5001", "run") - - if len(output) > 0 { - fmt.Fprintf(os.Stdout, "%s\n", output) - } if err != nil { t.Fatal(err) } @@ -110,7 +98,7 @@ func TestChallengeTLS_Run_IP(t *testing.T) { func TestChallengeTLS_Run_CSR(t *testing.T) { loader.CleanLegoFiles() - output, err := load.RunLego( + err := load.RunLego( "-m", "hubert@hubert.com", "--accept-tos", "-s", "https://localhost:14000/dir", @@ -118,10 +106,6 @@ func TestChallengeTLS_Run_CSR(t *testing.T) { "--tls", "--tls.port", ":5001", "run") - - if len(output) > 0 { - fmt.Fprintf(os.Stdout, "%s\n", output) - } if err != nil { t.Fatal(err) } @@ -130,7 +114,7 @@ func TestChallengeTLS_Run_CSR(t *testing.T) { func TestChallengeTLS_Run_CSR_PEM(t *testing.T) { loader.CleanLegoFiles() - output, err := load.RunLego( + err := load.RunLego( "-m", "hubert@hubert.com", "--accept-tos", "-s", "https://localhost:14000/dir", @@ -138,10 +122,6 @@ func TestChallengeTLS_Run_CSR_PEM(t *testing.T) { "--tls", "--tls.port", ":5001", "run") - - if len(output) > 0 { - fmt.Fprintf(os.Stdout, "%s\n", output) - } if err != nil { t.Fatal(err) } @@ -150,7 +130,7 @@ func TestChallengeTLS_Run_CSR_PEM(t *testing.T) { func TestChallengeTLS_Run_Revoke(t *testing.T) { loader.CleanLegoFiles() - output, err := load.RunLego( + err := load.RunLego( "-m", "hubert@hubert.com", "--accept-tos", "-s", "https://localhost:14000/dir", @@ -159,15 +139,11 @@ func TestChallengeTLS_Run_Revoke(t *testing.T) { "--tls", "--tls.port", ":5001", "run") - - if len(output) > 0 { - fmt.Fprintf(os.Stdout, "%s\n", output) - } if err != nil { t.Fatal(err) } - output, err = load.RunLego( + err = load.RunLego( "-m", "hubert@hubert.com", "--accept-tos", "-s", "https://localhost:14000/dir", @@ -175,10 +151,6 @@ func TestChallengeTLS_Run_Revoke(t *testing.T) { "--tls", "--tls.port", ":5001", "revoke") - - if len(output) > 0 { - fmt.Fprintf(os.Stdout, "%s\n", output) - } if err != nil { t.Fatal(err) } @@ -187,7 +159,7 @@ func TestChallengeTLS_Run_Revoke(t *testing.T) { func TestChallengeTLS_Run_Revoke_Non_ASCII(t *testing.T) { loader.CleanLegoFiles() - output, err := load.RunLego( + err := load.RunLego( "-m", "hubert@hubert.com", "--accept-tos", "-s", "https://localhost:14000/dir", @@ -195,15 +167,11 @@ func TestChallengeTLS_Run_Revoke_Non_ASCII(t *testing.T) { "--tls", "--tls.port", ":5001", "run") - - if len(output) > 0 { - fmt.Fprintf(os.Stdout, "%s\n", output) - } if err != nil { t.Fatal(err) } - output, err = load.RunLego( + err = load.RunLego( "-m", "hubert@hubert.com", "--accept-tos", "-s", "https://localhost:14000/dir", @@ -211,10 +179,6 @@ func TestChallengeTLS_Run_Revoke_Non_ASCII(t *testing.T) { "--tls", "--tls.port", ":5001", "revoke") - - if len(output) > 0 { - fmt.Fprintf(os.Stdout, "%s\n", output) - } if err != nil { t.Fatal(err) } diff --git a/e2e/dnschallenge/dns_challenges_test.go b/e2e/dnschallenge/dns_challenges_test.go index 2c228230dd..9ae07d46a4 100644 --- a/e2e/dnschallenge/dns_challenges_test.go +++ b/e2e/dnschallenge/dns_challenges_test.go @@ -40,7 +40,7 @@ func TestMain(m *testing.M) { } func TestDNSHelp(t *testing.T) { - output, err := load.RunLego("dnshelp") + output, err := load.RunLegoCombinedOutput("dnshelp") if err != nil { fmt.Fprintf(os.Stderr, "%s\n", output) t.Fatal(err) @@ -52,7 +52,7 @@ func TestDNSHelp(t *testing.T) { func TestChallengeDNS_Run(t *testing.T) { loader.CleanLegoFiles() - output, err := load.RunLego( + err := load.RunLego( "-m", "hubert@hubert.com", "--accept-tos", "--dns", "exec", @@ -62,10 +62,6 @@ func TestChallengeDNS_Run(t *testing.T) { "-d", "*.légo.acme", "-d", "légo.acme", "run") - - if len(output) > 0 { - fmt.Fprintf(os.Stdout, "%s\n", output) - } if err != nil { t.Fatal(err) } diff --git a/e2e/loader/loader.go b/e2e/loader/loader.go index 7e8ff539f0..5579bb5235 100644 --- a/e2e/loader/loader.go +++ b/e2e/loader/loader.go @@ -1,6 +1,7 @@ package loader import ( + "bufio" "bytes" "crypto/tls" "errors" @@ -87,7 +88,7 @@ func (l *EnvLoader) MainTest(m *testing.M) int { return m.Run() } -func (l *EnvLoader) RunLego(arg ...string) ([]byte, error) { +func (l *EnvLoader) RunLegoCombinedOutput(arg ...string) ([]byte, error) { cmd := exec.Command(l.lego, arg...) cmd.Env = l.LegoOptions @@ -96,6 +97,37 @@ func (l *EnvLoader) RunLego(arg ...string) ([]byte, error) { return cmd.CombinedOutput() } +func (l *EnvLoader) RunLego(arg ...string) error { + cmd := exec.Command(l.lego, arg...) + cmd.Env = l.LegoOptions + + fmt.Printf("$ %s\n", strings.Join(cmd.Args, " ")) + + stdout, err := cmd.StdoutPipe() + if err != nil { + return fmt.Errorf("create pipe: %w", err) + } + + cmd.Stderr = cmd.Stdout + + err = cmd.Start() + if err != nil { + return fmt.Errorf("start command: %w", err) + } + + scanner := bufio.NewScanner(stdout) + for scanner.Scan() { + println(scanner.Text()) + } + + err = cmd.Wait() + if err != nil { + return fmt.Errorf("wait command: %w", err) + } + + return nil +} + func (l *EnvLoader) launchPebble() func() { if l.PebbleOptions == nil { return func() {}