I am trying to write a golang test for a dagger function, but I get: panic: DAGGER_SESSION_PORT is not set.
Maybe it is not possible, du you know, and if so how - thanks.
Code:
package main
import (
"context"
"dagger/dockerfile/internal/dagger"
)
type Dockerfile struct{}
// Build and publish image from existing Dockerfile
func (m *Dockerfile) Build(
ctx context.Context,
// location of directory containing Dockerfile
src *dagger.Directory,
) (string, error) {
ref, err := dag.Container().
WithDirectory("/src", src).
WithWorkdir("/src").
Directory("/src").
DockerBuild(). // build from Dockerfile
Publish(ctx, "ttl.sh/health:1h")
if err != nil {
return "", err
}
return ref, nil
}
func TestMain(T *testing.T) {
doc := Dockerfile{}
dir := dag.Directory().Directory("/src")
doc.Build(context.Background(), dir)
}