From 14d894423be82c877af0f30b1b5ac7e355e02277 Mon Sep 17 00:00:00 2001 From: David Aronchick Date: Mon, 7 Feb 2022 17:32:19 -0800 Subject: [PATCH] adding tests, Make file and interfaces --- .gitignore | 6 +- Makefile | 138 +++++++++++++++++++++++++++ README.md | 12 ++- cmd/bacalhau/root.go | 12 +-- cmd/bacalhau/serve.go | 16 +++- experimental/.keep | 0 experimental/sample.go | 17 ++++ go.mod | 114 +++++++++++++++++++++- go.sum | 31 ++---- internal/jsonrpc_server.go | 33 ++----- pkg/mocks/mock_strings.go | 6 ++ pkg/networker/networker_interface.go | 29 ++++++ pkg/networker/networker_live.go | 59 ++++++++++++ pkg/networker/networker_mock.go | 40 ++++++++ pkg/utils/arrays.go | 53 ++++++++++ pkg/utils/testutils.go | 37 +++++++ test/README.md | 9 ++ test/integration/.keep | 0 test/integration/cmd_root_test.go | 51 ++++++++++ test/integration/cmd_serve_test.go | 60 ++++++++++++ test/testdata/.keep | 0 test/utils/.keep | 0 22 files changed, 650 insertions(+), 73 deletions(-) create mode 100644 Makefile create mode 100644 experimental/.keep create mode 100644 experimental/sample.go create mode 100644 pkg/mocks/mock_strings.go create mode 100644 pkg/networker/networker_interface.go create mode 100644 pkg/networker/networker_live.go create mode 100644 pkg/networker/networker_mock.go create mode 100644 pkg/utils/arrays.go create mode 100644 pkg/utils/testutils.go create mode 100644 test/README.md create mode 100644 test/integration/.keep create mode 100644 test/integration/cmd_root_test.go create mode 100644 test/integration/cmd_serve_test.go create mode 100644 test/testdata/.keep create mode 100644 test/utils/.keep diff --git a/.gitignore b/.gitignore index e6d35e74c9..4d2e4934bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ -outputs \ No newline at end of file +outputs + +bin + +.vscode diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..66a39526c8 --- /dev/null +++ b/Makefile @@ -0,0 +1,138 @@ +RUSTFLAGS="-C target-feature=+crt-static" + +# Detect OS +OS := $(shell uname | tr "[:upper:]" "[:lower:]") +ARCH := $(shell uname -m | tr "[:upper:]" "[:lower:]") +GOPATH ?= $(shell go env GOPATH) +GOFLAGS ?= $(GOFLAGS:) +GO=go +GO_MAJOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1) +GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2) +GO_OS = $(shell $(GO) version | cut -c 14- | cut -d' ' -f2 | cut -d'/' -f1 | tr "[:upper:]" "[:lower:]") +GO_ARCH = $(shell $(GO) version | cut -c 14- | cut -d' ' -f2 | cut -d'/' -f2 | tr "[:upper:]" "[:lower:]") + +define GO_MISMATCH_ERROR + +Your go binary does not match your architecture. + Go binary: $(GO_OS) - $(GO_ARCH) + Environment: $(OS) - $(ARCH) + GOPATH: $(GOPATH) + +endef +export GO_MISMATCH_ERROR + +all: go-arch-alignment build +.PHONY: all + +build: + go build +.PHONY: build + +go-arch-alignment: +mismatch = +ifeq ($(OS), darwin) +ifneq ($(ARCH), $(GO_ARCH)) +mismatch = yes +endif +endif + +ifdef mismatch +$(info $(GO_MISMATCH_ERROR)) +$(error Please change your go binary) +endif +.PHONY: go-arch-alignment + +all: build + +# Run go fmt against code +fmt: + @${GO} fmt ./cmd/... + + +# Run go vet against code +vet: + @${GO} vet ./cmd/... + +################################################################################ +# Target: modtidy # +################################################################################ +.PHONY: modtidy +modtidy: + go mod tidy + +################################################################################ +# Target: check-diff # +################################################################################ +.PHONY: check-diff +check-diff: + git diff --exit-code ./go.mod # check no changes + git diff --exit-code ./go.sum # check no changes + +## Run all pre-commit hooks +################################################################################ +# Target: precommit # +################################################################################ +.PHONY: precommit +precommit: + ${PRECOMMIT} run --all + +################################################################################ +# Target: build # +################################################################################ +.PHONY: build +build: build-bacalhau + + +################################################################################ +# Target: build-bacalhau # +################################################################################ +.PHONY: build-bacalhau +build-bacalhau: fmt vet + CGO_ENABLED=0 GOOS=$(shell go env GOOS) GOARCH=$(shell go env GOARCH) ${GO} build -gcflags '-N -l' -ldflags "-X main.VERSION=$(TAG)" -o bin/$(ARCH)/bacalhau main.go + cp bin/$(ARCH)/bacalhau bin/bacalhau + + +################################################################################ +# Target: clean # +################################################################################ +.PHONY: clean +clean: + go clean + + +################################################################################ +# Target: test # +################################################################################ +.PHONY: test +test: build-bacalhau + go test ./test/... -v + +################################################################################ +# Target: lint # +################################################################################ +.PHONY: lint +lint: build-bacalhau + golangci-lint run --timeout 10m + +# Run the unittests and output a junit report for use with prow +################################################################################ +# Target: test-junit # +################################################################################ +.PHONY: test-junit +test-junit: build-bacalhau + echo Running tests ... junit_file=$(JUNIT_FILE) + go test ./... -v 2>&1 | go-junit-report > $(JUNIT_FILE) --set-exit-code + +.PHONY: generate +generate: + CGO_ENABLED=0 GOARCH=$(shell go env GOARCH) ${GO} generate -gcflags '-N -l' -ldflags "-X main.VERSION=$(TAG)" ./... + echo "[OK] Files added to pipeline template directory!" + +.PHONY: security +security: + gosec -exclude=G204,G304 -exclude-dir=test ./... + echo "[OK] Go security check was completed!" + +release: + echo "Executing 'make release'" + # NOOP diff --git a/README.md b/README.md index 5b3a50cf2d..122ecfeb1d 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,21 @@ # Bacalhau - The Filecoin Distributed Computation Framework -## demo! +## demo -https://user-images.githubusercontent.com/264658/152514573-b7b115ce-4123-486c-983a-8e26acf4b86d.mp4 + ## running locally ### requirements - * linux - * go >= 1.16 - * [ignite](https://ignite.readthedocs.io/en/stable/installation/) +* linux +* go >= 1.16 () +* [ignite](https://ignite.readthedocs.io/en/stable/installation/) ### start compute nodes +The first + Have a few terminal windows. This starts the first compute node listening on port 8080 so we can connect to a known port. diff --git a/cmd/bacalhau/root.go b/cmd/bacalhau/root.go index 094716dc10..e310ac90c1 100644 --- a/cmd/bacalhau/root.go +++ b/cmd/bacalhau/root.go @@ -11,26 +11,26 @@ var jsonrpcPort int var developmentMode bool func init() { - rootCmd.AddCommand(serveCmd) - rootCmd.AddCommand(submitCmd) - rootCmd.PersistentFlags().IntVar( + RootCmd.AddCommand(ServeCmd) + RootCmd.AddCommand(submitCmd) + RootCmd.PersistentFlags().IntVar( &jsonrpcPort, "jsonrpc-port", 1234, `The port for the client and server to communicate on over localhost (via jsonrpc).`, ) - rootCmd.PersistentFlags().BoolVar( + RootCmd.PersistentFlags().BoolVar( &developmentMode, "dev", false, `Development mode makes it easier to run multiple bacalhau nodes on the same machine.`, ) } -var rootCmd = &cobra.Command{ +var RootCmd = &cobra.Command{ Use: "bacalhau", Short: "Compute over data", Long: `Compute over data`, } func Execute() { - if err := rootCmd.Execute(); err != nil { + if err := RootCmd.Execute(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } diff --git a/cmd/bacalhau/serve.go b/cmd/bacalhau/serve.go index c9378b8a00..80a578fdd3 100644 --- a/cmd/bacalhau/serve.go +++ b/cmd/bacalhau/serve.go @@ -6,6 +6,7 @@ import ( "log" "github.com/filecoin-project/bacalhau/internal" + "github.com/filecoin-project/bacalhau/pkg/networker" "github.com/phayes/freeport" "github.com/spf13/cobra" ) @@ -15,21 +16,21 @@ var hostAddress string var hostPort int func init() { - serveCmd.PersistentFlags().StringVar( + ServeCmd.PersistentFlags().StringVar( &peerConnect, "peer", "", `The libp2p multiaddress to connect to.`, ) - serveCmd.PersistentFlags().StringVar( + ServeCmd.PersistentFlags().StringVar( &hostAddress, "host", "127.0.0.1", `The port to listen on.`, ) - serveCmd.PersistentFlags().IntVar( + ServeCmd.PersistentFlags().IntVar( &hostPort, "port", 0, `The port to listen on.`, ) } -var serveCmd = &cobra.Command{ +var ServeCmd = &cobra.Command{ Use: "serve", Short: "Start the bacalhau compute node", RunE: func(cmd *cobra.Command, args []string) error { @@ -63,10 +64,15 @@ Command to connect other peers: go run . serve --peer /ip4/%s/tcp/%d/p2p/%s%s%s `, hostAddress, hostPort, computeNode.Host.ID(), jsonRpcString, devString) + i := networker.GetNetworker(cmd, args) // run the jsonrpc server, passing it a reference to the pubsub topic so // that the CLI can also send messages to the chat room - internal.RunBacalhauRpcServer(hostAddress, jsonrpcPort, computeNode) + err = i.RunBacalhauRpcServer(hostAddress, jsonrpcPort, computeNode) + + if err != nil { + return err + } return nil diff --git a/experimental/.keep b/experimental/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/experimental/sample.go b/experimental/sample.go new file mode 100644 index 0000000000..d6c3b59a7b --- /dev/null +++ b/experimental/sample.go @@ -0,0 +1,17 @@ +// THIS FILE IS NOT FOR PRODUCTION USE OR INCLUSION IN ANY PACKAGE +// It is a convient place to add libraries from the rest of the + +package bacalhau + +import ( + "crypto/rand" + "fmt" + "math/big" +) + + +func bacalhau() { + // ... + r, _ := rand.Int(rand.Reader, big.NewInt(10)) + fmt.Printf("Test: %v", r) +} diff --git a/go.mod b/go.mod index d44e9a1c40..dd5a5940ad 100644 --- a/go.mod +++ b/go.mod @@ -1,15 +1,121 @@ module github.com/filecoin-project/bacalhau -go 1.16 +go 1.17 require ( - github.com/gdamore/tcell/v2 v2.1.0 - github.com/google/uuid v1.3.0 // indirect + github.com/google/uuid v1.3.0 github.com/libp2p/go-libp2p v0.17.0 github.com/libp2p/go-libp2p-core v0.13.0 github.com/libp2p/go-libp2p-pubsub v0.6.0 github.com/multiformats/go-multiaddr v0.4.0 github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 - github.com/rivo/tview v0.0.0-20210125085121-dbc1f32bb1d0 github.com/spf13/cobra v0.0.5 + github.com/stretchr/testify v1.7.0 + go.uber.org/zap v1.21.0 +) + +require ( + github.com/beorn7/perks v1.0.1 // indirect + github.com/btcsuite/btcd v0.22.0-beta // indirect + github.com/cespare/xxhash/v2 v2.1.1 // indirect + github.com/cheekybits/genny v1.0.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect + github.com/flynn/noise v1.0.0 // indirect + github.com/francoispqt/gojay v1.2.13 // indirect + github.com/fsnotify/fsnotify v1.4.9 // indirect + github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/google/gopacket v1.1.19 // indirect + github.com/gorilla/websocket v1.4.2 // indirect + github.com/hashicorp/golang-lru v0.5.4 // indirect + github.com/huin/goupnp v1.0.2 // indirect + github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/ipfs/go-cid v0.0.7 // indirect + github.com/ipfs/go-ipfs-util v0.0.2 // indirect + github.com/ipfs/go-log v1.0.5 // indirect + github.com/ipfs/go-log/v2 v2.4.0 // indirect + github.com/jackpal/go-nat-pmp v1.0.2 // indirect + github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect + github.com/klauspost/compress v1.11.7 // indirect + github.com/klauspost/cpuid/v2 v2.0.9 // indirect + github.com/koron/go-ssdp v0.0.2 // indirect + github.com/libp2p/go-addr-util v0.1.0 // indirect + github.com/libp2p/go-buffer-pool v0.0.2 // indirect + github.com/libp2p/go-cidranger v1.1.0 // indirect + github.com/libp2p/go-conn-security-multistream v0.3.0 // indirect + github.com/libp2p/go-eventbus v0.2.1 // indirect + github.com/libp2p/go-flow-metrics v0.0.3 // indirect + github.com/libp2p/go-libp2p-asn-util v0.1.0 // indirect + github.com/libp2p/go-libp2p-autonat v0.7.0 // indirect + github.com/libp2p/go-libp2p-blankhost v0.3.0 // indirect + github.com/libp2p/go-libp2p-discovery v0.6.0 // indirect + github.com/libp2p/go-libp2p-mplex v0.4.1 // indirect + github.com/libp2p/go-libp2p-nat v0.1.0 // indirect + github.com/libp2p/go-libp2p-noise v0.3.0 // indirect + github.com/libp2p/go-libp2p-peerstore v0.6.0 // indirect + github.com/libp2p/go-libp2p-pnet v0.2.0 // indirect + github.com/libp2p/go-libp2p-quic-transport v0.15.2 // indirect + github.com/libp2p/go-libp2p-swarm v0.9.0 // indirect + github.com/libp2p/go-libp2p-tls v0.3.1 // indirect + github.com/libp2p/go-libp2p-transport-upgrader v0.6.0 // indirect + github.com/libp2p/go-libp2p-yamux v0.7.0 // indirect + github.com/libp2p/go-maddr-filter v0.1.0 // indirect + github.com/libp2p/go-mplex v0.3.0 // indirect + github.com/libp2p/go-msgio v0.1.0 // indirect + github.com/libp2p/go-nat v0.1.0 // indirect + github.com/libp2p/go-netroute v0.1.6 // indirect + github.com/libp2p/go-openssl v0.0.7 // indirect + github.com/libp2p/go-reuseport v0.1.0 // indirect + github.com/libp2p/go-reuseport-transport v0.1.0 // indirect + github.com/libp2p/go-sockaddr v0.1.1 // indirect + github.com/libp2p/go-stream-muxer-multistream v0.3.0 // indirect + github.com/libp2p/go-tcp-transport v0.4.0 // indirect + github.com/libp2p/go-ws-transport v0.5.0 // indirect + github.com/libp2p/go-yamux/v2 v2.3.0 // indirect + github.com/lucas-clemente/quic-go v0.24.0 // indirect + github.com/marten-seemann/qtls-go1-16 v0.1.4 // indirect + github.com/marten-seemann/qtls-go1-17 v0.1.0 // indirect + github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect + github.com/miekg/dns v1.1.43 // indirect + github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect + github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect + github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect + github.com/minio/sha256-simd v1.0.0 // indirect + github.com/mr-tron/base58 v1.2.0 // indirect + github.com/multiformats/go-base32 v0.0.3 // indirect + github.com/multiformats/go-base36 v0.1.0 // indirect + github.com/multiformats/go-multiaddr-dns v0.3.1 // indirect + github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect + github.com/multiformats/go-multibase v0.0.3 // indirect + github.com/multiformats/go-multihash v0.0.15 // indirect + github.com/multiformats/go-multistream v0.2.2 // indirect + github.com/multiformats/go-varint v0.0.6 // indirect + github.com/nxadm/tail v1.4.8 // indirect + github.com/onsi/ginkgo v1.16.4 // indirect + github.com/opentracing/opentracing-go v1.2.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/prometheus/client_golang v1.11.0 // indirect + github.com/prometheus/client_model v0.2.0 // indirect + github.com/prometheus/common v0.30.0 // indirect + github.com/prometheus/procfs v0.7.3 // indirect + github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect + github.com/spf13/pflag v1.0.3 // indirect + github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 // indirect + github.com/whyrusleeping/timecache v0.0.0-20160911033111-cfcb2f1abfee // indirect + go.uber.org/atomic v1.9.0 // indirect + go.uber.org/multierr v1.7.0 // indirect + golang.org/x/crypto v0.0.0-20210813211128-0a44fdfbc16e // indirect + golang.org/x/mod v0.4.2 // indirect + golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d // indirect + golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect + golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 // indirect + golang.org/x/tools v0.1.5 // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect + google.golang.org/protobuf v1.27.1 // indirect + gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/go.sum b/go.sum index 61cb982673..643707e10b 100644 --- a/go.sum +++ b/go.sum @@ -162,13 +162,6 @@ github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2 github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= -github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= -github.com/gdamore/tcell v1.4.0 h1:vUnHwJRvcPQa3tzi+0QI4U9JINXYJlOz9yiaiPQ2wMU= -github.com/gdamore/tcell v1.4.0/go.mod h1:vxEiSDZdW3L+Uhjii9c3375IlDmR05bzxY404ZVSMo0= -github.com/gdamore/tcell/v2 v2.0.1-0.20201017141208-acf90d56d591/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA= -github.com/gdamore/tcell/v2 v2.1.0 h1:UnSmozHgBkQi2PGsFr+rpdXuAPRRucMegpQp3Z3kDro= -github.com/gdamore/tcell/v2 v2.1.0/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= @@ -541,15 +534,12 @@ github.com/libp2p/go-yamux v1.4.1 h1:P1Fe9vF4th5JOxxgQvfbOHkrGqIZniTLf+ddhZp8YTI github.com/libp2p/go-yamux v1.4.1/go.mod h1:fr7aVgmdNGJK+N1g+b6DW6VxzbRCjCOejR/hkmpooHE= github.com/libp2p/go-yamux/v2 v2.3.0 h1:luRV68GS1vqqr6EFUjtu1kr51d+IbW0gSowu8emYWAI= github.com/libp2p/go-yamux/v2 v2.3.0/go.mod h1:iTU+lOIn/2h0AgKcL49clNTwfEw+WSfDYrXe05EyKIs= -github.com/libp2p/zeroconf/v2 v2.1.1 h1:XAuSczA96MYkVwH+LqqqCUZb2yH3krobMJ1YE+0hG2s= github.com/libp2p/zeroconf/v2 v2.1.1/go.mod h1:fuJqLnUwZTshS3U/bMRJ3+ow/v9oid1n0DmyYyNO1Xs= github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= github.com/lucas-clemente/quic-go v0.23.0/go.mod h1:paZuzjXCE5mj6sikVLMvqXk8lJV2AsqtJ6bDhjEfxx0= github.com/lucas-clemente/quic-go v0.24.0 h1:ToR7SIIEdrgOhgVTHvPgdVRJfgVy+N0wQAagH7L4d5g= github.com/lucas-clemente/quic-go v0.24.0/go.mod h1:paZuzjXCE5mj6sikVLMvqXk8lJV2AsqtJ6bDhjEfxx0= -github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac= -github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= @@ -572,9 +562,6 @@ github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg= -github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= @@ -760,11 +747,6 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1 github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= -github.com/rivo/tview v0.0.0-20210125085121-dbc1f32bb1d0 h1:WCfp+Jq9Mx156zIf9X6Frd6F19rf7wIRlm54UPxUfcU= -github.com/rivo/tview v0.0.0-20210125085121-dbc1f32bb1d0/go.mod h1:1QW7hX7RQzOqyGgx8O64bRPQBrFtPflioPPX5gFPV3A= -github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= -github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= @@ -877,8 +859,9 @@ go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.0.0/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= -go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= +go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= +go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= @@ -891,8 +874,9 @@ go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= go.uber.org/zap v1.14.1/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ= -go.uber.org/zap v1.19.0 h1:mZQZefskPPCMIBCSEH0v2/iUqqLrYtaeqwD6FUGUnFE= go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= +go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8= +go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE= golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d/go.mod h1:OWs+y06UdEOHN4y+MfF/py+xQ/tYqIWW03b70/CG9Rw= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -943,7 +927,6 @@ golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= @@ -1051,7 +1034,6 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1087,7 +1069,6 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210113181707-4bcb84eeeb78/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1110,7 +1091,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= @@ -1171,8 +1151,9 @@ golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA= +golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/internal/jsonrpc_server.go b/internal/jsonrpc_server.go index 762076de27..395032771c 100644 --- a/internal/jsonrpc_server.go +++ b/internal/jsonrpc_server.go @@ -1,12 +1,6 @@ package internal import ( - "fmt" - "log" - "net" - "net/http" - "net/rpc" - "github.com/filecoin-project/bacalhau/internal/types" ) @@ -18,28 +12,13 @@ type SubmitArgs struct { Job *types.Job } -func (server *JobServer) Submit(args *SubmitArgs, reply *types.Job) error { - server.ComputeNode.Publish(args.Job) - *reply = *args.Job - return nil -} -func RunBacalhauRpcServer(host string, port int, computeNode *ComputeNode) { - job := &JobServer{ - ComputeNode: computeNode, - } - err := rpc.Register(job) - if err != nil { - log.Fatalf("Format of service Job isn't correct. %s", err) - } - rpc.HandleHTTP() - l, e := net.Listen("tcp", fmt.Sprintf("%s:%d", host, port)) - if e != nil { - log.Fatalf("Couldn't start listening on port %d. Error %s", port, e) - } - log.Println("Serving RPC handler") - err = http.Serve(l, nil) +func (server *JobServer) Submit(args *SubmitArgs, reply *types.Job) error { + err := server.ComputeNode.Publish(args.Job) + if err != nil { - log.Fatalf("Error serving: %s", err) + return err } + *reply = *args.Job + return nil } diff --git a/pkg/mocks/mock_strings.go b/pkg/mocks/mock_strings.go new file mode 100644 index 0000000000..8515af8366 --- /dev/null +++ b/pkg/mocks/mock_strings.go @@ -0,0 +1,6 @@ +package mocks + +var ( + CALL_RUN_BACALHAU_RPC_SERVER_SUCCESSFUL_PROBE string = "call-run-bacalhau-rpc-server-successful" + CALL_RUN_BACALHAU_RPC_SERVER_SUCCESSFUL_RESULT string = "CALL RUN BACALHAU RPC SERVER SUCCESSFUL" +) \ No newline at end of file diff --git a/pkg/networker/networker_interface.go b/pkg/networker/networker_interface.go new file mode 100644 index 0000000000..3188f0bc0f --- /dev/null +++ b/pkg/networker/networker_interface.go @@ -0,0 +1,29 @@ +package networker + +import ( + "os" + + "github.com/filecoin-project/bacalhau/internal" + "github.com/spf13/cobra" +) + +type NetworkerInterface interface { + // Run a bacalhau server + RunBacalhauRpcServer(string, int, *internal.ComputeNode) error + + // Instantiation getter/setters + GetCmd() *cobra.Command + SetCmd(*cobra.Command) + GetCmdArgs() []string + SetCmdArgs([]string) +} + +func GetNetworker(cmd *cobra.Command, args []string) NetworkerInterface { + var n NetworkerInterface = &NetworkerLive{} + if os.Getenv("TEST_PASS") != "" { + n = &NetworkerMock{} + } + n.SetCmd(cmd) + n.SetCmdArgs(args) + return n +} \ No newline at end of file diff --git a/pkg/networker/networker_live.go b/pkg/networker/networker_live.go new file mode 100644 index 0000000000..90bcc180f8 --- /dev/null +++ b/pkg/networker/networker_live.go @@ -0,0 +1,59 @@ +package networker + +import ( + "fmt" + "log" + "net" + "net/http" + "net/rpc" + + "github.com/filecoin-project/bacalhau/internal" + "github.com/spf13/cobra" +) + +type NetworkerLive struct { + _cmd *cobra.Command + _cmdArgs []string +} + + +func (i *NetworkerLive) RunBacalhauRpcServer(host string, port int, computeNode *internal.ComputeNode) error { + job := &internal.JobServer{ + ComputeNode: computeNode, + } + err := rpc.Register(job) + if err != nil { + log.Fatalf("Format of service Job isn't correct. %s", err) + } + rpc.HandleHTTP() + l, err := net.Listen("tcp", fmt.Sprintf("%s:%d", host, port)) + if err != nil { + log.Fatalf("Couldn't start listening on port %d. Error %s", port, err) + return err + } + log.Println("Serving RPC handler") + err = http.Serve(l, nil) + if err != nil { + log.Fatalf("Error serving: %s", err) + return err + } + return nil +} + + +func (n *NetworkerLive) GetCmd() *cobra.Command { + return n._cmd +} + +func (n *NetworkerLive) SetCmd(cmd *cobra.Command) { + n._cmd = cmd +} + +func (n *NetworkerLive) GetCmdArgs() []string { + return n._cmdArgs +} + +func (n *NetworkerLive) SetCmdArgs(args []string) { + n._cmdArgs = args +} + diff --git a/pkg/networker/networker_mock.go b/pkg/networker/networker_mock.go new file mode 100644 index 0000000000..681107fbd2 --- /dev/null +++ b/pkg/networker/networker_mock.go @@ -0,0 +1,40 @@ +package networker + +import ( + "fmt" + + "github.com/filecoin-project/bacalhau/internal" + "github.com/filecoin-project/bacalhau/pkg/mocks" + "github.com/filecoin-project/bacalhau/pkg/utils" + "github.com/spf13/cobra" +) + +type NetworkerMock struct { + _cmd *cobra.Command + _cmdArgs []string +} + +func (i *NetworkerMock) RunBacalhauRpcServer(host string, port int, computeNode *internal.ComputeNode) error { + if utils.ContainsString(i.GetCmdArgs(), mocks.CALL_RUN_BACALHAU_RPC_SERVER_SUCCESSFUL_PROBE) { + return nil + } + + return fmt.Errorf("Was not able to successfully call pipeline") +} + + +func (n *NetworkerMock) GetCmd() *cobra.Command { + return n._cmd +} + +func (n *NetworkerMock) SetCmd(cmd *cobra.Command) { + n._cmd = cmd +} + +func (n *NetworkerMock) GetCmdArgs() []string { + return n._cmdArgs +} + +func (n *NetworkerMock) SetCmdArgs(args []string) { + n._cmdArgs = args +} \ No newline at end of file diff --git a/pkg/utils/arrays.go b/pkg/utils/arrays.go new file mode 100644 index 0000000000..d01c53cbe8 --- /dev/null +++ b/pkg/utils/arrays.go @@ -0,0 +1,53 @@ +package utils + +import ( + "fmt" + "strings" +) + +func ContainsString(s []string, e string) bool { + for _, a := range s { + if a == e { + return true + } + } + return false +} + +func ContainsInt(s []int, e int) bool { + for _, a := range s { + if a == e { + return true + } + } + return false +} + +func JoinMapKeysValues(s map[string]string) (string, error) { + values := make([]string, 0, len(s)) + for k, v := range s { + values = append(values, fmt.Sprintf("%v='%v'", k, v)) + } + return strings.Join(values, ", "), nil +} + +func AppendIfMissing(slice []string, s string) []string { + if ContainsString(slice, s) { + return slice + } + return append(slice, s) +} + +func RemoveIndex(s []int, index int) []int { + ret := make([]int, 0) + ret = append(ret, s[:index]...) + return append(ret, s[index+1:]...) +} + +func ValueOrDefault(s string, d string) string { + if s != "" { + return s + } else { + return d + } +} \ No newline at end of file diff --git a/pkg/utils/testutils.go b/pkg/utils/testutils.go new file mode 100644 index 0000000000..daddf6ea97 --- /dev/null +++ b/pkg/utils/testutils.go @@ -0,0 +1,37 @@ +package utils + +import ( + "bytes" + "fmt" + + "github.com/spf13/cobra" + "go.uber.org/zap" + log "go.uber.org/zap" + "go.uber.org/zap/zaptest/observer" +) +func ExecuteCommandC(cmd *cobra.Command, logger *log.Logger, args ...string) (c *cobra.Command, output string, err error) { + buf := new(bytes.Buffer) + + root := cmd.Root() + root.SetOut(buf) + root.SetErr(buf) + root.SetArgs(args) + + // // Need to check if we're running in debug mode for VSCode + // // Empty them if they exist + // if (len(os.Args) > 2) && (os.Args[1] == "-test.run") { + // os.Args[1] = "" + // os.Args[2] = "" + // } + + logger.Debug(fmt.Sprintf("Command to execute: bacalhau %v", root.CalledAs())) + + c, err = root.ExecuteC() + return c, buf.String(), err +} + + +func SetupLogsCapture() (*zap.Logger, *observer.ObservedLogs) { + core, logs := observer.New(zap.InfoLevel) + return zap.New(core), logs +} diff --git a/test/README.md b/test/README.md new file mode 100644 index 0000000000..cdcf65f468 --- /dev/null +++ b/test/README.md @@ -0,0 +1,9 @@ +# `/test` + +Additional external test apps and test data. Feel free to structure the `/test` directory anyway you want. For bigger projects it makes sense to have a data subdirectory. For example, you can have `/test/data` or `/test/testdata` if you need Go to ignore what's in that directory. Note that Go will also ignore directories or files that begin with "." or "_", so you have more flexibility in terms of how you name your test data directory. + +Examples: + +* https://github.com/openshift/origin/tree/master/test (test data is in the `/testdata` subdirectory) + + diff --git a/test/integration/.keep b/test/integration/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/integration/cmd_root_test.go b/test/integration/cmd_root_test.go new file mode 100644 index 0000000000..d962e35bd2 --- /dev/null +++ b/test/integration/cmd_root_test.go @@ -0,0 +1,51 @@ +package integration_test + +import ( + "testing" + + cmd "github.com/filecoin-project/bacalhau/cmd/bacalhau" + "github.com/filecoin-project/bacalhau/pkg/utils" + "github.com/spf13/cobra" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" +) + +// Define the suite, and absorb the built-in basic suite +// functionality from testify - including a T() method which +// returns the current testing context +type RootSuite struct { + suite.Suite + rootCmd *cobra.Command +} + +// before each test +func (suite *RootSuite) SetupTest() { + suite.rootCmd = cmd.RootCmd +} + +func (suite *RootSuite) Test_DefaultRun() { + logger, _ := utils.SetupLogsCapture() + + // logger.Warn("This is the warning") + + // if logs.Len() != 1 { + // suite.T().Errorf("No logs") + // } else { + // entry := logs.All()[0] + // if entry.Level != zap.WarnLevel || entry.Message != "This is the warning" { + // suite.T().Errorf("Invalid log entry %v", entry) + // } + // } + command, out, err := utils.ExecuteCommandC(suite.rootCmd, logger, "") + + // Putting empty assignments here for debugging in the future + _ = command + _ = err + + assert.Contains(suite.T(), string(out), "bacalhau [command] --help") +} + +func TestRootSuite(t *testing.T) { + suite.Run(t, new(RootSuite)) +} \ No newline at end of file diff --git a/test/integration/cmd_serve_test.go b/test/integration/cmd_serve_test.go new file mode 100644 index 0000000000..75dc6be570 --- /dev/null +++ b/test/integration/cmd_serve_test.go @@ -0,0 +1,60 @@ +package integration_test + +import ( + "fmt" + "os" + "testing" + + cmd "github.com/filecoin-project/bacalhau/cmd/bacalhau" + "github.com/filecoin-project/bacalhau/pkg/mocks" + "github.com/filecoin-project/bacalhau/pkg/utils" + "github.com/spf13/cobra" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" +) + +// Define the suite, and absorb the built-in basic suite +// functionality from testify - including a T() method which +// returns the current testing context +type ServeSuite struct { + suite.Suite + serveCmd *cobra.Command +} + +func (suite *ServeSuite) SetupAllSuite() { + +} + +// before each test +func (suite *ServeSuite) SetupTest() { + os.Setenv("TEST_PASS", "1") + suite.serveCmd = cmd.ServeCmd +} + +func (suite *ServeSuite) Test_DefaultServe() { + logger, _ := utils.SetupLogsCapture() + + // logger.Warn("This is the warning") + + // if logs.Len() != 1 { + // suite.T().Errorf("No logs") + // } else { + // entry := logs.All()[0] + // if entry.Level != zap.WarnLevel || entry.Message != "This is the warning" { + // suite.T().Errorf("Invalid log entry %v", entry) + // } + // } + command, out, err := utils.ExecuteCommandC(suite.serveCmd, logger, "serve", "--", mocks.CALL_RUN_BACALHAU_RPC_SERVER_SUCCESSFUL_PROBE) + + // Putting empty assignments here for debugging in the future + _ = command + _ = err + _ = out + + assert.NoError(suite.T(), err, fmt.Sprintf("Error found (non expected): %v", err)) +} + +func TestServeSuite(t *testing.T) { + suite.Run(t, new(ServeSuite)) +} \ No newline at end of file diff --git a/test/testdata/.keep b/test/testdata/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/utils/.keep b/test/utils/.keep new file mode 100644 index 0000000000..e69de29bb2