Skip to content

Commit

Permalink
fix: tests using generate workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
lgdd committed Feb 4, 2024
1 parent ab58caa commit d246383
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
13 changes: 7 additions & 6 deletions lfr/pkg/generate/docker/docker_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package docker

import (
"github.com/lgdd/liferay-cli/lfr/pkg/generate/workspace"
"github.com/lgdd/liferay-cli/lfr/pkg/project"
"os"
"path/filepath"
"strings"
"testing"

"github.com/lgdd/liferay-cli/lfr/pkg/generate/workspace"
"github.com/lgdd/liferay-cli/lfr/pkg/project"
)

func Test_GenerateDocker_ShouldCreateDockerfileAndCompose(t *testing.T) {
liferayWorkspace := filepath.Join(t.TempDir(), "liferay-workspace")
err := workspace.Generate(liferayWorkspace, project.Gradle, "7.3")
err := workspace.Generate(liferayWorkspace, project.Gradle, "7.3", "portal")
if err != nil {
t.Fatal(err)
}
Expand All @@ -29,7 +30,7 @@ func Test_GenerateDocker_ShouldCreateDockerfileAndCompose(t *testing.T) {

func Test_GenerateDocker_WithMultiStageAndGradle_ShouldContainExpectedStages(t *testing.T) {
liferayWorkspace := filepath.Join(t.TempDir(), "liferay-workspace")
err := workspace.Generate(liferayWorkspace, project.Gradle, "7.3")
err := workspace.Generate(liferayWorkspace, project.Gradle, "7.3", "portal")
if err != nil {
t.Fatal(err)
}
Expand All @@ -52,7 +53,7 @@ func Test_GenerateDocker_WithMultiStageAndGradle_ShouldContainExpectedStages(t *

func Test_GenerateDocker_WithMultiStageAndMaven_ShouldContainExpectedStages(t *testing.T) {
liferayWorkspace := filepath.Join(t.TempDir(), "liferay-workspace")
err := workspace.Generate(liferayWorkspace, project.Maven, "7.3")
err := workspace.Generate(liferayWorkspace, project.Maven, "7.3", "portal")
if err != nil {
t.Fatal(err)
}
Expand All @@ -75,7 +76,7 @@ func Test_GenerateDocker_WithMultiStageAndMaven_ShouldContainExpectedStages(t *t

func Test_GenerateDocker_WithWrongJavaVersion_ShouldFail(t *testing.T) {
liferayWorkspace := filepath.Join(t.TempDir(), "liferay-workspace")
err := workspace.Generate(liferayWorkspace, project.Gradle, "7.3")
err := workspace.Generate(liferayWorkspace, project.Gradle, "7.3", "portal")
if err != nil {
t.Fatal(err)
}
Expand Down
12 changes: 6 additions & 6 deletions lfr/pkg/generate/sb/service_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func Test_GenerateServiceBuilder_WithGradle_ShouldCreateExpectedFiles(t *testing.T) {
liferayWorkspace := filepath.Join(t.TempDir(), "liferay-workspace")
err := workspace.Generate(liferayWorkspace, project.Gradle, "7.3")
err := workspace.Generate(liferayWorkspace, project.Gradle, "7.3", "portal")
if err != nil {
t.Fatal(err)
}
Expand All @@ -41,7 +41,7 @@ func Test_GenerateServiceBuilder_WithGradle_ShouldCreateExpectedFiles(t *testing

func Test_GenerateServiceBuilder_WithMaven_ShouldCreateExpectedFiles(t *testing.T) {
liferayWorkspace := filepath.Join(t.TempDir(), "liferay-workspace")
err := workspace.Generate(liferayWorkspace, project.Maven, "7.3")
err := workspace.Generate(liferayWorkspace, project.Maven, "7.3", "portal")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -97,7 +97,7 @@ func Test_GenerateServiceBuilder_WithMaven_ShouldCreateExpectedFiles(t *testing.

func Test_GenerateServiceBuilder_With73_ShouldContainCorrespondingDoctype(t *testing.T) {
liferayWorkspace := filepath.Join(t.TempDir(), "liferay-workspace")
err := workspace.Generate(liferayWorkspace, project.Gradle, "7.3")
err := workspace.Generate(liferayWorkspace, project.Gradle, "7.3", "portal")
if err != nil {
t.Fatal(err)
}
Expand All @@ -118,7 +118,7 @@ func Test_GenerateServiceBuilder_With73_ShouldContainCorrespondingDoctype(t *tes

func Test_GenerateServiceBuilder_With72_ShouldContainCorrespondingDoctype(t *testing.T) {
liferayWorkspace := filepath.Join(t.TempDir(), "liferay-workspace")
err := workspace.Generate(liferayWorkspace, project.Gradle, "7.2")
err := workspace.Generate(liferayWorkspace, project.Gradle, "7.2", "portal")
if err != nil {
t.Fatal(err)
}
Expand All @@ -139,7 +139,7 @@ func Test_GenerateServiceBuilder_With72_ShouldContainCorrespondingDoctype(t *tes

func Test_GenerateServiceBuilder_With71_ShouldContainCorrespondingDoctype(t *testing.T) {
liferayWorkspace := filepath.Join(t.TempDir(), "liferay-workspace")
err := workspace.Generate(liferayWorkspace, project.Gradle, "7.1")
err := workspace.Generate(liferayWorkspace, project.Gradle, "7.1", "portal")
if err != nil {
t.Fatal(err)
}
Expand All @@ -160,7 +160,7 @@ func Test_GenerateServiceBuilder_With71_ShouldContainCorrespondingDoctype(t *tes

func Test_GenerateServiceBuilder_With70_ShouldContainCorrespondingDoctype(t *testing.T) {
liferayWorkspace := filepath.Join(t.TempDir(), "liferay-workspace")
err := workspace.Generate(liferayWorkspace, project.Gradle, "7.0")
err := workspace.Generate(liferayWorkspace, project.Gradle, "7.0", "portal")
if err != nil {
t.Fatal(err)
}
Expand Down
16 changes: 8 additions & 8 deletions lfr/pkg/generate/workspace/workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestGenerate_Gradle_ShouldHaveExpectedFiles(t *testing.T) {
workspaceDir := filepath.Join(t.TempDir(), "liferay-workspace")
err := Generate(workspaceDir, "gradle", "7.3")
err := Generate(workspaceDir, "gradle", "7.3", "portal")

if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -46,7 +46,7 @@ func TestGenerate_Gradle_ShouldHaveExpectedFiles(t *testing.T) {
t.Fatal(err)
}

metadata, err := project.NewMetadata(workspaceDir, "7.3")
metadata, err := project.NewMetadata(workspaceDir, "7.3", "portal")

if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestGenerate_Gradle_ShouldHaveExpectedFiles(t *testing.T) {

func TestGenerate_Maven_ShouldHaveExpectedFiles(t *testing.T) {

Check failure on line 75 in lfr/pkg/generate/workspace/workspace_test.go

View workflow job for this annotation

GitHub Actions / lint

cyclomatic complexity 22 of func `TestGenerate_Maven_ShouldHaveExpectedFiles` is high (> 15) (gocyclo)

Check failure on line 75 in lfr/pkg/generate/workspace/workspace_test.go

View workflow job for this annotation

GitHub Actions / lint

cyclomatic complexity 22 of func `TestGenerate_Maven_ShouldHaveExpectedFiles` is high (> 15) (gocyclo)
workspaceDir := filepath.Join(t.TempDir(), "liferay-workspace")
err := Generate(workspaceDir, "maven", "7.3")
err := Generate(workspaceDir, "maven", "7.3", "portal")

defer t.Cleanup(func() {
err = os.RemoveAll(workspaceDir)
Expand Down Expand Up @@ -114,7 +114,7 @@ func TestGenerate_Maven_ShouldHaveExpectedFiles(t *testing.T) {
t.Fatal(err)
}

metadata, err := project.NewMetadata(workspaceDir, "7.3")
metadata, err := project.NewMetadata(workspaceDir, "7.3", "portal")

if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -219,7 +219,7 @@ func TestGenerate_Maven_ShouldHaveExpectedFiles(t *testing.T) {

func TestGenerateWorkspace_WithWrongVersion_ShouldFail(t *testing.T) {
workspaceDir := filepath.Join(t.TempDir(), "liferay-workspace")
err := Generate(workspaceDir, "gradle", "6.2")
err := Generate(workspaceDir, "gradle", "6.2", "portal")

if err == nil {
t.Fatal("workspace with wrong version should fail")
Expand All @@ -234,7 +234,7 @@ func TestGenerateWorkspace_WithWrongVersion_ShouldFail(t *testing.T) {

func TestGenerateWorkspace_WithWrongBuildTool_ShouldFail(t *testing.T) {
workspaceDir := filepath.Join(t.TempDir(), "liferay-workspace")
err := Generate(workspaceDir, "ant", "7.3")
err := Generate(workspaceDir, "ant", "7.3", "portal")

if err == nil {
t.Fatal("workspace with wrong build tool should fail")
Expand All @@ -250,7 +250,7 @@ func TestGenerateWorkspace_WithWrongBuildTool_ShouldFail(t *testing.T) {
func TestGenerateWorkspace_WithMaven_ShouldHaveDefaultPackageName(t *testing.T) {
workspaceDir := filepath.Join(t.TempDir(), "liferay-workspace")
project.PackageName = "org.acme"
err := Generate(workspaceDir, "maven", "7.3")
err := Generate(workspaceDir, "maven", "7.3", "portal")
if err != nil {
t.Fatal(err)
}
Expand All @@ -266,7 +266,7 @@ func TestGenerateWorkspace_WithMaven_ShouldHaveDefaultPackageName(t *testing.T)
func TestGenerateWorkspace_WithGradle_ShouldHaveDefaultPackageName(t *testing.T) {
workspaceDir := filepath.Join(t.TempDir(), "liferay-workspace")
project.PackageName = "org.acme"
err := Generate(workspaceDir, "gradle", "7.3")
err := Generate(workspaceDir, "gradle", "7.3", "portal")
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit d246383

Please sign in to comment.