mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-03 08:50:42 +02:00
initial release
This commit is contained in:
commit
d56c889224
62 changed files with 8229 additions and 0 deletions
42
internal/version/version.go
Normal file
42
internal/version/version.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package version // import "github.com/pomerium/pomerium/internal/version"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
// ProjectName is the canonical project name set by ldl flags
|
||||
ProjectName = ""
|
||||
// ProjectURL is the canonical project url set by ldl flags
|
||||
ProjectURL = ""
|
||||
// Version specifies Semantic versioning increment (MAJOR.MINOR.PATCH).
|
||||
Version = "v0.0.0"
|
||||
// GitCommit specifies the git commit sha, set by the compiler.
|
||||
GitCommit = ""
|
||||
// BuildMeta specifies release type (dev,rc1,beta,etc)
|
||||
BuildMeta = ""
|
||||
|
||||
runtimeVersion = runtime.Version()
|
||||
)
|
||||
|
||||
// FullVersion returns a version string.
|
||||
func FullVersion() string {
|
||||
var sb strings.Builder
|
||||
sb.Grow(len(Version) + len(GitCommit) + len(BuildMeta) + len("-") + len("+"))
|
||||
sb.WriteString(Version)
|
||||
if BuildMeta != "" {
|
||||
sb.WriteString("-" + BuildMeta)
|
||||
}
|
||||
if GitCommit != "" {
|
||||
sb.WriteString("+" + GitCommit)
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
// UserAgent returns a user-agent string as specified in RFC 2616:14.43
|
||||
// https://tools.ietf.org/html/rfc2616
|
||||
func UserAgent() string {
|
||||
return fmt.Sprintf("%s/%s (+%s; %s; %s)", ProjectName, Version, ProjectURL, GitCommit, runtimeVersion)
|
||||
}
|
71
internal/version/version_test.go
Normal file
71
internal/version/version_test.go
Normal file
|
@ -0,0 +1,71 @@
|
|||
package version // import "github.com/pomerium/pomerium/internal/version"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFullVersionVersion(t *testing.T) {
|
||||
tests := []struct {
|
||||
Version string
|
||||
GitCommit string
|
||||
BuildMeta string
|
||||
|
||||
expected string
|
||||
}{
|
||||
{"", "", "", ""},
|
||||
{"1.0.0", "", "", "1.0.0"},
|
||||
{"1.0.0", "314501b", "", "1.0.0+314501b"},
|
||||
{"1.0.0", "314501b", "dev", "1.0.0-dev+314501b"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
Version = tt.Version
|
||||
GitCommit = tt.GitCommit
|
||||
BuildMeta = tt.BuildMeta
|
||||
|
||||
if got := FullVersion(); got != tt.expected {
|
||||
t.Errorf("expected (%s) got (%s) for Version(%s), GitCommit(%s) BuildMeta(%s)",
|
||||
tt.expected,
|
||||
got,
|
||||
tt.Version,
|
||||
tt.GitCommit,
|
||||
tt.BuildMeta)
|
||||
}
|
||||
}
|
||||
}
|
||||
func BenchmarkFullVersion(b *testing.B) {
|
||||
Version = "1.0.0"
|
||||
GitCommit = "314501b"
|
||||
BuildMeta = "dev"
|
||||
for i := 0; i < b.N; i++ {
|
||||
FullVersion()
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserAgent(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
Version string
|
||||
GitCommit string
|
||||
BuildMeta string
|
||||
ProjectName string
|
||||
ProjectURL string
|
||||
want string
|
||||
}{
|
||||
{"good user agent", "1.0.0", "314501b", "dev", "pomerium", "github.com/pomerium", fmt.Sprintf("pomerium/1.0.0 (+github.com/pomerium; 314501b; %s)", runtime.Version())},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
Version = tt.Version
|
||||
GitCommit = tt.GitCommit
|
||||
BuildMeta = tt.BuildMeta
|
||||
ProjectName = tt.ProjectName
|
||||
ProjectURL = tt.ProjectURL
|
||||
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := UserAgent(); got != tt.want {
|
||||
t.Errorf("UserAgent() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue