Skip to content
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

Feat/fancy logging #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/gotest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: 1.19.1
- name: Set up gotestfmt
# https://github.com/GoTestTools/gotestfmt#github-actions
run: go install github.com/laurentsenta/gotestfmt/v2/cmd/gotestfmt@fix-coverage2
- name: Check out Kubo
uses: actions/checkout@v3
- name: Restore Go cache
Expand Down
7 changes: 5 additions & 2 deletions cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,8 +717,11 @@ func serveHTTPApi(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, error
return nil, fmt.Errorf("serveHTTPApi: ConstructNode() failed: %s", err)
}

if err := node.Repo.SetAPIAddr(rewriteMaddrToUseLocalhostIfItsAny(listeners[0].Multiaddr())); err != nil {
return nil, fmt.Errorf("serveHTTPApi: SetAPIAddr() failed: %w", err)
if len(listeners) > 0 {
// Only add an api file if the API is running.
if err := node.Repo.SetAPIAddr(rewriteMaddrToUseLocalhostIfItsAny(listeners[0].Multiaddr())); err != nil {
return nil, fmt.Errorf("serveHTTPApi: SetAPIAddr() failed: %w", err)
}
}

errc := make(chan error)
Expand Down
4 changes: 2 additions & 2 deletions coverage/Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ $(UCOVER_$(d)): $(d)/coverage_deps ALWAYS
$(eval TMP_PKG := $(subst _,/,$(basename $(@F))))
$(eval TMP_DEPS := $(shell $(GOCC) list -f '{{range .Deps}}{{.}} {{end}}' $(go-flags-with-tags) $(TMP_PKG) | sed 's/ /\n/g' | grep ipfs/go-ipfs) $(TMP_PKG))
$(eval TMP_DEPS_LIST := $(call join-with,$(comma),$(TMP_DEPS)))
$(GOCC) test $(go-flags-with-tags) $(GOTFLAGS) -v -covermode=atomic -json -coverpkg=$(TMP_DEPS_LIST) -coverprofile=$@ $(TMP_PKG) | tee -a test/unit/gotest.json

$(GOCC) test $(go-flags-with-tags) $(GOTFLAGS) -v -covermode=atomic -json -coverpkg=$(TMP_DEPS_LIST) -coverprofile=$@ $(TMP_PKG) | tee -a test/unit/gotest.json | gotestfmt
# ^^^ This is where we generate the gotest.json file.

$(d)/unit_tests.coverprofile: $(UCOVER_$(d))
gocovmerge $^ > $@
Expand Down
18 changes: 18 additions & 0 deletions test/cli/daemon_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cli

import (
"testing"

"github.com/ipfs/kubo/test/cli/harness"
)

func TestDaemon(t *testing.T) {
t.Parallel()

t.Run("daemon starts if api is set to null", func(t *testing.T) {
t.Parallel()
node := harness.NewT(t).NewNode().Init()
node.SetIPFSConfig("API", nil)
node.IPFS("daemon") // can't use .StartDaemon because it do a .WaitOnAPI
})
}
17 changes: 14 additions & 3 deletions test/cli/harness/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,20 @@ func (n *Node) SetIPFSConfig(key string, val interface{}, flags ...string) {
n.IPFS(args...)

// validate the config was set correctly
var newVal string
n.GetIPFSConfig(key, &newVal)
if val != newVal {

// Create a new value which is a pointer to the same type as the source.
var newVal any
if val != nil {
// If it is not nil grab the type with reflect.
newVal = reflect.New(reflect.TypeOf(val)).Interface()
} else {
// else just set a pointer to an any.
var anything any
newVal = &anything
}
n.GetIPFSConfig(key, newVal)
// dereference newVal using reflect to load the resulting value
if val != reflect.ValueOf(newVal).Elem().Interface() {
log.Panicf("key '%s' did not retain value '%s' after it was set, got '%s'", key, val, newVal)
}
}
Expand Down
1 change: 1 addition & 0 deletions test/unit/Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include mk/header.mk

CLEAN += $(d)/gotest.json $(d)/gotest.junit.xml

# looks like: we pass the `cat D/gotest.json` generated by a previous rule to gotestsum for formatting.
$(d)/gotest.junit.xml: test/bin/gotestsum coverage/unit_tests.coverprofile
gotestsum --no-color --junitfile $@ --raw-command cat $(@D)/gotest.json

Expand Down