Skip to content

Commit

Permalink
refactor(test): move feature tests under /test
Browse files Browse the repository at this point in the history
  • Loading branch information
majori committed Feb 26, 2024
1 parent 8352918 commit eabec60
Show file tree
Hide file tree
Showing 21 changed files with 15 additions and 3 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ Feature: Recipes as OCI artifacts

Scenario: Pull a recipe from OCI repository
Given a recipes directory
And a project directory
And a recipe "foo"
And recipe "foo" generates file "README.md" with content "initial"
And a local OCI registry
And the recipe "foo" is pushed to the local OCI repository "foo:v0.0.1"
When I pull the recipe "foo" from the local OCI repository "foo:v0.0.1"
Then no errors were printed
And the recipes directory should contain recipe "foo"
And the project directory should contain file "foo/recipe.yml"

Scenario: Push a recipe to OCI repository with authentication
Given a recipes directory
Expand All @@ -30,13 +31,14 @@ Feature: Recipes as OCI artifacts

Scenario: Pull a recipe from OCI repository with authentication
Given a recipes directory
And a project directory
And a recipe "foo"
And recipe "foo" generates file "README.md" with content "initial"
And a local OCI registry with authentication
And the recipe "foo" is pushed to the local OCI repository "foo:v0.0.1"
When I pull the recipe "foo" from the local OCI repository "foo:v0.0.1"
Then no errors were printed
And the recipes directory should contain recipe "foo"
And the project directory should contain file "foo/recipe.yml"

Scenario: Try to push a recipe to OCI repository without authentication
Given a recipes directory
Expand All @@ -49,6 +51,7 @@ Feature: Recipes as OCI artifacts

Scenario: Try to pull a recipe from OCI repository which not exist
Given a recipes directory
And a project directory
And a local OCI registry with authentication
When I pull the recipe "foo" from the local OCI repository "foo:v0.0.1"
Then CLI produced an error "recipe not found"
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 8 additions & 1 deletion internal/cli/cmds_test.go → test/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type (
cmdStdErrCtxKey struct{}
cmdAdditionalFlagsCtxKey struct{}
dockerResourcesCtxKey struct{}
scenarioNameCtxKey struct{}
)

type OCIRegistry struct {
Expand Down Expand Up @@ -117,6 +118,7 @@ func TestFeatures(t *testing.T) {
ctx = context.WithValue(ctx, cmdAdditionalFlagsCtxKey{}, make(map[string]string))
ctx = context.WithValue(ctx, dockerResourcesCtxKey{}, []*dockertest.Resource{})
ctx = context.WithValue(ctx, cmdStdInCtxKey{}, NewBlockBuffer())
ctx = context.WithValue(ctx, scenarioNameCtxKey{}, sc.Name)

return ctx, nil
})
Expand All @@ -128,7 +130,7 @@ func TestFeatures(t *testing.T) {
Strict: true,
Concurrency: 8,
Format: "pretty",
Paths: []string{"../../test"},
Paths: []string{"./features"},
TestingT: t,
},
}
Expand Down Expand Up @@ -289,9 +291,14 @@ func bufferKeysToInput(ctx context.Context, keys string) (context.Context, error

func aRecipe(ctx context.Context, recipeName string) (context.Context, error) {
dir := ctx.Value(recipesDirectoryPathCtxKey{}).(string)
scenarioName := ctx.Value(scenarioNameCtxKey{}).(string)

re := recipe.NewRecipe()
re.Name = recipeName
re.Version = "v0.0.1"
re.Description = scenarioName

fmt.Println(dir)

if err := re.Save(filepath.Join(dir, recipeName)); err != nil {
return ctx, err
Expand Down
2 changes: 2 additions & 0 deletions internal/cli/pull_test.go → test/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ func AddPullSteps(s *godog.ScenarioContext) {
}

func iPullRecipe(ctx context.Context, recipeName, repoName string) (context.Context, error) {
dir := ctx.Value(projectDirectoryPathCtxKey{}).(string)
ociRegistry := ctx.Value(ociRegistryCtxKey{}).(OCIRegistry)
configDir, configFileExists := ctx.Value(dockerConfigDirectoryPathCtxKey{}).(string)

args := []string{
"pull",
filepath.Join(ociRegistry.Resource.GetHostPort("5000/tcp"), repoName),
fmt.Sprintf("--dir=%s", dir),
}

if ociRegistry.TLSEnabled {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit eabec60

Please sign in to comment.