summaryrefslogtreecommitdiff
path: root/internal/meta
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2022-01-15 12:08:20 +0300
committerValery Piashchynski <[email protected]>2022-01-15 12:08:20 +0300
commit5254c8eb27311e2a8a53a4c90c3829cf1238c563 (patch)
treeb51c9a4c1dd4c25adc511498ce0380a7078c5572 /internal/meta
parent13609dd03dd0d2fa85b9fb850be787bf4e2ea67f (diff)
Repository content update
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'internal/meta')
-rw-r--r--internal/meta/meta.go23
-rw-r--r--internal/meta/meta_test.go49
2 files changed, 72 insertions, 0 deletions
diff --git a/internal/meta/meta.go b/internal/meta/meta.go
new file mode 100644
index 00000000..0c5a0556
--- /dev/null
+++ b/internal/meta/meta.go
@@ -0,0 +1,23 @@
+package meta
+
+import "strings"
+
+// next variables will be set during compilation (do NOT rename them).
+var (
+ version = "local"
+ buildTime = "development" //nolint:gochecknoglobals
+)
+
+// Version returns version value (without `v` prefix).
+func Version() string {
+ v := strings.TrimSpace(version)
+
+ if len(v) > 1 && ((v[0] == 'v' || v[0] == 'V') && (v[1] >= '0' && v[1] <= '9')) {
+ return v[1:]
+ }
+
+ return v
+}
+
+// BuildTime returns application building time.
+func BuildTime() string { return buildTime }
diff --git a/internal/meta/meta_test.go b/internal/meta/meta_test.go
new file mode 100644
index 00000000..32dee122
--- /dev/null
+++ b/internal/meta/meta_test.go
@@ -0,0 +1,49 @@
+package meta
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestVersion(t *testing.T) {
+ for give, want := range map[string]string{
+ // without changes
+ "vvv": "vvv",
+ "victory": "victory",
+ "voodoo": "voodoo",
+ "foo": "foo",
+ "0.0.0": "0.0.0",
+ "v": "v",
+ "V": "V",
+
+ // "v" prefix removal
+ "v0.0.0": "0.0.0",
+ "V0.0.0": "0.0.0",
+ "v1": "1",
+ "V1": "1",
+
+ // with spaces
+ " 0.0.0": "0.0.0",
+ "v0.0.0 ": "0.0.0",
+ " V0.0.0": "0.0.0",
+ "v1 ": "1",
+ " V1": "1",
+ "v ": "v",
+ } {
+ version = give
+
+ assert.Equal(t, want, Version())
+ }
+}
+
+func TestBuildTime(t *testing.T) {
+ for give, want := range map[string]string{
+ "development": "development",
+ "2021-03-26T13:50:31+0500": "2021-03-26T13:50:31+0500",
+ } {
+ buildTime = give
+
+ assert.Equal(t, want, BuildTime())
+ }
+}