-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
731 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package buildinfo | ||
|
||
var ( | ||
// Branch contains the current Git revision. Use make to build to make | ||
// sure this gets set. | ||
branch string | ||
|
||
// BuildDate contains the date of the current build. | ||
buildDate string | ||
|
||
// Version contains version | ||
version string | ||
|
||
// Version contains repository name | ||
repo string | ||
) | ||
|
||
// BuildInfo contains information about the current build | ||
type BuildInfo struct { | ||
Version string `json:"version,omitempty"` | ||
Branch string `json:"branch,omitempty"` | ||
BuildDate string `json:"build_date,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
Repo string `json:"repo,omitempty"` | ||
} | ||
|
||
// GetBuildInfo returns build info data | ||
func GetBuildInfo() *BuildInfo { | ||
return &BuildInfo{ | ||
Version: version, | ||
Branch: branch, | ||
BuildDate: buildDate, | ||
Repo: repo, | ||
} | ||
} |
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,27 @@ | ||
package buildinfo | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"net/http/httptest" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestBuildInfo(t *testing.T) { | ||
buildInfo := GetBuildInfo() | ||
buildInfo.Name = "test" | ||
rr := httptest.NewRecorder() | ||
rr.WriteHeader(http.StatusOK) | ||
e := json.NewEncoder(rr).Encode(buildInfo) | ||
// Check the status code is what we expect. | ||
if nil != e { | ||
t.Error("Something went wrong with serialization") | ||
} | ||
|
||
expected := `{"name":"test"}` | ||
if strings.TrimSpace(rr.Body.String()) != expected { | ||
t.Errorf("incorrect build format response: got %v want %v", | ||
rr.Body.String(), expected) | ||
} | ||
} |
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
Oops, something went wrong.