From 193ff50cac05f4007a9ef5870492aab13a42042b Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Tue, 12 Sep 2023 15:25:21 -0700 Subject: [PATCH] Fix tests --- Makefile | 42 ++++++++++++++-------- flowkit/state_test.go | 17 ++++----- internal/super/files_test.go | 18 +++++----- internal/transactions/transactions_test.go | 10 ++++-- 4 files changed, 53 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index bd131835f..15f3378f1 100644 --- a/Makefile +++ b/Makefile @@ -8,11 +8,22 @@ VERSION := $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null) COVER_PROFILE := coverage.txt # Disable go sum database lookup for private repos GOPRIVATE := github.com/dapperlabs/* + # Ensure go bin path is in path (Especially for CI) -GOPATH ?= $(HOME)/go -PATH := $(PATH):$(GOPATH)/bin -# OS -UNAME := $(shell uname) +ifeq ($(OS),Windows_NT) + GOPATH ?= $(USERPROFILE)\go + PATH := $(PATH);$(GOPATH)\bin +else + GOPATH ?= $(HOME)/go + PATH := $(PATH):$(GOPATH)/bin +endif + +# Set MKDIR variable based on OS +ifeq ($(OS),Windows_NT) + MKDIR := mkdir +else + MKDIR := mkdir -p +endif MIXPANEL_PROJECT_TOKEN := 3fae49de272be1ceb8cf34119f747073 ACCOUNT_TOKEN := lilico:sF60s3wughJBmNh2 @@ -24,17 +35,20 @@ binary: $(BINARY) .PHONY: install-tools install-tools: - cd ${GOPATH}; \ - mkdir -p ${GOPATH}; \ - GO111MODULE=on go install github.com/axw/gocov/gocov@latest; \ - GO111MODULE=on go install github.com/matm/gocov-html@latest; \ - GO111MODULE=on go install github.com/sanderhahn/gozip/cmd/gozip@latest; \ - GO111MODULE=on go install github.com/vektra/mockery/v2@latest; + $(MKDIR) ${GOPATH} && \ + go env -w GO111MODULE=on && \ + go install github.com/axw/gocov/gocov@latest && \ + go install github.com/matm/gocov-html@latest && \ + go install github.com/sanderhahn/gozip/cmd/gozip@latest && \ + go install github.com/vektra/mockery/v2@latest; .PHONY: test test: - GO111MODULE=on go test -coverprofile=$(COVER_PROFILE) $(if $(JSON_OUTPUT),-json,) ./... - cd flowkit; GO111MODULE=on go test -coverprofile=$(COVER_PROFILE) $(if $(JSON_OUTPUT),-json,) ./... + go env -w GO111MODULE=on && \ + go env -w CGO_ENABLED=0 && \ + go test -coverprofile=$(COVER_PROFILE) $(if $(JSON_OUTPUT),-json,) ./... && \ + cd flowkit && \ + go test -coverprofile=$(COVER_PROFILE) $(if $(JSON_OUTPUT),-json,) ./... .PHONY: test-e2e-emulator test-e2e-emulator: @@ -104,7 +118,7 @@ check-schema: .PHONY: check-tidy check-tidy: go mod tidy - cd flowkit; go mod tidy + cd flowkit && go mod tidy .PHONY: generate-schema generate-schema: @@ -112,5 +126,5 @@ generate-schema: .PHONY: generate generate: install-tools - cd flowkit; \ + cd flowkit && \ go generate ./... \ No newline at end of file diff --git a/flowkit/state_test.go b/flowkit/state_test.go index a7b2a9b6c..e8d73e6d3 100644 --- a/flowkit/state_test.go +++ b/flowkit/state_test.go @@ -21,6 +21,7 @@ package flowkit import ( "fmt" "os" + "path/filepath" "sort" "testing" @@ -343,7 +344,7 @@ func generateAliasesComplexProject() State { func Test_GetContractsByNameSimple(t *testing.T) { p := generateSimpleProject() - path := "../hungry-kitties/cadence/contracts/NonFungibleToken.cdc" + path := filepath.FromSlash("../hungry-kitties/cadence/contracts/NonFungibleToken.cdc") af.WriteFile(path, []byte("pub contract{}"), os.ModePerm) contracts, err := p.DeploymentContractsByNetwork(config.EmulatorNetwork) @@ -423,13 +424,13 @@ func Test_GetContractsByNameComplex(t *testing.T) { assert.Equal(t, contractNames[5], "KittyItemsMarket") assert.Equal(t, contractNames[6], "NonFungibleToken") - assert.Equal(t, sources[0], "../hungry-kitties/cadence/contracts/FungibleToken.cdc") - assert.Equal(t, sources[1], "../hungry-kitties/cadence/contracts/NonFungibleToken.cdc") - assert.Equal(t, sources[2], "cadence/kibble/contracts/Kibble.cdc") - assert.Equal(t, sources[3], "cadence/kittyItems/contracts/KittyItems.cdc") - assert.Equal(t, sources[4], "cadence/kittyItems/contracts/KittyItems.cdc") - assert.Equal(t, sources[5], "cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc") - assert.Equal(t, sources[6], "cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc") + assert.Equal(t, sources[0], filepath.FromSlash("../hungry-kitties/cadence/contracts/FungibleToken.cdc")) + assert.Equal(t, sources[1], filepath.FromSlash("../hungry-kitties/cadence/contracts/NonFungibleToken.cdc")) + assert.Equal(t, sources[2], filepath.FromSlash("cadence/kibble/contracts/Kibble.cdc")) + assert.Equal(t, sources[3], filepath.FromSlash("cadence/kittyItems/contracts/KittyItems.cdc")) + assert.Equal(t, sources[4], filepath.FromSlash("cadence/kittyItems/contracts/KittyItems.cdc")) + assert.Equal(t, sources[5], filepath.FromSlash("cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc")) + assert.Equal(t, sources[6], filepath.FromSlash("cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc")) assert.Equal(t, targets[0], "f8d6e0586b0a20c1") assert.Equal(t, targets[1], "f8d6e0586b0a20c1") diff --git a/internal/super/files_test.go b/internal/super/files_test.go index 879ad9fb5..85993f026 100644 --- a/internal/super/files_test.go +++ b/internal/super/files_test.go @@ -28,11 +28,11 @@ import ( func Test_AccountFromPath(t *testing.T) { paths := [][]string{ // first is path, second is account name - {"cadence/contracts/alice/foo.cdc", "alice"}, - {"cadence/contracts/alice", "alice"}, - {"cadence/contracts/alice/boo/foo.cdc", ""}, - {"cadence/contracts/foo.cdc", ""}, - {"cadence/contracts/foo/bar/goo/foo", ""}, + {filepath.FromSlash("cadence/contracts/alice/foo.cdc"), "alice"}, + {filepath.FromSlash("cadence/contracts/alice"), "alice"}, + {filepath.FromSlash("cadence/contracts/alice/boo/foo.cdc"), ""}, + {filepath.FromSlash("cadence/contracts/foo.cdc"), ""}, + {filepath.FromSlash("cadence/contracts/foo/bar/goo/foo"), ""}, } for i, test := range paths { @@ -45,10 +45,10 @@ func Test_AccountFromPath(t *testing.T) { func Test_RelativeProjectPath(t *testing.T) { cdcDir := "/Users/Mike/Dev/my-project/cadence" paths := [][]string{ - {filepath.Join(cdcDir, "/contracts/foo.cdc"), "cadence/contracts/foo.cdc"}, - {filepath.Join(cdcDir, "/contracts/alice/foo.cdc"), "cadence/contracts/alice/foo.cdc"}, - {filepath.Join(cdcDir, "/scripts/bar.cdc"), "cadence/scripts/bar.cdc"}, - {filepath.Join(cdcDir, "/bar.cdc"), "cadence/bar.cdc"}, + {filepath.Join(cdcDir, "/contracts/foo.cdc"), filepath.FromSlash("cadence/contracts/foo.cdc")}, + {filepath.Join(cdcDir, "/contracts/alice/foo.cdc"), filepath.FromSlash("cadence/contracts/alice/foo.cdc")}, + {filepath.Join(cdcDir, "/scripts/bar.cdc"), filepath.FromSlash("cadence/scripts/bar.cdc")}, + {filepath.Join(cdcDir, "/bar.cdc"), filepath.FromSlash("cadence/bar.cdc")}, } f := &projectFiles{ diff --git a/internal/transactions/transactions_test.go b/internal/transactions/transactions_test.go index ad9e799c8..ef49d676a 100644 --- a/internal/transactions/transactions_test.go +++ b/internal/transactions/transactions_test.go @@ -20,6 +20,7 @@ package transactions import ( "encoding/json" + "fmt" "strings" "testing" @@ -31,6 +32,7 @@ import ( "github.com/onflow/flow-cli/flowkit" "github.com/onflow/flow-cli/flowkit/accounts" "github.com/onflow/flow-cli/flowkit/config" + "github.com/onflow/flow-cli/flowkit/output" "github.com/onflow/flow-cli/flowkit/tests" "github.com/onflow/flow-cli/flowkit/transactions" "github.com/onflow/flow-cli/internal/command" @@ -344,10 +346,10 @@ Payload (hidden, use --include payload)`, "\n"), result.String()) t.Run("Success with result", func(t *testing.T) { result := transactionResult{tx: tx, result: txResult} - assert.Equal(t, strings.TrimPrefix(` + expectedString := strings.TrimPrefix(fmt.Sprintf(` Block ID 7aa74143741c1c3b837d389fcffa7a5e251b67b4ffef6d6887b40cd9c803f537 Block Height 1 -Status ✅ SEALED +Status %s SEALED ID e913d1f3e431c7df49c99845bea9ebff9db11bbf25d507b9ad0fad45652d515f Payer 0000000000000002 Authorizers [] @@ -372,7 +374,9 @@ Events: Code (hidden, use --include code) -Payload (hidden, use --include payload)`, "\n"), result.String()) +Payload (hidden, use --include payload)`, output.OkEmoji()), "\n") + + assert.Equal(t, expectedString, result.String()) assert.Equal(t, map[string]any{ "authorizers": "[]",