Skip to content

Commit

Permalink
new(tests): added new tests
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Scolaro <[email protected]>
  • Loading branch information
therealbobo committed Jun 1, 2023
1 parent 63b6bf3 commit 3554a49
Show file tree
Hide file tree
Showing 16 changed files with 1,889 additions and 46 deletions.
84 changes: 84 additions & 0 deletions cmd/artifact/install/install_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package install_test

import (
"context"
"fmt"
"os"
"path/filepath"
"testing"

"github.com/distribution/distribution/v3/configuration"
_ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/spf13/cobra"
"oras.land/oras-go/v2/registry/remote"

"github.com/falcosecurity/falcoctl/cmd"
commonoptions "github.com/falcosecurity/falcoctl/pkg/options"
testutils "github.com/falcosecurity/falcoctl/pkg/test"
)

const (
rulesfiletgz = "../../../pkg/test/data/rules.tar.gz"
rulesfileyaml = "../../../pkg/test/data/rules.yaml"
plugintgz = "../../../pkg/test/data/plugin.tar.gz"
)

var (
registry string
ctx = context.Background()
output = gbytes.NewBuffer()
rootCmd *cobra.Command
opt *commonoptions.CommonOptions
port int
orasRegistry *remote.Registry
configFile string
err error
args []string
)

func TestInstall(t *testing.T) {
var err error
RegisterFailHandler(Fail)
port, err = testutils.FreePort()
Expect(err).ToNot(HaveOccurred())
registry = fmt.Sprintf("localhost:%d", port)
RunSpecs(t, "root suite")
}

var _ = BeforeSuite(func() {
config := &configuration.Configuration{}
config.HTTP.Addr = fmt.Sprintf("localhost:%d", port)
// Create and configure the common options.
opt = commonoptions.NewOptions()
opt.Initialize(commonoptions.WithWriter(output))
opt.Printer.DisableStylingf()

// Create the oras registry.
orasRegistry, err = testutils.NewOrasRegistry(registry, true)
Expect(err).ToNot(HaveOccurred())

// Start the local registry.
go func() {
err := testutils.StartRegistry(context.Background(), config)
Expect(err).ToNot(BeNil())
}()

// Create temporary directory used to save the configuration file.
configFile, err = testutils.CreateEmptyFile("falcoctl.yaml")
Expect(err).Should(Succeed())

})

var _ = AfterSuite(func() {
configDir := filepath.Dir(configFile)
Expect(os.RemoveAll(configDir)).Should(Succeed())
})

func executeRoot(args []string) error {
rootCmd.SetArgs(args)
rootCmd.SetOut(output)
return cmd.Execute(rootCmd, opt.Printer)
}
Loading

0 comments on commit 3554a49

Please sign in to comment.