This repository has been archived by the owner on Nov 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDI-2274: GRPC based collectors **must** provide LastAdvertisedTime o…
…r framework panics
- Loading branch information
1 parent
c2aef10
commit 5f1e84f
Showing
2 changed files
with
87 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// +build small | ||
|
||
/* | ||
http://www.apache.org/licenses/LICENSE-2.0.txt | ||
Copyright 2016 Intel Corporation | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package client | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/intelsdi-x/snap/core" | ||
. "github.com/smartystreets/goconvey/convey" | ||
) | ||
|
||
func TestToCoreMetric(t *testing.T) { | ||
tc := testCases() | ||
Convey("Test ToCoreMetric", t, func() { | ||
for _, c := range tc { | ||
Convey(c.description, func() { | ||
mt := ToMetric(c) | ||
cmt := ToCoreMetric(mt) | ||
So(cmt.Timestamp(), ShouldNotBeNil) | ||
So(cmt.LastAdvertisedTime(), ShouldNotBeNil) | ||
|
||
if cmt.Version() == 2 { | ||
So(cmt.Timestamp(), ShouldResemble, cmt.LastAdvertisedTime()) | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
func testCases() []*metric { | ||
now := time.Now() | ||
tc := []*metric{ | ||
&metric{ | ||
namespace: core.NewNamespace("a", "b", "c"), | ||
version: 1, | ||
description: "No timeStamp and lastAdvertisedTime defined", | ||
}, | ||
&metric{ | ||
namespace: core.NewNamespace("x", "y", "z"), | ||
version: 1, | ||
timeStamp: time.Now(), | ||
description: "Has timestamp but no lastAdvertisedTime defined", | ||
}, | ||
&metric{ | ||
namespace: core.NewNamespace("x", "y", "z"), | ||
version: 1, | ||
lastAdvertisedTime: time.Now(), | ||
description: "No timestamp but has lastAdvertisedTime defined", | ||
}, | ||
&metric{ | ||
namespace: core.NewNamespace("x", "y", "z"), | ||
version: 2, | ||
timeStamp: now, | ||
lastAdvertisedTime: now, | ||
description: "Has both timestamp and lastAdvertisedTime defined", | ||
}, | ||
} | ||
return tc | ||
} |