-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(integration): Add scaffold for running integration tests (#73)
Signed-off-by: Daniel Pacak <pacak.daniel@gmail.com>
- Loading branch information
1 parent
a0ad1ad
commit bce75c3
Showing
8 changed files
with
140 additions
and
5 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
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,50 @@ | ||
package integration_tests | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/onsi/gomega/gexec" | ||
"k8s.io/client-go/tools/clientcmd" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
apiextensions "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1beta1" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
var ( | ||
kubernetesClientset kubernetes.Interface | ||
apiextensionsClientset apiextensions.ApiextensionsV1beta1Interface | ||
) | ||
|
||
var ( | ||
pathToStarboardCLI string | ||
) | ||
|
||
var _ = BeforeSuite(func() { | ||
var err error | ||
pathToStarboardCLI, err = gexec.Build("github.com/aquasecurity/starboard/cmd/starboard") | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
config, err := clientcmd.BuildConfigFromFlags("", os.Getenv("KUBECONFIG")) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
kubernetesClientset, err = kubernetes.NewForConfig(config) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
apiextensionsClientset, err = apiextensions.NewForConfig(config) | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
|
||
func TestStarboardCLI(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("Skipping integration test") | ||
} | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Starboard CLI") | ||
} | ||
|
||
var _ = AfterSuite(func() { | ||
gexec.CleanupBuildArtifacts() | ||
}) |
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,66 @@ | ||
package integration_tests | ||
|
||
import ( | ||
"context" | ||
"os/exec" | ||
|
||
apiextentions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" | ||
|
||
meta "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Starboard CLI", func() { | ||
|
||
BeforeEach(func() { | ||
// currently do nothing | ||
}) | ||
|
||
Describe("Running version command", func() { | ||
It("should print the current version of the executable binary", func() { | ||
cmd := exec.Command(pathToStarboardCLI, []string{"version"}...) | ||
output, err := cmd.Output() | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(string(output)).To(Equal("Starboard Version: {Version:dev Commit:none Date:unknown}\n")) | ||
}) | ||
|
||
}) | ||
|
||
Describe("Running init command", func() { | ||
It("should initialize Starboard", func() { | ||
cmd := exec.Command(pathToStarboardCLI, []string{"init", "-v", "3"}...) | ||
err := cmd.Run() | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
crdsList, err := apiextensionsClientset.CustomResourceDefinitions().List(context.TODO(), meta.ListOptions{}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
GetNames := func(crds []apiextentions.CustomResourceDefinition) []string { | ||
names := make([]string, len(crds)) | ||
for i, crd := range crds { | ||
names[i] = crd.Name | ||
} | ||
return names | ||
} | ||
|
||
Expect(crdsList.Items).To(WithTransform(GetNames, ContainElements( | ||
"ciskubebenchreports.aquasecurity.github.io", | ||
"configauditreports.aquasecurity.github.io", | ||
"kubehunterreports.aquasecurity.github.io", | ||
"vulnerabilities.aquasecurity.github.io", | ||
))) | ||
|
||
_, err = kubernetesClientset.CoreV1().Namespaces().Get(context.TODO(), "starboard", meta.GetOptions{}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
// TODO Assert other Kubernetes resources that we create in the init command | ||
}) | ||
}) | ||
|
||
AfterEach(func() { | ||
// currently do nothing | ||
}) | ||
|
||
}) |
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