From 787faf56fd6708bce02cc87fbe5844faf0423c0d Mon Sep 17 00:00:00 2001 From: aricart Date: Tue, 3 Dec 2019 10:55:48 -0400 Subject: [PATCH] Relaxed sampling for service latency, as 0 disables it. Fixed new staticcheck errors --- account_claims_test.go | 2 +- activation_claims_test.go | 2 +- cluster_claims_test.go | 2 +- exports.go | 4 ++-- exports_test.go | 18 +++++++++++++----- header.go | 2 +- operator_claims_test.go | 2 +- server_claims_test.go | 2 +- user_claims_test.go | 2 +- 9 files changed, 22 insertions(+), 14 deletions(-) diff --git a/account_claims_test.go b/account_claims_test.go index bdeb1de..c9fe4a2 100644 --- a/account_claims_test.go +++ b/account_claims_test.go @@ -228,7 +228,7 @@ func TestAccountImports(t *testing.T) { func TestNewNilAccountClaim(t *testing.T) { v := NewAccountClaims("") if v != nil { - t.Fatal(fmt.Sprintf("expected nil account claim")) + t.Fatal("expected nil account claim") } } diff --git a/activation_claims_test.go b/activation_claims_test.go index aed77df..2f76ded 100644 --- a/activation_claims_test.go +++ b/activation_claims_test.go @@ -136,7 +136,7 @@ func TestPublicIsNotValid(t *testing.T) { func TestNilActivationClaim(t *testing.T) { v := NewActivationClaims("") if v != nil { - t.Fatal(fmt.Sprintf("expected nil user claim")) + t.Fatal("expected nil activation claim") } } diff --git a/cluster_claims_test.go b/cluster_claims_test.go index bc84c77..45f9239 100644 --- a/cluster_claims_test.go +++ b/cluster_claims_test.go @@ -113,7 +113,7 @@ func TestClusterSubjects(t *testing.T) { func TestNewNilClusterClaims(t *testing.T) { v := NewClusterClaims("") if v != nil { - t.Fatal(fmt.Sprintf("expected nil user claim")) + t.Fatal("expected nil cluster claim") } } diff --git a/exports.go b/exports.go index 5578f98..00bc522 100644 --- a/exports.go +++ b/exports.go @@ -60,8 +60,8 @@ type ServiceLatency struct { } func (sl *ServiceLatency) Validate(vr *ValidationResults) { - if sl.Sampling < 1 || sl.Sampling > 100 { - vr.AddError("sampling percentage needs to be between 1-100") + if sl.Sampling < 0 || sl.Sampling > 100 { + vr.AddError("sampling percentage needs to be between 0-100") } sl.Results.Validate(vr) if sl.Results.HasWildCards() { diff --git a/exports_test.go b/exports_test.go index b674c90..f47bb42 100644 --- a/exports_test.go +++ b/exports_test.go @@ -229,7 +229,7 @@ func TestExportRevocation(t *testing.T) { e.RevokeAt(pubKey, now.Add(time.Second*1000)) if !e.IsRevoked(pubKey) { - t.Errorf("revocation be true we revoked in the future") + t.Error("revocation be true we revoked in the future") } } @@ -247,15 +247,23 @@ func TestExportTrackLatency(t *testing.T) { vr = CreateValidationResults() e.Validate(vr) if vr.IsEmpty() { - t.Errorf("adding latency tracking to a stream should have an validation issue") + t.Error("adding latency tracking to a stream should have an validation issue") } e = &Export{Subject: "foo", Type: Service} e.Latency = &ServiceLatency{Sampling: 0, Results: "results"} vr = CreateValidationResults() e.Validate(vr) + if !vr.IsEmpty() { + t.Fatal(vr.Issues[0]) + } + + e = &Export{Subject: "foo", Type: Service} + e.Latency = &ServiceLatency{Sampling: -1, Results: "results"} + vr = CreateValidationResults() + e.Validate(vr) if vr.IsEmpty() { - t.Errorf("Sampling <1 should have a validation issue") + t.Error("Sampling < 0 should have a validation issue") } e = &Export{Subject: "foo", Type: Service} @@ -263,7 +271,7 @@ func TestExportTrackLatency(t *testing.T) { vr = CreateValidationResults() e.Validate(vr) if vr.IsEmpty() { - t.Errorf("Sampling >100 should have a validation issue") + t.Error("Sampling >100 should have a validation issue") } e = &Export{Subject: "foo", Type: Service} @@ -271,7 +279,7 @@ func TestExportTrackLatency(t *testing.T) { vr = CreateValidationResults() e.Validate(vr) if vr.IsEmpty() { - t.Errorf("Results subject needs to be valid publish subject") + t.Error("Results subject needs to be valid publish subject") } } diff --git a/header.go b/header.go index 27c6581..796cab4 100644 --- a/header.go +++ b/header.go @@ -23,7 +23,7 @@ import ( const ( // Version is semantic version. - Version = "0.3.2" + Version = "0.3.4" // TokenTypeJwt is the JWT token type supported JWT tokens // encoded and decoded by this library diff --git a/operator_claims_test.go b/operator_claims_test.go index 750dce1..c761c44 100644 --- a/operator_claims_test.go +++ b/operator_claims_test.go @@ -110,7 +110,7 @@ func TestInvalidOperatorClaimIssuer(t *testing.T) { func TestNewNilOperatorClaims(t *testing.T) { v := NewOperatorClaims("") if v != nil { - t.Fatal(fmt.Sprintf("expected nil user claim")) + t.Fatal("expected nil operator claim") } } diff --git a/server_claims_test.go b/server_claims_test.go index b81c829..b66d1c0 100644 --- a/server_claims_test.go +++ b/server_claims_test.go @@ -113,7 +113,7 @@ func TestServerSubjects(t *testing.T) { func TestNewNilServerClaims(t *testing.T) { v := NewServerClaims("") if v != nil { - t.Fatal(fmt.Sprintf("expected nil user claim")) + t.Fatal("expected nil server claim") } } diff --git a/user_claims_test.go b/user_claims_test.go index 7c8f547..c9da7fe 100644 --- a/user_claims_test.go +++ b/user_claims_test.go @@ -113,7 +113,7 @@ func TestUserSubjects(t *testing.T) { func TestNewNilUserClaim(t *testing.T) { v := NewUserClaims("") if v != nil { - t.Fatal(fmt.Sprintf("expected nil user claim")) + t.Fatal("expected nil user claim") } }