-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
282 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package fixture_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/YuukanOO/seelf/internal/deployment/domain" | ||
"github.com/YuukanOO/seelf/internal/deployment/fixture" | ||
"github.com/YuukanOO/seelf/pkg/assert" | ||
) | ||
|
||
func Test_App(t *testing.T) { | ||
t.Run("should be able to build a random app", func(t *testing.T) { | ||
app := fixture.App() | ||
|
||
assert.NotZero(t, app.ID()) | ||
}) | ||
|
||
t.Run("should be able to build an app with a given name", func(t *testing.T) { | ||
app := fixture.App(fixture.WithAppName("foo")) | ||
|
||
created := assert.EventIs[domain.AppCreated](t, &app, 0) | ||
assert.Equal(t, "foo", created.Name) | ||
}) | ||
|
||
t.Run("should be able to build an app created by a specific user id", func(t *testing.T) { | ||
app := fixture.App(fixture.WithAppCreatedBy("uid")) | ||
|
||
created := assert.EventIs[domain.AppCreated](t, &app, 0) | ||
assert.Equal(t, "uid", created.Created.By()) | ||
}) | ||
|
||
t.Run("should be able to build an app with given production and staging configuration", func(t *testing.T) { | ||
production := domain.NewEnvironmentConfig("production_id") | ||
staging := domain.NewEnvironmentConfig("staging_id") | ||
app := fixture.App(fixture.WithEnvironmentConfig(production, staging)) | ||
|
||
created := assert.EventIs[domain.AppCreated](t, &app, 0) | ||
assert.DeepEqual(t, production, created.Production) | ||
assert.DeepEqual(t, staging, created.Staging) | ||
}) | ||
|
||
t.Run("should be able to build an app with given production configuration", func(t *testing.T) { | ||
config := domain.NewEnvironmentConfig("production_id") | ||
app := fixture.App(fixture.WithProductionConfig(config)) | ||
|
||
created := assert.EventIs[domain.AppCreated](t, &app, 0) | ||
assert.DeepEqual(t, config, created.Production) | ||
assert.NotEqual(t, config.Target(), created.Staging.Target()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package fixture_test | ||
|
||
import ( | ||
"testing" | ||
|
||
auth "github.com/YuukanOO/seelf/internal/auth/domain" | ||
authfixture "github.com/YuukanOO/seelf/internal/auth/fixture" | ||
"github.com/YuukanOO/seelf/internal/deployment/domain" | ||
"github.com/YuukanOO/seelf/internal/deployment/fixture" | ||
"github.com/YuukanOO/seelf/pkg/assert" | ||
) | ||
|
||
func Test_Database(t *testing.T) { | ||
t.Run("should be able to prepare a database without seeding it", func(t *testing.T) { | ||
ctx := fixture.PrepareDatabase(t) | ||
|
||
assert.NotNil(t, ctx) | ||
assert.NotNil(t, ctx.Config) | ||
assert.NotNil(t, ctx.AppsStore) | ||
assert.NotNil(t, ctx.TargetsStore) | ||
assert.NotNil(t, ctx.AppsStore) | ||
assert.NotNil(t, ctx.DeploymentsStore) | ||
assert.NotNil(t, ctx.RegistriesStore) | ||
assert.NotNil(t, ctx.Dispatcher) | ||
assert.HasLength(t, 0, ctx.Dispatcher.Signals()) | ||
assert.HasLength(t, 0, ctx.Dispatcher.Requests()) | ||
}) | ||
|
||
t.Run("should seed correctly and attach the first user id to the created context", func(t *testing.T) { | ||
user := authfixture.User() | ||
target := fixture.Target(fixture.WithTargetCreatedBy(user.ID())) | ||
config := domain.NewEnvironmentConfig(target.ID()) | ||
app := fixture.App( | ||
fixture.WithEnvironmentConfig(config, config), | ||
fixture.WithAppCreatedBy(user.ID()), | ||
) | ||
registry := fixture.Registry(fixture.WithRegistryCreatedBy(user.ID())) | ||
deployment := fixture.Deployment( | ||
fixture.FromApp(app), | ||
fixture.WithDeploymentRequestedBy(user.ID()), | ||
) | ||
|
||
ctx := fixture.PrepareDatabase(t, | ||
fixture.WithUsers(&user), | ||
fixture.WithTargets(&target), | ||
fixture.WithApps(&app), | ||
fixture.WithRegistries(®istry), | ||
fixture.WithDeployments(&deployment), | ||
) | ||
|
||
assert.Equal(t, user.ID(), auth.CurrentUser(ctx.Context).Get("")) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package fixture_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/YuukanOO/seelf/internal/deployment/domain" | ||
"github.com/YuukanOO/seelf/internal/deployment/fixture" | ||
"github.com/YuukanOO/seelf/pkg/assert" | ||
) | ||
|
||
func Test_Deployment(t *testing.T) { | ||
t.Run("should be able to create a new deployment", func(t *testing.T) { | ||
deployment := fixture.Deployment() | ||
|
||
assert.NotZero(t, deployment.ID()) | ||
assert.Equal(t, domain.Production, deployment.Config().Environment()) | ||
}) | ||
|
||
t.Run("should be able to create a new deployment from a given app", func(t *testing.T) { | ||
app := fixture.App() | ||
deployment := fixture.Deployment(fixture.FromApp(app)) | ||
|
||
created := assert.EventIs[domain.DeploymentCreated](t, &deployment, 0) | ||
assert.Equal(t, app.ID(), created.ID.AppID()) | ||
}) | ||
|
||
t.Run("should be able to create a new deployment requested by a given user id", func(t *testing.T) { | ||
deployment := fixture.Deployment(fixture.WithDeploymentRequestedBy("uid")) | ||
|
||
created := assert.EventIs[domain.DeploymentCreated](t, &deployment, 0) | ||
assert.Equal(t, "uid", created.Requested.By()) | ||
}) | ||
|
||
t.Run("should be able to create a new deployment with a given source data", func(t *testing.T) { | ||
source := fixture.SourceData() | ||
deployment := fixture.Deployment(fixture.WithSourceData(source)) | ||
|
||
created := assert.EventIs[domain.DeploymentCreated](t, &deployment, 0) | ||
assert.Equal(t, source, created.Source) | ||
}) | ||
|
||
t.Run("should be able to create a new deployment with a given environment", func(t *testing.T) { | ||
deployment := fixture.Deployment(fixture.ForEnvironment(domain.Staging)) | ||
|
||
created := assert.EventIs[domain.DeploymentCreated](t, &deployment, 0) | ||
assert.Equal(t, domain.Staging, created.Config.Environment()) | ||
}) | ||
} | ||
|
||
func Test_SourceData(t *testing.T) { | ||
t.Run("should be able to create a source data", func(t *testing.T) { | ||
source := fixture.SourceData() | ||
|
||
assert.Equal(t, "test", source.Kind()) | ||
assert.False(t, source.NeedVersionControl()) | ||
}) | ||
|
||
t.Run("should be able to create a source data with version control needed", func(t *testing.T) { | ||
source := fixture.SourceData(fixture.WithVersionControlNeeded()) | ||
|
||
assert.True(t, source.NeedVersionControl()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package fixture_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/YuukanOO/seelf/internal/deployment/domain" | ||
"github.com/YuukanOO/seelf/internal/deployment/fixture" | ||
"github.com/YuukanOO/seelf/pkg/assert" | ||
"github.com/YuukanOO/seelf/pkg/must" | ||
) | ||
|
||
func Test_Registry(t *testing.T) { | ||
t.Run("should be able to create a random registry", func(t *testing.T) { | ||
registry := fixture.Registry() | ||
|
||
assert.NotZero(t, registry.ID()) | ||
}) | ||
|
||
t.Run("should be able to create a registry with a given name", func(t *testing.T) { | ||
registry := fixture.Registry(fixture.WithRegistryName("my-registry")) | ||
|
||
created := assert.EventIs[domain.RegistryCreated](t, ®istry, 0) | ||
assert.Equal(t, "my-registry", created.Name) | ||
}) | ||
|
||
t.Run("should be able to create a registry created by a given user id", func(t *testing.T) { | ||
registry := fixture.Registry(fixture.WithRegistryCreatedBy("uid")) | ||
|
||
created := assert.EventIs[domain.RegistryCreated](t, ®istry, 0) | ||
assert.Equal(t, "uid", created.Created.By()) | ||
}) | ||
|
||
t.Run("should be able to create a registry with a given url", func(t *testing.T) { | ||
url := must.Panic(domain.UrlFrom("https://my-registry.com")) | ||
registry := fixture.Registry(fixture.WithUrl(url)) | ||
|
||
created := assert.EventIs[domain.RegistryCreated](t, ®istry, 0) | ||
assert.Equal(t, url, created.Url) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package fixture_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/YuukanOO/seelf/internal/deployment/domain" | ||
"github.com/YuukanOO/seelf/internal/deployment/fixture" | ||
"github.com/YuukanOO/seelf/pkg/assert" | ||
) | ||
|
||
func Test_Target(t *testing.T) { | ||
t.Run("should be able to create a target", func(t *testing.T) { | ||
target := fixture.Target() | ||
|
||
assert.NotZero(t, target.ID()) | ||
}) | ||
|
||
t.Run("should be able to create a target with a given name", func(t *testing.T) { | ||
target := fixture.Target(fixture.WithTargetName("name")) | ||
|
||
created := assert.EventIs[domain.TargetCreated](t, &target, 0) | ||
assert.Equal(t, "name", created.Name) | ||
}) | ||
|
||
t.Run("should be able to create a target with a given user id", func(t *testing.T) { | ||
target := fixture.Target(fixture.WithTargetCreatedBy("id")) | ||
|
||
created := assert.EventIs[domain.TargetCreated](t, &target, 0) | ||
assert.Equal(t, "id", created.Created.By()) | ||
}) | ||
|
||
t.Run("should be able to create a target with a given provider config", func(t *testing.T) { | ||
config := fixture.ProviderConfig() | ||
target := fixture.Target(fixture.WithProviderConfig(config)) | ||
|
||
created := assert.EventIs[domain.TargetCreated](t, &target, 0) | ||
assert.DeepEqual(t, config, created.Provider) | ||
}) | ||
} | ||
|
||
func Test_ProviderConfig(t *testing.T) { | ||
t.Run("should be able to create a provider config", func(t *testing.T) { | ||
config := fixture.ProviderConfig() | ||
|
||
assert.NotZero(t, config.Fingerprint()) | ||
assert.NotZero(t, config.Kind()) | ||
}) | ||
|
||
t.Run("should be able to create a provider config with a given fingerprint", func(t *testing.T) { | ||
config := fixture.ProviderConfig(fixture.WithFingerprint("fingerprint")) | ||
|
||
assert.Equal(t, "fingerprint", config.Fingerprint()) | ||
}) | ||
|
||
t.Run("should be able to create a provider config with a given kind", func(t *testing.T) { | ||
config := fixture.ProviderConfig(fixture.WithKind("kind")) | ||
|
||
assert.Equal(t, "kind", config.Kind()) | ||
}) | ||
|
||
t.Run("should be able to create a provider config with a given data", func(t *testing.T) { | ||
one := fixture.ProviderConfig( | ||
fixture.WithKind("kind"), | ||
fixture.WithFingerprint("fingerprint"), | ||
fixture.WithData("data")) | ||
two := fixture.ProviderConfig( | ||
fixture.WithKind("kind"), | ||
fixture.WithFingerprint("fingerprint"), | ||
fixture.WithData("data")) | ||
three := fixture.ProviderConfig() | ||
|
||
assert.True(t, one.Equals(two)) | ||
assert.False(t, one.Equals(three)) | ||
assert.False(t, two.Equals(three)) | ||
}) | ||
} |