From 1063b954de0d41e6d052f2ddb00b53d31c9e5dfc Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 9 Apr 2020 14:05:46 +0300 Subject: [PATCH] dont display t.Log/t.Logf as errors in github actions (#1508) * fix tests and github action annotations Signed-off-by: Vasiliy Tolstov --- api/server/acme/certmagic/certmagic_test.go | 10 ++++++- client/selector/default_test.go | 5 +++- client/selector/strategy_test.go | 5 +++- config/source/file/file_test.go | 2 +- registry/memory/memory_test.go | 5 +++- registry/util_test.go | 9 +++++-- router/default_test.go | 21 +++++++++++---- store/cloudflare/cloudflare_test.go | 8 +++++- store/cockroach/cockroach_test.go | 7 ++++- store/file/file_test.go | 15 ++++++----- store/memory/memory_test.go | 29 ++++++++++++++++----- transport/memory/memory_test.go | 9 +++++-- tunnel/tunnel_test.go | 14 ++++++---- web/service.go | 4 +-- web/service_test.go | 16 +++++++++--- 15 files changed, 118 insertions(+), 41 deletions(-) diff --git a/api/server/acme/certmagic/certmagic_test.go b/api/server/acme/certmagic/certmagic_test.go index 30d698c8..12893dfe 100644 --- a/api/server/acme/certmagic/certmagic_test.go +++ b/api/server/acme/certmagic/certmagic_test.go @@ -18,7 +18,7 @@ import ( func TestCertMagic(t *testing.T) { if len(os.Getenv("IN_TRAVIS_CI")) != 0 { - t.Skip("Travis doesn't let us bind :443") + t.Skip() } l, err := NewProvider().Listen() if err != nil { @@ -52,6 +52,10 @@ func TestCertMagic(t *testing.T) { } func TestStorageImplementation(t *testing.T) { + if len(os.Getenv("IN_TRAVIS_CI")) != 0 { + t.Skip() + } + apiToken, accountID := os.Getenv("CF_API_TOKEN"), os.Getenv("CF_ACCOUNT_ID") kvID := os.Getenv("KV_NAMESPACE_ID") if len(apiToken) == 0 || len(accountID) == 0 || len(kvID) == 0 { @@ -189,6 +193,10 @@ func TestStorageImplementation(t *testing.T) { // Full test with a real zone, with against LE staging func TestE2e(t *testing.T) { + if len(os.Getenv("IN_TRAVIS_CI")) != 0 { + t.Skip() + } + apiToken, accountID := os.Getenv("CF_API_TOKEN"), os.Getenv("CF_ACCOUNT_ID") kvID := os.Getenv("KV_NAMESPACE_ID") if len(apiToken) == 0 || len(accountID) == 0 || len(kvID) == 0 { diff --git a/client/selector/default_test.go b/client/selector/default_test.go index d3b50003..60d10b1b 100644 --- a/client/selector/default_test.go +++ b/client/selector/default_test.go @@ -1,6 +1,7 @@ package selector import ( + "os" "testing" "github.com/micro/go-micro/v2/registry/memory" @@ -25,5 +26,7 @@ func TestRegistrySelector(t *testing.T) { counts[node.Id]++ } - t.Logf("Selector Counts %v", counts) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Selector Counts %v", counts) + } } diff --git a/client/selector/strategy_test.go b/client/selector/strategy_test.go index 07bf30b6..692c802f 100644 --- a/client/selector/strategy_test.go +++ b/client/selector/strategy_test.go @@ -1,6 +1,7 @@ package selector import ( + "os" "testing" "github.com/micro/go-micro/v2/registry" @@ -50,6 +51,8 @@ func TestStrategies(t *testing.T) { counts[node.Id]++ } - t.Logf("%s: %+v\n", name, counts) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("%s: %+v\n", name, counts) + } } } diff --git a/config/source/file/file_test.go b/config/source/file/file_test.go index 1d0a3ad0..e388a88a 100644 --- a/config/source/file/file_test.go +++ b/config/source/file/file_test.go @@ -59,8 +59,8 @@ func TestFile(t *testing.T) { if err != nil { t.Error(err) } - t.Logf("%+v", c) if string(c.Data) != string(data) { + t.Logf("%+v", c) t.Error("data from file does not match") } } diff --git a/registry/memory/memory_test.go b/registry/memory/memory_test.go index 9609b20c..0244a8da 100644 --- a/registry/memory/memory_test.go +++ b/registry/memory/memory_test.go @@ -2,6 +2,7 @@ package memory import ( "fmt" + "os" "testing" "time" @@ -205,7 +206,9 @@ func TestMemoryRegistryTTLConcurrent(t *testing.T) { } } - t.Logf("test will wait %v, then check TTL timeouts", waitTime) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("test will wait %v, then check TTL timeouts", waitTime) + } errChan := make(chan error, concurrency) syncChan := make(chan struct{}) diff --git a/registry/util_test.go b/registry/util_test.go index 75fd5133..e1a6e9a0 100644 --- a/registry/util_test.go +++ b/registry/util_test.go @@ -1,6 +1,7 @@ package registry import ( + "os" "testing" ) @@ -32,7 +33,9 @@ func TestRemove(t *testing.T) { if i := len(servs); i > 0 { t.Errorf("Expected 0 nodes, got %d: %+v", i, servs) } - t.Logf("Services %+v", servs) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Services %+v", servs) + } } func TestRemoveNodes(t *testing.T) { @@ -67,5 +70,7 @@ func TestRemoveNodes(t *testing.T) { if i := len(nodes); i != 1 { t.Errorf("Expected only 1 node, got %d: %+v", i, nodes) } - t.Logf("Nodes %+v", nodes) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Nodes %+v", nodes) + } } diff --git a/router/default_test.go b/router/default_test.go index 19d36423..4ed2f08e 100644 --- a/router/default_test.go +++ b/router/default_test.go @@ -2,6 +2,7 @@ package router import ( "fmt" + "os" "sync" "testing" "time" @@ -29,7 +30,9 @@ func TestRouterStartStop(t *testing.T) { if err := r.Stop(); err != nil { t.Errorf("failed to stop router: %v", err) } - t.Logf("TestRouterStartStop STOPPED") + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("TestRouterStartStop STOPPED") + } } func TestRouterAdvertise(t *testing.T) { @@ -49,7 +52,9 @@ func TestRouterAdvertise(t *testing.T) { // receive announce event ann := <-ch - t.Logf("received announce advert: %v", ann) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("received announce advert: %v", ann) + } // Generate random unique routes nrRoutes := 5 @@ -81,9 +86,13 @@ func TestRouterAdvertise(t *testing.T) { wg.Done() defer close(createDone) for _, route := range routes { - t.Logf("Creating route %v", route) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Creating route %v", route) + } if err := r.Table().Create(route); err != nil { - t.Logf("Failed to create route: %v", err) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Failed to create route: %v", err) + } errChan <- err return } @@ -105,7 +114,9 @@ func TestRouterAdvertise(t *testing.T) { t.Errorf("failed advertising events: %v", advertErr) default: // do nothing for now - t.Logf("Router advert received: %v", advert) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Router advert received: %v", advert) + } adverts += len(advert.Events) } return diff --git a/store/cloudflare/cloudflare_test.go b/store/cloudflare/cloudflare_test.go index dbf78c26..9cc7a05b 100644 --- a/store/cloudflare/cloudflare_test.go +++ b/store/cloudflare/cloudflare_test.go @@ -11,6 +11,10 @@ import ( ) func TestCloudflare(t *testing.T) { + if len(os.Getenv("IN_TRAVIS_CI")) != 0 { + t.Skip() + } + apiToken, accountID := os.Getenv("CF_API_TOKEN"), os.Getenv("CF_ACCOUNT_ID") kvID := os.Getenv("KV_NAMESPACE_ID") if len(apiToken) == 0 || len(accountID) == 0 || len(kvID) == 0 { @@ -31,7 +35,9 @@ func TestCloudflare(t *testing.T) { if err != nil { t.Fatalf("List: %s\n", err.Error()) } else { - t.Log("Listed " + strconv.Itoa(len(records)) + " records") + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Log("Listed " + strconv.Itoa(len(records)) + " records") + } } err = wkv.Write(&store.Record{ diff --git a/store/cockroach/cockroach_test.go b/store/cockroach/cockroach_test.go index f5b0077c..5bd6dc40 100644 --- a/store/cockroach/cockroach_test.go +++ b/store/cockroach/cockroach_test.go @@ -3,6 +3,7 @@ package cockroach import ( "database/sql" "fmt" + "os" "testing" "time" @@ -11,6 +12,10 @@ import ( ) func TestSQL(t *testing.T) { + if len(os.Getenv("IN_TRAVIS_CI")) != 0 { + t.Skip() + } + connection := fmt.Sprintf( "host=%s port=%d user=%s sslmode=disable dbname=%s", "localhost", @@ -23,7 +28,7 @@ func TestSQL(t *testing.T) { t.Fatal(err) } if err := db.Ping(); err != nil { - t.Skip(err) + t.Fatal(err) } db.Close() diff --git a/store/file/file_test.go b/store/file/file_test.go index 6dd58c64..fded4644 100644 --- a/store/file/file_test.go +++ b/store/file/file_test.go @@ -53,8 +53,9 @@ func TestFileStoreDatabaseTable(t *testing.T) { } func fileTest(s store.Store, t *testing.T) { - t.Logf("Options %s %v\n", s.String(), s.Options()) - + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Options %s %v\n", s.String(), s.Options()) + } // Read and Write an expiring Record if err := s.Write(&store.Record{ Key: "Hello", @@ -109,7 +110,7 @@ func fileTest(s store.Store, t *testing.T) { } else { if len(results) != 2 { t.Errorf("Expected 2 items, got %d", len(results)) - t.Logf("Table test: %v\n", spew.Sdump(results)) + //t.Logf("Table test: %v\n", spew.Sdump(results)) } } @@ -120,7 +121,7 @@ func fileTest(s store.Store, t *testing.T) { t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", spew.Sdump(results), err) } else if len(results) != 1 { t.Errorf("Expected 1 item, got %d", len(results)) - t.Logf("Table test: %v\n", spew.Sdump(results)) + //t.Logf("Table test: %v\n", spew.Sdump(results)) } if err := s.Delete("foo"); err != nil { @@ -163,7 +164,7 @@ func fileTest(s store.Store, t *testing.T) { } else { if len(results) != 3 { t.Errorf("Expected 3 items, got %d", len(results)) - t.Logf("Table test: %v\n", spew.Sdump(results)) + //t.Logf("Table test: %v\n", spew.Sdump(results)) } } @@ -173,7 +174,7 @@ func fileTest(s store.Store, t *testing.T) { } else { if len(results) != 2 { t.Errorf("Expected 2 items, got %d", len(results)) - t.Logf("Table test: %v\n", spew.Sdump(results)) + //t.Logf("Table test: %v\n", spew.Sdump(results)) } } @@ -183,7 +184,7 @@ func fileTest(s store.Store, t *testing.T) { } else { if len(results) != 1 { t.Errorf("Expected 1 item, got %d", len(results)) - t.Logf("Table test: %# v\n", spew.Sdump(results)) + // t.Logf("Table test: %# v\n", spew.Sdump(results)) } } if err := s.Delete("foo"); err != nil { diff --git a/store/memory/memory_test.go b/store/memory/memory_test.go index 14ac49a6..8d51ea0d 100644 --- a/store/memory/memory_test.go +++ b/store/memory/memory_test.go @@ -2,6 +2,7 @@ package memory import ( "fmt" + "os" "testing" "time" @@ -42,7 +43,9 @@ func TestMemoryNamespacePrefix(t *testing.T) { } func basictest(s store.Store, t *testing.T) { - t.Logf("Testing store %s, with options %# v\n", s.String(), pretty.Formatter(s.Options())) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Testing store %s, with options %# v\n", s.String(), pretty.Formatter(s.Options())) + } // Read and Write an expiring Record if err := s.Write(&store.Record{ Key: "Hello", @@ -97,7 +100,9 @@ func basictest(s store.Store, t *testing.T) { if len(results) != 3 { t.Errorf("Expected 3 items, got %d", len(results)) } - t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + } } time.Sleep(time.Millisecond * 100) if results, err := s.Read("foo", store.ReadPrefix()); err != nil { @@ -106,7 +111,9 @@ func basictest(s store.Store, t *testing.T) { if len(results) != 2 { t.Errorf("Expected 2 items, got %d", len(results)) } - t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + } } time.Sleep(time.Millisecond * 100) if results, err := s.Read("foo", store.ReadPrefix()); err != nil { @@ -115,7 +122,9 @@ func basictest(s store.Store, t *testing.T) { if len(results) != 1 { t.Errorf("Expected 1 item, got %d", len(results)) } - t.Logf("Prefix test: %# v\n", pretty.Formatter(results)) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Prefix test: %# v\n", pretty.Formatter(results)) + } } if err := s.Delete("foo", func(d *store.DeleteOptions) {}); err != nil { t.Errorf("Delete failed (%v)", err) @@ -156,7 +165,9 @@ func basictest(s store.Store, t *testing.T) { if len(results) != 3 { t.Errorf("Expected 3 items, got %d", len(results)) } - t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + } } time.Sleep(time.Millisecond * 100) if results, err := s.Read("foo", store.ReadSuffix()); err != nil { @@ -165,7 +176,9 @@ func basictest(s store.Store, t *testing.T) { if len(results) != 2 { t.Errorf("Expected 2 items, got %d", len(results)) } - t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + } } time.Sleep(time.Millisecond * 100) if results, err := s.Read("foo", store.ReadSuffix()); err != nil { @@ -174,7 +187,9 @@ func basictest(s store.Store, t *testing.T) { if len(results) != 1 { t.Errorf("Expected 1 item, got %d", len(results)) } - t.Logf("Prefix test: %# v\n", pretty.Formatter(results)) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Prefix test: %# v\n", pretty.Formatter(results)) + } } if err := s.Delete("foo"); err != nil { t.Errorf("Delete failed (%v)", err) diff --git a/transport/memory/memory_test.go b/transport/memory/memory_test.go index 50e64aaf..1d46d401 100644 --- a/transport/memory/memory_test.go +++ b/transport/memory/memory_test.go @@ -1,6 +1,7 @@ package memory import ( + "os" "testing" "github.com/micro/go-micro/v2/transport" @@ -24,7 +25,9 @@ func TestMemoryTransport(t *testing.T) { if err := sock.Recv(&m); err != nil { return } - t.Logf("Server Received %s", string(m.Body)) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Server Received %s", string(m.Body)) + } if err := sock.Send(&transport.Message{ Body: []byte(`pong`), }); err != nil { @@ -54,7 +57,9 @@ func TestMemoryTransport(t *testing.T) { if err := c.Recv(&m); err != nil { return } - t.Logf("Client Received %s", string(m.Body)) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Client Received %s", string(m.Body)) + } } } diff --git a/tunnel/tunnel_test.go b/tunnel/tunnel_test.go index 2e86baf0..1c620347 100644 --- a/tunnel/tunnel_test.go +++ b/tunnel/tunnel_test.go @@ -1,6 +1,7 @@ package tunnel import ( + "os" "sync" "testing" "time" @@ -288,12 +289,15 @@ func TestTunnelRTTRate(t *testing.T) { // wait until done wg.Wait() - for _, link := range tunA.Links() { - t.Logf("Link %s length %v rate %v", link.Id(), link.Length(), link.Rate()) - } + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + // only needed for debug + for _, link := range tunA.Links() { + t.Logf("Link %s length %v rate %v", link.Id(), link.Length(), link.Rate()) + } - for _, link := range tunB.Links() { - t.Logf("Link %s length %v rate %v", link.Id(), link.Length(), link.Rate()) + for _, link := range tunB.Links() { + t.Logf("Link %s length %v rate %v", link.Id(), link.Length(), link.Rate()) + } } } diff --git a/web/service.go b/web/service.go index 069a53e2..737f801b 100644 --- a/web/service.go +++ b/web/service.go @@ -226,8 +226,8 @@ func (s *service) start() error { ch <- l.Close() }() - if logger.V(logger.InfoLevel, log) { - log.Infof("Listening on %v", l.Addr().String()) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Listening on %v", l.Addr().String()) } return nil } diff --git a/web/service_test.go b/web/service_test.go index 428f9424..0d033038 100644 --- a/web/service_test.go +++ b/web/service_test.go @@ -110,7 +110,9 @@ func TestService(t *testing.T) { t.Fatalf("service.Run():%v", err) } case <-time.After(time.Duration(time.Second)): - t.Logf("service.Run() survived a client request without an error") + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("service.Run() survived a client request without an error") + } } ch := make(chan os.Signal, 1) @@ -125,10 +127,14 @@ func TestService(t *testing.T) { if err != nil { t.Fatalf("service.Run():%v", err) } else { - t.Log("service.Run() nil return on syscall.SIGTERM") + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Log("service.Run() nil return on syscall.SIGTERM") + } } case <-time.After(time.Duration(time.Second)): - t.Logf("service.Run() survived a client request without an error") + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("service.Run() survived a client request without an error") + } } eventually(func() bool { @@ -286,7 +292,9 @@ func TestTLS(t *testing.T) { t.Fatalf("service.Run():%v", err) } case <-time.After(time.Duration(time.Second)): - t.Logf("service.Run() survived a client request without an error") + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("service.Run() survived a client request without an error") + } } }