diff options
Diffstat (limited to 'workhorse/internal/version')
-rw-r--r-- | workhorse/internal/version/version.go | 20 | ||||
-rw-r--r-- | workhorse/internal/version/version_test.go | 19 |
2 files changed, 39 insertions, 0 deletions
diff --git a/workhorse/internal/version/version.go b/workhorse/internal/version/version.go new file mode 100644 index 00000000000..790edf8ffca --- /dev/null +++ b/workhorse/internal/version/version.go @@ -0,0 +1,20 @@ +package version + +import "fmt" + +var version = "unknown" +var build = "unknown" +var schema = "gitlab-workhorse (%s)-(%s)" + +func SetVersion(v, b string) { + version = v + build = b +} + +func GetUserAgent() string { + return GetApplicationVersion() +} + +func GetApplicationVersion() string { + return fmt.Sprintf(schema, version, build) +} diff --git a/workhorse/internal/version/version_test.go b/workhorse/internal/version/version_test.go new file mode 100644 index 00000000000..9d0581e093b --- /dev/null +++ b/workhorse/internal/version/version_test.go @@ -0,0 +1,19 @@ +package version + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestVersion(t *testing.T) { + require.Equal(t, GetApplicationVersion(), "gitlab-workhorse (unknown)-(unknown)") + + SetVersion("15.3", "123.123") + + require.Equal(t, GetApplicationVersion(), "gitlab-workhorse (15.3)-(123.123)") + + SetVersion("", "123.123") + + require.Equal(t, GetApplicationVersion(), "gitlab-workhorse ()-(123.123)") +} |