This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(GH-28) Add acceptance tests for
prm set|get
- Loading branch information
sanfrancrisko
committed
Dec 3, 2021
1 parent
efcbc4e
commit ac22a1f
Showing
2 changed files
with
215 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,110 @@ | ||
package get_test | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/puppetlabs/pdkgo/acceptance/testutils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const APP = "prm" | ||
|
||
func Test_PrmGet_NoArgs(t *testing.T) { | ||
testutils.SkipAcceptanceTest(t) | ||
|
||
// Setup | ||
testutils.SetAppName(APP) | ||
|
||
// Exec | ||
stdout, stderr, exitCode := testutils.RunAppCommand("get", "") | ||
|
||
// Assert | ||
assert.Contains(t, stdout, "Displays the requested configuration value\n\nUsage:\n prm get") | ||
assert.Empty(t, stderr) | ||
assert.Equal(t, 0, exitCode) | ||
} | ||
|
||
func Test_PrmGet_Puppet_FirstRun(t *testing.T) { | ||
testutils.SkipAcceptanceTest(t) | ||
|
||
// Setup | ||
testutils.SetAppName(APP) | ||
tempDir := testutils.GetTmpDir(t) | ||
|
||
// Exec | ||
stdout, stderr, exitCode := testutils.RunAppCommand(fmt.Sprintf("get puppet --config %s", filepath.Join(tempDir, ".prm.yaml")), "") | ||
|
||
// Assert | ||
assert.Contains(t, stdout, "Puppet version is configured to: 7.0.0") | ||
assert.Empty(t, stderr) | ||
assert.Equal(t, 0, exitCode) | ||
} | ||
|
||
func Test_PrmGet_Backend_FirstRun(t *testing.T) { | ||
testutils.SkipAcceptanceTest(t) | ||
|
||
// Setup | ||
testutils.SetAppName(APP) | ||
tempDir := testutils.GetTmpDir(t) | ||
|
||
// Exec | ||
stdout, stderr, exitCode := testutils.RunAppCommand(fmt.Sprintf("get backend --config %s", filepath.Join(tempDir, ".prm.yaml")), "") | ||
|
||
// Assert | ||
assert.Contains(t, stdout, "Backend is configured to: docker") | ||
assert.Empty(t, stderr) | ||
assert.Equal(t, 0, exitCode) | ||
} | ||
|
||
func Test_PrmGet_Puppet_EnsureSet(t *testing.T) { | ||
testutils.SkipAcceptanceTest(t) | ||
|
||
// Setup | ||
testutils.SetAppName(APP) | ||
tempDir := testutils.GetTmpDir(t) | ||
|
||
// Exec | ||
_, _, _ = testutils.RunAppCommand(fmt.Sprintf("set puppet 1.2.3 --config %s", filepath.Join(tempDir, ".prm.yaml")), "") | ||
stdout, stderr, exitCode := testutils.RunAppCommand(fmt.Sprintf("get puppet --config %s", filepath.Join(tempDir, ".prm.yaml")), "") | ||
|
||
// Assert | ||
assert.Contains(t, stdout, "Puppet version is configured to: 1.2.3") | ||
assert.Empty(t, stderr) | ||
assert.Equal(t, 0, exitCode) | ||
} | ||
|
||
func Test_PrmGet_Backend_EnsureSet(t *testing.T) { | ||
testutils.SkipAcceptanceTest(t) | ||
|
||
// Setup | ||
testutils.SetAppName(APP) | ||
tempDir := testutils.GetTmpDir(t) | ||
|
||
// Exec | ||
// TODO: This test should set the value to something other than 'docker' when more options become available, to test | ||
// this functionality properly | ||
_, _, _ = testutils.RunAppCommand(fmt.Sprintf("set backend docker --config %s", filepath.Join(tempDir, ".prm.yaml")), "") | ||
stdout, stderr, exitCode := testutils.RunAppCommand(fmt.Sprintf("get backend --config %s", filepath.Join(tempDir, ".prm.yaml")), "") | ||
|
||
// Assert | ||
assert.Contains(t, stdout, "Backend is configured to: docker") | ||
assert.Empty(t, stderr) | ||
assert.Equal(t, 0, exitCode) | ||
} | ||
|
||
func Test_PrmGet_InvalidArg(t *testing.T) { | ||
testutils.SkipAcceptanceTest(t) | ||
|
||
// Setup | ||
testutils.SetAppName(APP) | ||
|
||
// Exec | ||
stdout, stderr, exitCode := testutils.RunAppCommand("get foo", "") | ||
|
||
// Assert | ||
assert.Contains(t, stdout, "Displays the requested configuration value\n\nUsage:\n prm get") | ||
assert.Empty(t, stderr) | ||
assert.Equal(t, 0, exitCode) | ||
} |
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,105 @@ | ||
package set_test | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/puppetlabs/pdkgo/acceptance/testutils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const APP = "prm" | ||
|
||
func Test_PrmSet_NoArgs(t *testing.T) { | ||
testutils.SkipAcceptanceTest(t) | ||
|
||
// Setup | ||
testutils.SetAppName(APP) | ||
|
||
// Exec | ||
stdout, stderr, exitCode := testutils.RunAppCommand("set", "") | ||
|
||
// Assert | ||
assert.Contains(t, stdout, "Sets the specified configuration to the specified value\n\nUsage:\n prm set") | ||
assert.Empty(t, stderr) | ||
assert.Equal(t, 0, exitCode) | ||
} | ||
|
||
func Test_PrmSet_Puppet_NoArgs(t *testing.T) { | ||
testutils.SkipAcceptanceTest(t) | ||
|
||
// Setup | ||
testutils.SetAppName(APP) | ||
|
||
// Exec | ||
stdout, stderr, exitCode := testutils.RunAppCommand("set puppet", "") | ||
|
||
// Assert | ||
assert.Equal(t, "Error: please specify a Puppet version after 'set puppet'\n", stdout) | ||
assert.Equal(t, "exit status 1", stderr) | ||
assert.Equal(t, 1, exitCode) | ||
} | ||
|
||
func Test_PrmSet_Puppet_ValidVer(t *testing.T) { | ||
testutils.SkipAcceptanceTest(t) | ||
|
||
// Setup | ||
testutils.SetAppName(APP) | ||
tempDir := testutils.GetTmpDir(t) | ||
|
||
// Exec | ||
stdout, stderr, exitCode := testutils.RunAppCommand(fmt.Sprintf("set puppet 1.2.3 --config %s", filepath.Join(tempDir, ".prm.yaml")), "") | ||
|
||
// Assert | ||
assert.Empty(t, stdout) | ||
assert.Empty(t, stderr) | ||
assert.Equal(t, 0, exitCode) | ||
|
||
stdout, stderr, exitCode = testutils.RunAppCommand(fmt.Sprintf("get puppet --config %s", filepath.Join(tempDir, ".prm.yaml")), "") | ||
assert.Contains(t, stdout, "Puppet version is configured to: 1.2.3") | ||
assert.Empty(t, stderr) | ||
assert.Equal(t, 0, exitCode) | ||
} | ||
|
||
func Test_PrmSet_Puppet_InvalidVer(t *testing.T) { | ||
testutils.SkipAcceptanceTest(t) | ||
|
||
// Setup | ||
testutils.SetAppName(APP) | ||
tempDir := testutils.GetTmpDir(t) | ||
|
||
// Exec | ||
stdout, stderr, exitCode := testutils.RunAppCommand(fmt.Sprintf("set puppet foo.bar --config %s", filepath.Join(tempDir, ".prm.yaml")), "") | ||
|
||
// Assert | ||
assert.Contains(t, stdout, "'foo.bar' is not a semantic (x.y.z) Puppet version: Invalid Semantic Version") | ||
assert.Equal(t, "exit status 1", stderr) | ||
assert.Equal(t, 1, exitCode) | ||
|
||
stdout, stderr, exitCode = testutils.RunAppCommand(fmt.Sprintf("get puppet --config %s", filepath.Join(tempDir, ".prm.yaml")), "") | ||
assert.Contains(t, stdout, "Puppet version is configured to: 7.0.0") | ||
assert.Empty(t, stderr) | ||
assert.Equal(t, 0, exitCode) | ||
} | ||
|
||
func Test_PrmSet_Backend_InvalidOpt(t *testing.T) { | ||
testutils.SkipAcceptanceTest(t) | ||
|
||
// Setup | ||
testutils.SetAppName(APP) | ||
tempDir := testutils.GetTmpDir(t) | ||
|
||
// Exec | ||
stdout, stderr, exitCode := testutils.RunAppCommand(fmt.Sprintf("set backend foo.bar --config %s", filepath.Join(tempDir, ".prm.yaml")), "") | ||
|
||
// Assert | ||
assert.Contains(t, stdout, "'foo.bar' is not a valid backend type, please specify one of the following backend types:") | ||
assert.Equal(t, "exit status 1", stderr) | ||
assert.Equal(t, 1, exitCode) | ||
|
||
stdout, stderr, exitCode = testutils.RunAppCommand(fmt.Sprintf("get backend --config %s", filepath.Join(tempDir, ".prm.yaml")), "") | ||
assert.Contains(t, stdout, "Backend is configured to: docker") | ||
assert.Empty(t, stderr) | ||
assert.Equal(t, 0, exitCode) | ||
} |