-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Create a BDD Test Automation Framework with ginkgo #552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-robot
merged 3 commits into
openshift:master
from
alejovicu:libvirt-tests
Feb 5, 2019
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
242 changes: 242 additions & 0 deletions
242
tests/bdd-smoke/suites/config/libvirt/install_config_test.go
This file contains hidden or 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,242 @@ | ||
| package config_test | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/openshift/installer/tests/bdd-smoke/utils" | ||
|
|
||
| . "github.com/onsi/ginkgo" | ||
| . "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| func TestInstallConfig(t *testing.T) { | ||
| RegisterFailHandler(Fail) | ||
| RunSpecs(t, "Test Suite for create install-config in libvirt") | ||
| } | ||
|
|
||
| var _ = Describe("Feature: Check that install-config command generates the install configuration asset for libvirt", func() { | ||
|
|
||
| openshiftInstallerPath := os.Getenv("GOPATH") + "/src/github.com/openshift/installer" | ||
| openshiftInstallBinPath := openshiftInstallerPath + "/bin/openshift-install" | ||
|
|
||
| AfterSuite(func() { | ||
| args := []string{"-rf", | ||
| "scenario1/", | ||
| "scenario3/", | ||
| "scenario4/", | ||
| "scenario5/", | ||
| "tests/bdd-smoke/suites/config/libvirt/scenario6/", | ||
| ".openshift_install_state.json", | ||
| ".openshift_install.log", | ||
| "install-config.yaml"} | ||
| utils.RunOSCommandWithArgs("rm", args, openshiftInstallerPath) | ||
| }) | ||
|
|
||
| // tests for openshift-install create install-config | ||
| Context("Scenario: Generate configuration asset specifying a directory", func() { | ||
| testData := &utils.DataToValidate{ | ||
| BaseDomain: "tt.testing", | ||
| ClusterName: "test1", | ||
| SSH: "id_rsa.pub", | ||
| PullSecret: `{"auths": {"quay.io": {"auth": "aValidPullSecret","email": ""}}}`, | ||
| ConnectionURI: "qemu+tcp://192.168.122.1/system", | ||
| } | ||
|
|
||
| It("Given that the openshift-install is compiled", func() { | ||
| Ω(openshiftInstallBinPath).Should(BeAnExistingFile()) | ||
| }) | ||
| It("When I execute openshift-install create install-config --dir=scenario1", func() { | ||
| args := []string{"create", "install-config", "--dir=scenario1"} | ||
| commandLineArgs := [][]string{ | ||
| {"SSH Public Key", testData.SSH}, | ||
| {"Platform", "libvirt"}, | ||
| {"Libvirt Connection URI", testData.ConnectionURI}, | ||
| {"Base Domain", testData.BaseDomain}, | ||
| {"Cluster Name", testData.ClusterName}, | ||
| {"Pull Secret", testData.PullSecret}, | ||
| } | ||
| cmdOut := utils.RunInstallerWithSurvey(args, openshiftInstallerPath, commandLineArgs) | ||
| Ω(cmdOut).Should(ContainSubstring(".ssh/id_rsa.pub")) | ||
| Ω(cmdOut).Should(ContainSubstring("Platform libvirt")) | ||
| Ω(cmdOut).Should(ContainSubstring("Libvirt Connection URI qemu+tcp://192.168.122.1/system")) | ||
| Ω(cmdOut).Should(ContainSubstring("Base Domain tt.testing")) | ||
| Ω(cmdOut).Should(ContainSubstring("Cluster Name test1")) | ||
| }) | ||
| Specify("Then I expect to see the install-config.yaml file in the path ./scenario1/", func() { | ||
| Ω(openshiftInstallerPath + "/scenario1/install-config.yaml").Should(BeAnExistingFile()) | ||
| }) | ||
| Specify("And I expect install-config.yaml file contains the info specified in the environment variables", func() { | ||
| utils.ValidateInstallConfig(openshiftInstallerPath+"/scenario1/install-config.yaml", *testData) | ||
| }) | ||
| Specify("And I expect .openshift_install_state.json file contains the info specified in the environment variables", func() { | ||
| utils.ValidateInstallStateConfig(openshiftInstallerPath+"/scenario1/.openshift_install_state.json", *testData) | ||
| }) | ||
| }) | ||
|
|
||
| Context("Scenario: Generate configuration asset without specifying a directory with log level in debug", func() { | ||
| testData := &utils.DataToValidate{ | ||
| BaseDomain: "tt.testing", | ||
| ClusterName: "test1", | ||
| SSH: "id_rsa.pub", | ||
| PullSecret: `{"auths": {"quay.io": {"auth": "aValidPullSecret","email": ""}}}`, | ||
| ConnectionURI: "qemu+tcp://192.168.122.1/system", | ||
| } | ||
| It("Given that the openshift-install is compiled", func() { | ||
| Ω(openshiftInstallBinPath).Should(BeAnExistingFile()) | ||
| }) | ||
| It("When I execute bin/openshift-install install-config --log-level=debug", func() { | ||
| args := []string{"create", "install-config", "--log-level=debug"} | ||
| commandLineArgs := [][]string{ | ||
| {"SSH Public Key", testData.SSH}, | ||
| {"Platform", "libvirt"}, | ||
| {"Libvirt Connection URI", testData.ConnectionURI}, | ||
| {"Base Domain", testData.BaseDomain}, | ||
| {"Cluster Name", testData.ClusterName}, | ||
| {"Pull Secret", testData.PullSecret}, | ||
| } | ||
| cmdOut := utils.RunInstallerWithSurvey(args, openshiftInstallerPath, commandLineArgs) | ||
| Ω(cmdOut).Should(ContainSubstring(".ssh/id_rsa.pub")) | ||
| Ω(cmdOut).Should(ContainSubstring("Platform libvirt")) | ||
| Ω(cmdOut).Should(ContainSubstring("Libvirt Connection URI qemu+tcp://192.168.122.1/system")) | ||
| Ω(cmdOut).Should(ContainSubstring("Base Domain tt.testing")) | ||
| Ω(cmdOut).Should(ContainSubstring("Cluster Name test1")) | ||
| }) | ||
| Specify("Then I expect to see the install-config.yaml file in the path ./", func() { | ||
| Ω(openshiftInstallerPath + "/install-config.yaml").Should(BeAnExistingFile()) | ||
| }) | ||
| Specify("And I expect to see the .openshift_install_state.json file in the path ./", func() { | ||
| Ω(openshiftInstallerPath + "/.openshift_install_state.json").Should(BeAnExistingFile()) | ||
| }) | ||
| Specify("And I expect install-config.yaml file contains the info specified in the environment variables", func() { | ||
| utils.ValidateInstallConfig(openshiftInstallerPath+"/install-config.yaml", *testData) | ||
| }) | ||
| Specify("And I expect .openshift_install_state.json file contains the info specified in the environment variables", func() { | ||
| utils.ValidateInstallStateConfig(openshiftInstallerPath+"/.openshift_install_state.json", *testData) | ||
| }) | ||
| }) | ||
|
|
||
| Context("Scenario: Generate configuration asset specifying a directory with log level in error", func() { | ||
| cmdOut := "" | ||
| testData := &utils.DataToValidate{ | ||
| BaseDomain: "tt.testing", | ||
| ClusterName: "test1", | ||
| SSH: "id_rsa.pub", | ||
| PullSecret: `{"auths": {"quay.io": {"auth": "aValidPullSecret","email": ""}}}`, | ||
| ConnectionURI: "qemu+tcp://192.168.122.1/system", | ||
| } | ||
| It("Given that the openshift-install is compiled", func() { | ||
| Ω(openshiftInstallBinPath).Should(BeAnExistingFile()) | ||
| }) | ||
| It("When I execute bin/openshift-install install-config --dir=scenario3 --log-level=error", func() { | ||
| args := []string{"create", "install-config", "--dir=scenario3", "--log-level=error"} | ||
| commandLineArgs := [][]string{ | ||
| {"SSH Public Key", testData.SSH}, | ||
| {"Platform", "libvirt"}, | ||
| {"Libvirt Connection URI", testData.ConnectionURI}, | ||
| {"Base Domain", testData.BaseDomain}, | ||
| {"Cluster Name", testData.ClusterName}, | ||
| {"Pull Secret", testData.PullSecret}, | ||
| } | ||
| cmdOut := utils.RunInstallerWithSurvey(args, openshiftInstallerPath, commandLineArgs) | ||
| Ω(cmdOut).Should(ContainSubstring(".ssh/id_rsa.pub")) | ||
| Ω(cmdOut).Should(ContainSubstring("Platform libvirt")) | ||
| Ω(cmdOut).Should(ContainSubstring("Libvirt Connection URI qemu+tcp://192.168.122.1/system")) | ||
| Ω(cmdOut).Should(ContainSubstring("Base Domain tt.testing")) | ||
| Ω(cmdOut).Should(ContainSubstring("Cluster Name test1")) | ||
| }) | ||
| Specify("Then I expect to see the install-config.yaml file in the path ./scenario3", func() { | ||
| Ω(openshiftInstallerPath + "/scenario3/install-config.yaml").Should(BeAnExistingFile()) | ||
| }) | ||
| Specify("And I expect install-config.yaml file contains the info specified in the environment variables", func() { | ||
| utils.ValidateInstallConfig(openshiftInstallerPath+"/scenario3/install-config.yaml", *testData) | ||
| }) | ||
| Specify("And I expect .openshift_install_state.json file contains the info specified in the environment variables", func() { | ||
| utils.ValidateInstallStateConfig(openshiftInstallerPath+"/scenario3/.openshift_install_state.json", *testData) | ||
| }) | ||
| Specify("And I expect to not to get any error in output log from the console", func() { | ||
| Ω(cmdOut).Should(Equal("")) | ||
| }) | ||
| }) | ||
|
|
||
| Context("Scenario: Generate configuration asset specifying a directory running it from other path", func() { | ||
| cmdOut := "" | ||
| testData := &utils.DataToValidate{ | ||
| BaseDomain: "tt.testing", | ||
| ClusterName: "test1", | ||
| SSH: "id_rsa.pub", | ||
| PullSecret: `{"auths": {"quay.io": {"auth": "aValidPullSecret","email": ""}}}`, | ||
| ConnectionURI: "qemu+tcp://192.168.122.1/system", | ||
| } | ||
| It("Given that the openshift-install is compiled", func() { | ||
| Ω(openshiftInstallBinPath).Should(BeAnExistingFile()) | ||
| }) | ||
| It("When I execute bin/openshift-install install-config --dir=scenario6 --log-level=error", func() { | ||
| args := []string{"create", "install-config", "--dir=scenario6"} | ||
| commandLineArgs := [][]string{ | ||
| {"SSH Public Key", testData.SSH}, | ||
| {"Platform", "libvirt"}, | ||
| {"Libvirt Connection URI", testData.ConnectionURI}, | ||
| {"Base Domain", testData.BaseDomain}, | ||
| {"Cluster Name", testData.ClusterName}, | ||
| {"Pull Secret", testData.PullSecret}, | ||
| } | ||
| cmdOut := utils.RunInstallerWithSurvey(args, ".", commandLineArgs) | ||
| Ω(cmdOut).Should(ContainSubstring(".ssh/id_rsa.pub")) | ||
| Ω(cmdOut).Should(ContainSubstring("Platform libvirt")) | ||
| Ω(cmdOut).Should(ContainSubstring("Libvirt Connection URI qemu+tcp://192.168.122.1/system")) | ||
| Ω(cmdOut).Should(ContainSubstring("Base Domain tt.testing")) | ||
| Ω(cmdOut).Should(ContainSubstring("Cluster Name test1")) | ||
| }) | ||
| Specify("Then I expect to see the install-config.yaml file in the path ./scenario6", func() { | ||
| Ω("scenario6/install-config.yaml").Should(BeAnExistingFile()) | ||
| }) | ||
| Specify("And I expect install-config.yaml file contains the info specified in the environment variables", func() { | ||
| utils.ValidateInstallConfig("scenario6/install-config.yaml", *testData) | ||
| }) | ||
| Specify("And I expect .openshift_install_state.json file contains the info specified in the environment variables", func() { | ||
| utils.ValidateInstallStateConfig("scenario6/.openshift_install_state.json", *testData) | ||
| }) | ||
| Specify("And I expect to not to get any error in output log from the console", func() { | ||
| Ω(cmdOut).Should(Equal("")) | ||
| }) | ||
| }) | ||
|
|
||
| Context("Scenario: Use previously generated configuration asset without specifying a directory with log level in debug", func() { | ||
| testData := &utils.DataToValidate{ | ||
| BaseDomain: "tt.testing", | ||
| ClusterName: "test1", | ||
| SSH: "id_rsa.pub", | ||
| PullSecret: `{"auths": {"quay.io": {"auth": "aValidPullSecret","email": ""}}}`, | ||
| ConnectionURI: "qemu+tcp://192.168.122.1/system", | ||
| } | ||
| It("Given that the openshift-install is compiled", func() { | ||
| Ω(openshiftInstallBinPath).Should(BeAnExistingFile()) | ||
| }) | ||
| It("When I execute bin/openshift-install install-config --log-level=debug", func() { | ||
| args := []string{"create", "install-config", "--log-level=debug"} | ||
| commandLineArgs := [][]string{ | ||
| {"SSH Public Key", testData.SSH}, | ||
| {"Platform", "libvirt"}, | ||
| {"Libvirt Connection URI", testData.ConnectionURI}, | ||
| {"Base Domain", testData.BaseDomain}, | ||
| {"Cluster Name", testData.ClusterName}, | ||
| {"Pull Secret", testData.PullSecret}, | ||
| } | ||
| cmdOut := utils.RunInstallerWithSurvey(args, openshiftInstallerPath, commandLineArgs) | ||
| Ω(cmdOut).Should(ContainSubstring("")) | ||
| }) | ||
| Specify("Then I expect to see the install-config.yaml file in the path ./", func() { | ||
| Ω(openshiftInstallerPath + "/install-config.yaml").Should(BeAnExistingFile()) | ||
| }) | ||
| Specify("And I expect to see the .openshift_install_state.json file in the path ./", func() { | ||
| Ω(openshiftInstallerPath + "/.openshift_install_state.json").Should(BeAnExistingFile()) | ||
| }) | ||
| Specify("And I expect install-config.yaml file contains the info specified in the environment variables", func() { | ||
| utils.ValidateInstallConfig(openshiftInstallerPath+"/install-config.yaml", *testData) | ||
| }) | ||
| Specify("And I expect .openshift_install_state.json file contains the info specified in the environment variables", func() { | ||
| utils.ValidateInstallStateConfig(openshiftInstallerPath+"/.openshift_install_state.json", *testData) | ||
| }) | ||
| }) | ||
| }) | ||
This file contains hidden or 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,13 @@ | ||
| package utils | ||
|
|
||
| import ( | ||
| "log" | ||
| "strings" | ||
| ) | ||
|
|
||
| // AssertStringContains compares two strings and fails if it isn't contained | ||
| func AssertStringContains(mainString string, subString string, errorMessage string) { | ||
| if !strings.Contains(mainString, subString) { | ||
| log.Fatal("Error: " + errorMessage + "\nExpected <<" + mainString + ">> but was <<" + subString + ">>") | ||
| } | ||
| } |
This file contains hidden or 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,76 @@ | ||
| package utils | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "fmt" | ||
| "log" | ||
| "os" | ||
| "os/exec" | ||
| "strings" | ||
| "time" | ||
|
|
||
| expect "github.com/Netflix/go-expect" | ||
| "github.com/hinshun/vt10x" | ||
| ) | ||
|
|
||
| // RunOSCommandWithArgs executes a command in the operating system with arguments | ||
| func RunOSCommandWithArgs(command string, arguments []string, path string) string { | ||
| cmd := exec.Command(command, arguments...) | ||
| cmd.Dir = path | ||
| cmd.Stdin = strings.NewReader("") | ||
| var outb, errb bytes.Buffer | ||
| cmd.Stdout = &outb | ||
| cmd.Stderr = &errb | ||
| err := cmd.Run() | ||
| if err != nil { | ||
| fmt.Println("Error: failed running the command \"" + command + "\" with the arguments:") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this could be more robust and compact with: fmt.Printf("Error: failed running the command %q with the arguments:", command)although printing straight to the terminal feels strange anyway. Does that get captured somewhere? Should we be logging these instead, or attaching it to the error before passing it to |
||
| fmt.Println(arguments) | ||
| fmt.Println(errb.String()) | ||
| log.Fatal(err) | ||
| } | ||
| return outb.String() + errb.String() | ||
| } | ||
|
|
||
| // RunInstallerWithSurvey run the installer given the command arguments, the path where will be launched and the command line values for survey | ||
| func RunInstallerWithSurvey(arguments []string, path string, commandLineArgs [][]string) string { | ||
| openshiftInstallBin := os.Getenv("GOPATH") + "/src/github.com/openshift/installer/bin/openshift-install" | ||
|
|
||
| c, state, errVt10x := vt10x.NewVT10XConsole() | ||
| if errVt10x != nil { | ||
| fmt.Println("Error: failed starting vt10x console") | ||
| log.Fatal(errVt10x) | ||
| } | ||
| defer c.Close() | ||
|
|
||
| donec := make(chan struct{}) | ||
| go func() { | ||
| defer close(donec) | ||
|
|
||
| for _, command := range commandLineArgs { | ||
| c.ExpectString(command[0]) | ||
| c.SendLine(command[1]) | ||
| } | ||
| c.ExpectEOF() | ||
| }() | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) | ||
| defer cancel() | ||
| cmd := exec.CommandContext(ctx, openshiftInstallBin, arguments...) | ||
| cmd.Dir = path | ||
| cmd.Stdin = c.Tty() | ||
| cmd.Stdout = c.Tty() | ||
| cmd.Stderr = c.Tty() | ||
|
|
||
| errCmd := cmd.Run() | ||
| if errVt10x != nil { | ||
| fmt.Println("Error: running the command : " + openshiftInstallBin + " with the arguments") | ||
| fmt.Println(arguments) | ||
| fmt.Println(commandLineArgs) | ||
| log.Fatal(errCmd) | ||
| } | ||
| c.Tty().Close() | ||
| <-donec | ||
|
|
||
| return expect.StripTrailingEmptyLines(state.String()) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: these aren't environment variables any more (and also in several other
Specifystrings in this commit).