Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions pkg/cmd/local_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cmd

import (
"testing"

"github.com/galasa-dev/cli/pkg/utils"
"github.com/stretchr/testify/assert"
)

func TestLocalNoCommandsProducesUsageReport(t *testing.T) {
// Given...
factory := NewMockFactory()
var args []string = []string{"local"}

// When...
Execute(factory, args)

// Then...
stdOutConsole := factory.GetStdOutConsole().(*utils.MockConsole)
outText := stdOutConsole.ReadText()
assert.Contains(t, outText, "Usage:")
assert.Contains(t, outText, "galasactl local [command]")

// We expect an exit code of 0 for this command.
finalWordHandler := factory.GetFinalWordHandler().(*MockFinalWordHandler)
o := finalWordHandler.ReportedObject
assert.Nil(t, o)
}
2 changes: 1 addition & 1 deletion pkg/cmd/projectCreate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ func TestCreateProjectUsingCommandLineNoFeaturesSetWorks(t *testing.T) {
// Check that the default folder was created.
fs := factory.GetFileSystem()
var isExists bool
isExists, err = fs.DirExists("my.pkg")
isExists, _ = fs.DirExists("my.pkg")
assert.True(t, isExists)
}

Expand Down
28 changes: 28 additions & 0 deletions pkg/cmd/project_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cmd

import (
"testing"

"github.com/galasa-dev/cli/pkg/utils"
"github.com/stretchr/testify/assert"
)

func TestProjectNoCommandsProducesUsageReport(t *testing.T) {
// Given...
factory := NewMockFactory()
var args []string = []string{"project"}

// When...
Execute(factory, args)

// Then...
stdOutConsole := factory.GetStdOutConsole().(*utils.MockConsole)
outText := stdOutConsole.ReadText()
assert.Contains(t, outText, "Usage:")
assert.Contains(t, outText, "galasactl project [command]")

// We expect an exit code of 0 for this command.
finalWordHandler := factory.GetFinalWordHandler().(*MockFinalWordHandler)
o := finalWordHandler.ReportedObject
assert.Nil(t, o)
}
108 changes: 108 additions & 0 deletions pkg/cmd/propertiesDelete_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright contributors to the Galasa project
*
* SPDX-License-Identifier: EPL-2.0
*/
package cmd

import (
"testing"
"github.com/galasa-dev/cli/pkg/utils"
"github.com/stretchr/testify/assert"
)

func TestPropertiesDeleteNoArgsReturnsError(t *testing.T) {
// Given...
factory := NewMockFactory()
var args []string = []string{"properties", "delete"}

// When...
err := Execute(factory, args)

// Then...
stdOutConsole := factory.GetStdOutConsole().(*utils.MockConsole)
outText := stdOutConsole.ReadText()
assert.Contains(t, outText, "Usage:")
assert.Contains(t, outText, "galasactl properties delete [flags]")

stdErrConsole := factory.GetStdErrConsole().(*utils.MockConsole)
errText := stdErrConsole.ReadText()
assert.Contains(t, errText, "Error: required flag(s) \"name\", \"namespace\" not set")

// We expect an exit code of 1 for this command. But it seems that syntax errors caught by cobra still return no error.
finalWordHandler := factory.GetFinalWordHandler().(*MockFinalWordHandler)
o := finalWordHandler.ReportedObject
assert.Nil(t, o)

assert.NotNil(t, err)
}

func TestPropertiesDeleteWithoutName(t *testing.T) {
// Given...
factory := NewMockFactory()
var args []string = []string{"properties", "delete", "--namespace", "jitters"}

// When...
err := Execute(factory, args)

// Then...
stdOutConsole := factory.GetStdOutConsole().(*utils.MockConsole)
outText := stdOutConsole.ReadText()
assert.Contains(t, outText, "Usage:")

stdErrConsole := factory.GetStdErrConsole().(*utils.MockConsole)
errText := stdErrConsole.ReadText()
assert.Contains(t, errText, "Error: required flag(s) \"name\" not set")

// We expect an exit code of 1 for this command. But it seems that syntax errors caught by cobra still return no error.
finalWordHandler := factory.GetFinalWordHandler().(*MockFinalWordHandler)
o := finalWordHandler.ReportedObject
assert.Nil(t, o)

assert.NotNil(t, err)
}

func TestPropertiesDeleteWithoutNamespace(t *testing.T) {
// Given...
factory := NewMockFactory()
var args []string = []string{"properties", "delete", "--name", "jeepers"}

// When...
err := Execute(factory, args)

// Then...
stdOutConsole := factory.GetStdOutConsole().(*utils.MockConsole)
outText := stdOutConsole.ReadText()
assert.Contains(t, outText, "Usage:")

stdErrConsole := factory.GetStdErrConsole().(*utils.MockConsole)
errText := stdErrConsole.ReadText()
assert.Contains(t, errText, "Error: required flag(s) \"namespace\" not set")

// We expect an exit code of 1 for this command. But it seems that syntax errors caught by cobra still return no error.
finalWordHandler := factory.GetFinalWordHandler().(*MockFinalWordHandler)
o := finalWordHandler.ReportedObject
assert.Nil(t, o)

assert.NotNil(t, err)
}

func TestPropertiesDeleteWithNameAndNamespace(t *testing.T) {
// Given...
factory := NewMockFactory()
fs := factory.GetFileSystem()
var args []string = []string{"properties", "delete", "--namespace", "gyro", "--name", "space.ball"}
homeDir, _ := fs.GetUserHomeDirPath()
galasaDir := homeDir + "/.galasa/"
fs.WriteTextFile(galasaDir+"bootstrap.properties", "")

// When...
err := Execute(factory, args)

// Then...
assert.Nil(t, err)

stdOutConsole := factory.GetStdOutConsole().(*utils.MockConsole)
outText := stdOutConsole.ReadText()
assert.Equal(t, outText, "")
}
86 changes: 86 additions & 0 deletions pkg/cmd/propertiesGet_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright contributors to the Galasa project
*
* SPDX-License-Identifier: EPL-2.0
*/
package cmd

import (
"testing"

"github.com/galasa-dev/cli/pkg/utils"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)

func propertiesExectuteTestReplacement(cmd *cobra.Command, args []string) error {
return nil
}

func TestPropertiesGetNoArgsReturnsError(t *testing.T) {
// Given...
factory := NewMockFactory()
var args []string = []string{"properties", "get"}

// When...
err := Execute(factory, args)

// Then...
stdOutConsole := factory.GetStdOutConsole().(*utils.MockConsole)
outText := stdOutConsole.ReadText()
assert.Contains(t, outText, "Usage:")
assert.Contains(t, outText, "galasactl properties get [flags]")

stdErrConsole := factory.GetStdErrConsole().(*utils.MockConsole)
errText := stdErrConsole.ReadText()
assert.Contains(t, errText, "Error: required flag(s) \"namespace\" not set")

// We expect an exit code of 1 for this command. But it seems that syntax errors caught by cobra still return no error.
finalWordHandler := factory.GetFinalWordHandler().(*MockFinalWordHandler)
o := finalWordHandler.ReportedObject
assert.Nil(t, o)

assert.NotNil(t, err)
}

// func TestPropertiesGetWithNamespaceReturnsTable(t *testing.T) {
// // Given...
// factory := NewMockFactory()
// fs := factory.GetFileSystem()
// homeDir, _ := fs.GetUserHomeDirPath()
// galasaDir := homeDir + "/.galasa/"
// fs.WriteTextFile(galasaDir+"bootstrap.properties", "")
// var args []string = []string{"properties", "get", "--namespace", "framework", "--log", "-"}

// var err error

// var commands map[string]*cobra.Command
// var parsedCommandValues map[string]interface{}

// commands, parsedCommandValues, err = CreateCommandTree(factory)
// rootCmd := commands["root"]
// propsGetCmd := commands["properties get"]

// // TODO: Over-ride the RunE function...
// propsGetCmd.RunE = propertiesExectuteTestReplacement

// rootCmd.SetArgs(args)

// // When...
// // err := Execute(factory, args)
// err = rootCmd.Execute()

// // Then...
// assert.Nil(t, err)

// propsGetData := parsedCommandValues["properties get"].(PropertiesGetCmdValues)
// assert.Nil(t, propsGetData.propertiesInfix)
// assert.Nil(t, propsGetData.propertiesPrefix)
// assert.Nil(t, propsGetData.propertiesSuffix)

// propsData := parsedCommandValues["properties"].(PropertiesCmdValues)
// assert.Equal(t, "framework", propsData.namespace)

// rootData := parsedCommandValues["root"].(RootCmdValues)
// assert.Equal(t, "-", rootData.logFileName)
// }
33 changes: 33 additions & 0 deletions pkg/cmd/properties_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright contributors to the Galasa project
*
* SPDX-License-Identifier: EPL-2.0
*/
package cmd

import (
"testing"

"github.com/galasa-dev/cli/pkg/utils"
"github.com/stretchr/testify/assert"
)

func TestPropertiesNoCommandsProducesUsageReport(t *testing.T) {
// Given...
factory := NewMockFactory()
var args []string = []string{"properties"}

// When...
Execute(factory, args)

// Then...
stdOutConsole := factory.GetStdOutConsole().(*utils.MockConsole)
outText := stdOutConsole.ReadText()
assert.Contains(t, outText, "Usage:")
assert.Contains(t, outText, "galasactl properties [command]")

// We expect an exit code of 0 for this command.
finalWordHandler := factory.GetFinalWordHandler().(*MockFinalWordHandler)
o := finalWordHandler.ReportedObject
assert.Nil(t, o)
}
53 changes: 53 additions & 0 deletions pkg/cmd/runsSubmitLocal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright contributors to the Galasa project
*
* SPDX-License-Identifier: EPL-2.0
*/
package cmd

import (
"testing"
"github.com/stretchr/testify/assert"
)

func TestRunsSubmitLocalWithoutObrWithClassErrors(t *testing.T) {
// Given...
factory := NewMockFactory()
var args []string = []string{"runs", "submit", "local", "--class", "osgi.bundle/class.path"}

// When...
err := Execute(factory, args)

// Then...
// Should throw an error asking for flags to be set
assert.NotNil(t, err, "err should have been set!")
assert.Contains(t, err.Error(), "required flag(s) \"obr\" not set")
}

func TestRunsSubmitLocalWithoutClassWithObrErrors(t *testing.T) {
// Given...
factory := NewMockFactory()
var args []string = []string{"runs", "submit", "local", "--obr", "mvn:second.breakfast/elevenses/0.1.0/brunch"}

// When...
err := Execute(factory, args)

// Then...
// Should throw an error asking for flags to be set
assert.NotNil(t, err, "err should have been set!")
assert.Contains(t, err.Error(), "required flag(s) \"class\" not set")
}

func TestMultipleRequiredFlagsNotSetReturnsListInError(t *testing.T) {
// Given...
factory := NewMockFactory()
var args []string = []string{"runs", "submit", "local"}

// When...
err := Execute(factory, args)

// Then...
// Should throw an error asking for flags to be set
assert.NotNil(t, err, "err should have been set!")
assert.Contains(t, err.Error(), "required flag(s) \"class\", \"obr\" not set")
}
39 changes: 39 additions & 0 deletions pkg/cmd/runsSubmit_tests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright contributors to the Galasa project
*
* SPDX-License-Identifier: EPL-2.0
*/
package cmd

import (
"testing"
"github.com/stretchr/testify/assert"
)

func TestRunsSubmitWithoutFlagsErrors(t *testing.T) {
// Given...
factory := NewMockFactory()
var args []string = []string{"runs", "submit", "local"}

// When...
err := Execute(factory, args)

// Then...
// Should throw an error asking for flags to be set
assert.NotNil(t, err, "err should have been set!")
assert.Contains(t, err.Error(), "GAL1009E: The submit command requires either test selection flags (eg: --stream, --class, --bundle, --package, --tag, --regex, --test) or --portfolio flag to be specified. Use the --help flag for more details.")
}

func TestRunsSubmitExecutesWithPortfolio(t *testing.T) {
// Given...
factory := NewMockFactory()
var args []string = []string{"runs", "submit", "local", "--class", "osgi.bundle/class.path"}

// When...
err := Execute(factory, args)

// Then...
// Should throw an error asking for flags to be set
assert.NotNil(t, err, "err should have been set!")
assert.Contains(t, err.Error(), "required flag(s) \"obr\" not set")
}