Skip to content

Commit

Permalink
fix action
Browse files Browse the repository at this point in the history
  • Loading branch information
m1yon committed Jun 29, 2024
1 parent 19f3f38 commit 0101747
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 2 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"log"
"log/slog"
"net/http"
Expand Down Expand Up @@ -41,5 +42,6 @@ func main() {
WriteTimeout: 10 * time.Second,
}

fmt.Println("server started")
log.Fatal(server.ListenAndServe())
}
5 changes: 3 additions & 2 deletions cmd/server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ func TestServer(t *testing.T) {
}

port := "3000"
driver, err := web.NewWebDriver(port)

host := tests.StartDockerServer(t, port)
driver, err := web.NewWebDriver(host, port)

if err != nil {
t.Fatal("failed creating web driver:", err.Error())
}

tests.StartDockerServer(t, port)
specifications.AuthSpecification(t, driver)
}
4 changes: 2 additions & 2 deletions tests/adapters/web/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Driver struct {
browser *rod.Browser
}

func NewWebDriver(port string) (*Driver, error) {
func NewWebDriver(host string, port string) (*Driver, error) {
browser := rod.New()
err := browser.Connect()

Expand All @@ -24,7 +24,7 @@ func NewWebDriver(port string) (*Driver, error) {
}

return &Driver{
BaseURL: fmt.Sprintf("http://localhost:%s", port),
BaseURL: fmt.Sprintf("http://%s:%s", host, port),
Client: &http.Client{
Timeout: 1 * time.Second,
},
Expand Down
12 changes: 8 additions & 4 deletions tests/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,27 @@ import (
"testing"
"time"

"github.com/docker/go-connections/nat"
"github.com/stretchr/testify/assert"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
)

const (
startupTimeout = 5 * time.Second
startupTimeout = 1 * time.Minute
dockerFilePath = "docker/server/Dockerfile"
)

func StartDockerServer(
t testing.TB,
port string,
) {
) string {
t.Helper()

ctx := context.Background()
req := testcontainers.ContainerRequest{
FromDockerfile: newTCDockerfile(),
ExposedPorts: []string{fmt.Sprintf("%s:%s", port, port)},
WaitingFor: wait.ForListeningPort(nat.Port(port)).WithStartupTimeout(startupTimeout),
WaitingFor: wait.ForLog("server started").WithStartupTimeout(startupTimeout),
Env: map[string]string{
"LOCAL_DB": "true",
},
Expand All @@ -41,6 +40,11 @@ func StartDockerServer(
t.Cleanup(func() {
assert.NoError(t, container.Terminate(ctx))
})

host, _ := container.Host(ctx)
fmt.Println("hossttttt", host)

return host
}

func newTCDockerfile() testcontainers.FromDockerfile {
Expand Down

0 comments on commit 0101747

Please sign in to comment.