Skip to content

Commit

Permalink
ci: relocate e2e tests
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sagi-Kazar <[email protected]>
  • Loading branch information
sagikazarmark committed Nov 18, 2024
1 parent 7fcf6a6 commit 7dd1ae5
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 78 deletions.
94 changes: 17 additions & 77 deletions .dagger/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,95 +4,35 @@ import (
"context"

"github.com/sagikazarmark/dagx/pipeline"

"github.com/twirphp/twirp/.dagger/internal/dagger"
)

// Run tests.
func (m *Twirp) Test() *Test {
return &Test{
Main: m,
}
}

type Test struct {
// +private
Main *Twirp
}

func (m *Test) All(
ctx context.Context,

// Run e2e tests.
func (m *Twirp) Tests(
// +optional
phpVersion string,
) error {
p := pipeline.New(ctx)

pipeline.AddSyncSteps(p,
m.Clientcompat(phpVersion),
m.Complete(phpVersion),
m.NoServices(phpVersion),
)

if phpVersion != "7.4" {
pipeline.AddSyncStep(p, m.Namespace(phpVersion))
}

return pipeline.Run(p)
}

func (m *Test) source(name string) *dagger.Directory {
return m.Main.Source.Directory("tests/" + name)
}

// TODO: make sure Composer dependencies are installed
func (m *Test) fullSourceWithCodegen(name string) *dagger.Directory {
generated := m.Main.generate(m.source(name))

return m.Main.Source.WithDirectory("tests/"+name+"/generated", generated)
}

func (m *Test) container(name string, phpVersion string) *dagger.Container {
) *Tests {
if phpVersion == "" {
phpVersion = defaultPhpVersion
}

return phpBase(phpVersion).Container().
WithFile("/usr/local/bin/clientcompat", m.Main.Clientcompat("")).
WithDirectory("/work", m.fullSourceWithCodegen(name)).
WithWorkdir("/work").
WithExec([]string{"composer", "install"}).
WithWorkdir("/work/tests/" + name)
return &Tests{
Main: m,
PhpVersion: phpVersion,
}
}

func (m *Test) Clientcompat(
// +optional
phpVersion string,
) *dagger.Container {
return m.container("clientcompat", phpVersion).
WithExec([]string{"clientcompat", "-client", "./compat.sh"})
}
type Tests struct {
// +private
Main *Twirp

func (m *Test) Complete(
// +optional
phpVersion string,
) *dagger.Container {
return m.container("complete", phpVersion).
WithExec([]string{"../../lib/vendor/bin/phpunit", "-v"})
// +private
PhpVersion string
}

func (m *Test) Namespace(
// +optional
phpVersion string,
) *dagger.Container {
return m.container("namespace", phpVersion).
WithExec([]string{"php", "test.php"})
}
func (m *Tests) All(ctx context.Context) error {
p := pipeline.New(ctx)

func (m *Test) NoServices(
// +optional
phpVersion string,
) *dagger.Container {
return m.container("no_services", phpVersion).
WithExec([]string{"bash", "-c", `test ! -f generated/Twirp/Tests/No_services/Proto/TwirpError.php || (echo "TwirpError.php should not be generated when there are no services defined in any of the proto files"; exit 1)`})
pipeline.AddStep(p, m.Etoe().All)

return pipeline.Run(p)
}
97 changes: 97 additions & 0 deletions .dagger/tests_e2e.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package main

import (
"context"

"github.com/sagikazarmark/dagx/pipeline"

"github.com/twirphp/twirp/.dagger/internal/dagger"
)

// Run e2e tests.
func (m *Tests) Etoe() *Etoe {
return &Etoe{
Main: m.Main,
PhpVersion: m.PhpVersion,
}
}

type Etoe struct {
// +private
Main *Twirp

// +private
PhpVersion string
}

func (m *Etoe) All(ctx context.Context) error {
p := pipeline.New(ctx)

pipeline.AddSyncSteps(p,
m.Clientcompat(m.PhpVersion),
m.Complete(m.PhpVersion),
m.NoServices(m.PhpVersion),
)

if m.PhpVersion != "7.4" {
pipeline.AddSyncStep(p, m.Namespace(m.PhpVersion))
}

return pipeline.Run(p)
}

func (m *Etoe) source(name string) *dagger.Directory {
return m.Main.Source.Directory("tests/" + name)
}

// TODO: make sure Composer dependencies are installed
func (m *Etoe) fullSourceWithCodegen(name string) *dagger.Directory {
generated := m.Main.generate(m.source(name))

return m.Main.Source.WithDirectory("tests/"+name+"/generated", generated)
}

func (m *Etoe) container(name string, phpVersion string) *dagger.Container {
if phpVersion == "" {
phpVersion = defaultPhpVersion
}

return phpBase(phpVersion).Container().
WithFile("/usr/local/bin/clientcompat", m.Main.Clientcompat("")).
WithDirectory("/work", m.fullSourceWithCodegen(name)).
WithWorkdir("/work").
WithExec([]string{"composer", "install"}).
WithWorkdir("/work/tests/" + name)
}

func (m *Etoe) Clientcompat(
// +optional
phpVersion string,
) *dagger.Container {
return m.container("clientcompat", phpVersion).
WithExec([]string{"clientcompat", "-client", "./compat.sh"})
}

func (m *Etoe) Complete(
// +optional
phpVersion string,
) *dagger.Container {
return m.container("complete", phpVersion).
WithExec([]string{"../../lib/vendor/bin/phpunit", "-v"})
}

func (m *Etoe) Namespace(
// +optional
phpVersion string,
) *dagger.Container {
return m.container("namespace", phpVersion).
WithExec([]string{"php", "test.php"})
}

func (m *Etoe) NoServices(
// +optional
phpVersion string,
) *dagger.Container {
return m.container("no_services", phpVersion).
WithExec([]string{"bash", "-c", `test ! -f generated/Twirp/Tests/No_services/Proto/TwirpError.php || (echo "TwirpError.php should not be generated when there are no services defined in any of the proto files"; exit 1)`})
}
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
uses: dagger/dagger-for-github@e5153f5610d82ac9f3f848f3a25ad9d696641068 # v7.0.1
with:
verb: call
args: test all --php-version ${{ matrix.php }}
args: test --php-version ${{ matrix.php }} all
# cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
version: ${{ env.DAGGER_VERSION }}

Expand Down

0 comments on commit 7dd1ae5

Please sign in to comment.