-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release v1.5.3
- Loading branch information
Showing
16 changed files
with
162 additions
and
25 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
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
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,50 @@ | ||
package device | ||
|
||
import ( | ||
"runtime" | ||
) | ||
|
||
// Cached runtime versions that can be updated globally by framework | ||
// integrations through AddVersion. | ||
var versions *RuntimeVersions | ||
|
||
// RuntimeVersions define the various versions of Go and any framework that may | ||
// be in use. | ||
// As a user of the notifier you're unlikely to need to modify this struct. | ||
// As such, the authors reserve the right to introduce breaking changes to the | ||
// properties in this struct. In particular the framework versions are liable | ||
// to change in new versions of the notifier in minor/patch versions. | ||
type RuntimeVersions struct { | ||
Go string `json:"go"` | ||
|
||
Gin string `json:"gin,omitempty"` | ||
Martini string `json:"martini,omitempty"` | ||
Negroni string `json:"negroni,omitempty"` | ||
Revel string `json:"revel,omitempty"` | ||
} | ||
|
||
// GetRuntimeVersions retrieves the recorded runtime versions in a goroutine-safe manner. | ||
func GetRuntimeVersions() *RuntimeVersions { | ||
if versions == nil { | ||
versions = &RuntimeVersions{Go: runtime.Version()} | ||
} | ||
return versions | ||
} | ||
|
||
// AddVersion permits a framework to register its version, assuming it's one of | ||
// the officially supported frameworks. | ||
func AddVersion(framework, version string) { | ||
if versions == nil { | ||
versions = &RuntimeVersions{Go: runtime.Version()} | ||
} | ||
switch framework { | ||
case "Martini": | ||
versions.Martini = version | ||
case "Gin": | ||
versions.Gin = version | ||
case "Negroni": | ||
versions.Negroni = version | ||
case "Revel": | ||
versions.Revel = version | ||
} | ||
} |
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,43 @@ | ||
package device | ||
|
||
import ( | ||
"runtime" | ||
"testing" | ||
) | ||
|
||
func TestPristineRuntimeVersions(t *testing.T) { | ||
versions = nil // reset global variable | ||
rv := GetRuntimeVersions() | ||
for _, tc := range []struct{ name, got, exp string }{ | ||
{name: "Go", got: rv.Go, exp: runtime.Version()}, | ||
{name: "Gin", got: rv.Gin, exp: ""}, | ||
{name: "Martini", got: rv.Martini, exp: ""}, | ||
{name: "Negroni", got: rv.Negroni, exp: ""}, | ||
{name: "Revel", got: rv.Revel, exp: ""}, | ||
} { | ||
if tc.got != tc.exp { | ||
t.Errorf("expected pristine '%s' runtime version to be '%s' but was '%s'", tc.name, tc.exp, tc.got) | ||
} | ||
} | ||
} | ||
|
||
func TestModifiedRuntimeVersions(t *testing.T) { | ||
versions = nil // reset global variable | ||
rv := GetRuntimeVersions() | ||
AddVersion("Gin", "1.2.1") | ||
AddVersion("Martini", "1.0.0") | ||
AddVersion("Negroni", "1.0.2") | ||
AddVersion("Revel", "0.20.1") | ||
for _, tc := range []struct{ name, got, exp string }{ | ||
{name: "Go", got: rv.Go, exp: runtime.Version()}, | ||
{name: "Gin", got: rv.Gin, exp: "1.2.1"}, | ||
{name: "Martini", got: rv.Martini, exp: "1.0.0"}, | ||
{name: "Negroni", got: rv.Negroni, exp: "1.0.2"}, | ||
{name: "Revel", got: rv.Revel, exp: "0.20.1"}, | ||
} { | ||
if tc.got != tc.exp { | ||
t.Errorf("expected modified '%s' runtime version to be '%s' but was '%s'", tc.name, tc.exp, tc.got) | ||
} | ||
} | ||
|
||
} |
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
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
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
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
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