Skip to content
Snippets Groups Projects
Commit f8d08edf authored by Jan Christophersen's avatar Jan Christophersen
Browse files

Fix wrong address being returned, add Unit tests

parent d057c11d
Branches
Tags
No related merge requests found
......@@ -88,7 +88,7 @@ func (c *configOptionsWithMetricsServer) metricsServerAddress() (string, error)
if len(port) == 0 {
return fmt.Sprintf("%s:%d", address, common.DefaultMetricsServerPort), nil
}
return c.config.MetricsServerAddress, nil
return address, nil
}
func init() {
......
package commands
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
)
func TestMetricsServerDefaultPort(t *testing.T) {
cfg := configOptionsWithMetricsServer{}
cfg.config = &common.Config{}
cfg.MetricsServerAddress = "localhost"
address, err := cfg.metricsServerAddress()
assert.NoError(t, err)
assert.Equal(t, address, fmt.Sprintf("%s:%d", cfg.MetricsServerAddress, common.DefaultMetricsServerPort))
}
func TestMetricsServerDefaultPortCommonConfig(t *testing.T) {
cfg := configOptionsWithMetricsServer{}
cfg.config = &common.Config{}
cfg.config.MetricsServerAddress = "localhost"
address, err := cfg.metricsServerAddress()
assert.NoError(t, err)
assert.Equal(t, address, fmt.Sprintf("%s:%d", cfg.config.MetricsServerAddress, common.DefaultMetricsServerPort))
}
func TestMetricsServerDoesNotTouchExistingPort(t *testing.T) {
cfg := configOptionsWithMetricsServer{}
cfg.config = &common.Config{}
cfg.MetricsServerAddress = "localhost:1234"
address, err := cfg.metricsServerAddress()
assert.NoError(t, err)
assert.Equal(t, address, cfg.MetricsServerAddress)
}
func TestMetricsServerDoesNotTouchExistingPortCommonConfig(t *testing.T) {
cfg := configOptionsWithMetricsServer{}
cfg.config = &common.Config{}
cfg.config.MetricsServerAddress = "localhost:1234"
address, err := cfg.metricsServerAddress()
assert.NoError(t, err)
assert.Equal(t, address, cfg.config.MetricsServerAddress)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment