-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create test_masonry.go for Masonry func
- Loading branch information
1 parent
891c33b
commit ce31a59
Showing
6 changed files
with
40 additions
and
65 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
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 |
---|---|---|
@@ -1,50 +1,33 @@ | ||
package diff_test | ||
|
||
import ( | ||
"bufio" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
. "github.com/onsi/gomega/gexec" | ||
"github.com/opencontrol/compliance-masonry/pkg/tests" | ||
) | ||
|
||
var _ = Describe("Diff Commands", func() { | ||
Describe("When the diff command is run", func() { | ||
It("should let the user know that they have not described a certification and show how to use the command", func() { | ||
output := Masonry("diff") | ||
output := testMasonry.Masonry("diff") | ||
Eventually(output.Err.Contents).Should(ContainSubstring("certification type not specified\n")) | ||
}) | ||
}) | ||
Describe("When the CLI is run with the `diff` command without opencontrols dir", func() { | ||
It("should let the user know that there is no opencontrols/certifications directory", func() { | ||
output := Masonry("diff", "LATO") | ||
output := testMasonry.Masonry("diff", "LATO") | ||
Eventually(output.Err.Contents).Should(ContainSubstring("Error: `" + filepath.Join("opencontrols", "certifications") + "` directory does exist\n")) | ||
}) | ||
}) | ||
Describe("When the CLI is run with the `diff` command with a certification", func() { | ||
It("should print the number of missing controls", func() { | ||
output := Masonry( | ||
output := testMasonry.Masonry( | ||
"diff", "LATO", | ||
"-o", filepath.Join("..", "..", "..", "test", "fixtures", "opencontrol_fixtures")).Wait(1 * time.Second) | ||
Eventually(output.Out.Contents).Should(ContainSubstring("Number of missing controls:")) | ||
}) | ||
}) | ||
}) | ||
|
||
func Masonry(args ...string) *Session { | ||
path, err := Build("github.com/opencontrol/compliance-masonry/cmd/compliance-masonry") | ||
Expect(err).NotTo(HaveOccurred()) | ||
cmd := exec.Command(path, args...) | ||
stdin, err := cmd.StdinPipe() | ||
Expect(err).ToNot(HaveOccurred()) | ||
buffer := bufio.NewWriter(stdin) | ||
_, _ = buffer.WriteString(strings.Join(args, " ")) | ||
_ = buffer.Flush() | ||
session, err := Start(cmd, GinkgoWriter, GinkgoWriter) | ||
Expect(err).NotTo(HaveOccurred()) | ||
return session | ||
} |
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
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
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
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,26 @@ | ||
package testMasonry | ||
|
||
import ( | ||
"bufio" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/onsi/ginkgo" | ||
"github.com/onsi/gomega" | ||
"github.com/onsi/gomega/gexec" | ||
) | ||
|
||
// Masonry is used to launch tests on the CLI | ||
func Masonry(args ...string) *Session { | ||
path, err := Build("github.com/opencontrol/compliance-masonry/cmd/compliance-masonry") | ||
Expect(err).NotTo(HaveOccurred()) | ||
cmd := exec.Command(path, args...) | ||
stdin, err := cmd.StdinPipe() | ||
Expect(err).ToNot(HaveOccurred()) | ||
buffer := bufio.NewWriter(stdin) | ||
_, _ = buffer.WriteString(strings.Join(args, " ")) | ||
_ = buffer.Flush() | ||
session, err := Start(cmd, GinkgoWriter, GinkgoWriter) | ||
Expect(err).NotTo(HaveOccurred()) | ||
return session | ||
} |