Skip to content

Commit 3e49bdd

Browse files
committed
Implement integration testing
1 parent e9a1d13 commit 3e49bdd

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

ci/main.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ func (m *Ci) Lint(ctx context.Context, dir *dagger.Directory) (string, error) {
3939
}
4040

4141
// Returns the Sast report as a file
42-
func (m *Ci) Sast(ctx context.Context, directory *dagger.Directory) *dagger.File {
42+
func (m *Ci) Sast(ctx context.Context, dir *dagger.Directory) *dagger.File {
4343
return dag.Container().
4444
From("presidentbeef/brakeman:latest").
45-
WithMountedDirectory("/app", directory).
45+
WithMountedDirectory("/app", dir).
4646
WithWorkdir("/app").
4747
WithExec([]string{"/usr/src/app/bin/brakeman"}).
4848
File("/app/brakeman-output.tabs")
@@ -77,18 +77,24 @@ func (m *Ci) Memcached(
7777

7878
// Executes the test suite for the Rails application in the provided Directory
7979
func (m *Ci) Test(ctx context.Context, dir *dagger.Directory) *dagger.Container {
80-
return dag.Container().From("ruby:latest").
81-
WithMountedDirectory("/app", dir).
82-
WithWorkdir("/app").
80+
81+
return dag.Container().
82+
From("ruby:latest").
83+
WithServiceBinding("postgresql", m.Postgres(ctx, "11")).
84+
WithServiceBinding("memcached", m.Memcached(ctx, "latest")).
85+
WithMountedDirectory("/mnt", dir).
86+
WithWorkdir("/mnt").
87+
WithEnvVariable("RAILS_DB_HOST", "postgresql"). // This is the service name of the postgres container called by rails
88+
WithEnvVariable("RAILS_TEST_DB_HOST", "postgresql").
8389
WithEnvVariable("RAILS_TEST_DB_NAME", "postgres").
8490
WithEnvVariable("RAILS_TEST_DB_USERNAME", "postgres").
8591
WithEnvVariable("RAILS_TEST_DB_PASSWORD", "postgres").
8692
WithEnvVariable("RAILS_ENV", "test").
8793
WithEnvVariable("CI", "true").
8894
WithEnvVariable("PGDATESTYLE", "German").
89-
WithExec([]string{"apt-get", "-yqq", "update"}).
95+
WithExec([]string{"apt-get", "update"}).
9096
WithExec([]string{"apt-get", "-yqq", "install", "libpq-dev", "libvips-dev"}).
91-
WithExec([]string{"gem", "install", "bundler"}).
97+
WithExec([]string{"gem", "install", "bundler", "--version", "~> 2"}).
9298
WithExec([]string{"bundle", "install", "--jobs", "4", "--retry", "3"}).
9399
WithExec([]string{"bundle", "exec", "rails", "db:create"}).
94100
WithExec([]string{"bundle", "exec", "rails", "db:migrate"}).

0 commit comments

Comments
 (0)