From 3045146dfec4c70d8e7fd06e49ca93c7ea6c74a2 Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Wed, 29 Nov 2023 11:10:46 +0100 Subject: Move function with only one usage --- client/go/internal/admin/jvm/application_container.go | 13 +++++++++++-- .../go/internal/admin/jvm/application_container_test.go | 15 +++++++++++++++ client/go/internal/util/md5.go | 17 ----------------- client/go/internal/util/md5_test.go | 13 ------------- 4 files changed, 26 insertions(+), 32 deletions(-) create mode 100644 client/go/internal/admin/jvm/application_container_test.go delete mode 100644 client/go/internal/util/md5.go delete mode 100644 client/go/internal/util/md5_test.go (limited to 'client/go') diff --git a/client/go/internal/admin/jvm/application_container.go b/client/go/internal/admin/jvm/application_container.go index c525ea77949..3959ccca5e9 100644 --- a/client/go/internal/admin/jvm/application_container.go +++ b/client/go/internal/admin/jvm/application_container.go @@ -4,7 +4,9 @@ package jvm import ( + "crypto/md5" "fmt" + "io" "os" "github.com/vespa-engine/vespa/client/go/internal/admin/defaults" @@ -22,6 +24,13 @@ type ApplicationContainer struct { containerBase } +func md5Hex(text string) string { + hasher := md5.New() + io.WriteString(hasher, text) + hash := hasher.Sum(nil) + return fmt.Sprintf("%x", hash) +} + func (a *ApplicationContainer) ArgForMain() string { dir := defaults.UnderVespaHome("lib/jars") return fmt.Sprintf("file:%s/%s", dir, JAR_FOR_APPLICATION_CONTAINER) @@ -31,7 +40,7 @@ func (a *ApplicationContainer) Discriminator() string { cfgId := a.ConfigId() if cfgId != "" { trace.Trace("Discriminator: using md5 of", cfgId) - return util.Md5Hex(cfgId + "\n") + return md5Hex(cfgId + "\n") } svcName := a.ServiceName() if svcName != "" { @@ -40,7 +49,7 @@ func (a *ApplicationContainer) Discriminator() string { } pid := os.Getpid() trace.Trace("Discriminator: using md5 of", pid) - return util.Md5Hex(fmt.Sprintf("%d", pid)) + return md5Hex(fmt.Sprintf("%d", pid)) } func (a *ApplicationContainer) addJdiscProperties() { diff --git a/client/go/internal/admin/jvm/application_container_test.go b/client/go/internal/admin/jvm/application_container_test.go new file mode 100644 index 00000000000..3a062edee16 --- /dev/null +++ b/client/go/internal/admin/jvm/application_container_test.go @@ -0,0 +1,15 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Author: arnej + +package jvm + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestMD5SimpleInputs(t *testing.T) { + assert.Equal(t, "d41d8cd98f00b204e9800998ecf8427e", md5Hex("")) + assert.Equal(t, "4044e8209f286312a68bbb54f8714922", md5Hex("admin/cluster-controllers/0\n")) +} diff --git a/client/go/internal/util/md5.go b/client/go/internal/util/md5.go deleted file mode 100644 index 6a98b49c472..00000000000 --- a/client/go/internal/util/md5.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -// Author: arnej - -package util - -import ( - "crypto/md5" - "fmt" - "io" -) - -func Md5Hex(text string) string { - hasher := md5.New() - io.WriteString(hasher, text) - hash := hasher.Sum(nil) - return fmt.Sprintf("%x", hash) -} diff --git a/client/go/internal/util/md5_test.go b/client/go/internal/util/md5_test.go deleted file mode 100644 index ac3bc6a9546..00000000000 --- a/client/go/internal/util/md5_test.go +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package util - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestMD5SimpleInputs(t *testing.T) { - assert.Equal(t, "d41d8cd98f00b204e9800998ecf8427e", Md5Hex("")) - assert.Equal(t, "4044e8209f286312a68bbb54f8714922", Md5Hex("admin/cluster-controllers/0\n")) -} -- cgit v1.2.3