Skip to content

Commit

Permalink
Fix URL preview test
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Feb 20, 2024
1 parent 9a97657 commit c7a8d4f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
4 changes: 4 additions & 0 deletions test/msc3916_misc_client_endpoints_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (s *MSC3916MiscClientEndpointsSuite) SetupSuite() {

func (s *MSC3916MiscClientEndpointsSuite) TearDownSuite() {
if s.htmlPage != nil {
if s.T().Failed() {
staticLogs, err := s.htmlPage.Logs()
s.deps.DumpDebugLogs(staticLogs, err, -1, s.htmlPage.PublicUrl)
}
s.htmlPage.Teardown()
}
if s.deps != nil {
Expand Down
32 changes: 18 additions & 14 deletions test/test_internals/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,23 @@ func (c *ContainerDeps) Teardown() {
func (c *ContainerDeps) Debug() {
for i, m := range c.Machines {
logs, err := m.Logs()
if err != nil {
log.Fatal(err)
}
b, err := io.ReadAll(logs)
if err != nil {
log.Fatal(err)
}
fmt.Printf("[MMR Deps] Logs from index %d (%s)", i, m.HttpUrl)
fmt.Println()
fmt.Println(string(b))
err = logs.Close()
if err != nil {
log.Fatal(err)
}
c.DumpDebugLogs(logs, err, i, m.HttpUrl)
}
}

func (c *ContainerDeps) DumpDebugLogs(logs io.ReadCloser, err error, i int, url string) {
if err != nil {
log.Fatal(err)
}
b, err := io.ReadAll(logs)
if err != nil {
log.Fatal(err)
}
fmt.Printf("[MMR Deps] Logs from index %d (%s)", i, url)
fmt.Println()
fmt.Println(string(b))
err = logs.Close()
if err != nil {
log.Fatal(err)
}
}
11 changes: 11 additions & 0 deletions test/test_internals/inline_dep_host_file.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package test_internals

import (
"context"
"fmt"
"io"
"log"
"os"
"path"
Expand All @@ -24,6 +26,11 @@ func ServeFile(fileName string, deps *ContainerDeps, contents string) (*HostedFi
return nil, err
}

err = os.Chmod(tmp, 0755)
if err != nil {
return nil, err
}

f, err := os.Create(path.Join(tmp, fileName))
if err != nil {
return nil, err
Expand Down Expand Up @@ -80,3 +87,7 @@ func (f *HostedFile) Teardown() {
log.Fatalf("Error cleaning up temporarily hosted file: %s", err.Error())
}
}

func (f *HostedFile) Logs() (io.ReadCloser, error) {
return f.nginx.Logs(context.Background())
}

0 comments on commit c7a8d4f

Please sign in to comment.