Skip to content

Commit

Permalink
use env var in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xaniasd authored and seldondev committed May 13, 2020
1 parent 9b43124 commit a98a323
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package v1

import (
"os"
"testing"

. "github.com/onsi/gomega"
Expand Down Expand Up @@ -210,7 +209,7 @@ func TestDefaultSingleContainer(t *testing.T) {
spec.DefaultSeldonDeployment("mydep", "default")

// Test Metric Ports
metricPort := GetPort(constants.DefaultMetricsPortName, spec.Predictors[0].ComponentSpecs[0].Spec.Containers[0].Ports)
metricPort := GetPort(envPredictiveUnitMetricsPortName, spec.Predictors[0].ComponentSpecs[0].Spec.Containers[0].Ports)
g.Expect(metricPort).NotTo(BeNil())
g.Expect(metricPort.ContainerPort).To(Equal(constants.FirstMetricsPortNumber))

Expand Down Expand Up @@ -267,11 +266,11 @@ func TestMetricsPortAddedTwoContainers(t *testing.T) {

//Metrics
spec.DefaultSeldonDeployment("mydep", "default")
metricPort := GetPort(constants.DefaultMetricsPortName, spec.Predictors[0].ComponentSpecs[0].Spec.Containers[0].Ports)
metricPort := GetPort(envPredictiveUnitMetricsPortName, spec.Predictors[0].ComponentSpecs[0].Spec.Containers[0].Ports)
g.Expect(metricPort).NotTo(BeNil())
g.Expect(metricPort.ContainerPort).To(Equal(constants.FirstMetricsPortNumber))

metricPort = GetPort(constants.DefaultMetricsPortName, spec.Predictors[0].ComponentSpecs[0].Spec.Containers[1].Ports)
metricPort = GetPort(envPredictiveUnitMetricsPortName, spec.Predictors[0].ComponentSpecs[0].Spec.Containers[1].Ports)
g.Expect(metricPort).NotTo(BeNil())
g.Expect(metricPort.ContainerPort).To(Equal(constants.FirstMetricsPortNumber + 1))

Expand Down Expand Up @@ -351,10 +350,10 @@ func TestMetricsPortAddedTwoComponentSpecsTwoContainers(t *testing.T) {
spec.DefaultSeldonDeployment(name, namespace)

// Metrics
metricPort := GetPort(constants.DefaultMetricsPortName, spec.Predictors[0].ComponentSpecs[0].Spec.Containers[0].Ports)
metricPort := GetPort(envPredictiveUnitMetricsPortName, spec.Predictors[0].ComponentSpecs[0].Spec.Containers[0].Ports)
g.Expect(metricPort).NotTo(BeNil())
g.Expect(metricPort.ContainerPort).To(Equal(constants.FirstMetricsPortNumber))
metricPort = GetPort(constants.DefaultMetricsPortName, spec.Predictors[0].ComponentSpecs[1].Spec.Containers[0].Ports)
metricPort = GetPort(envPredictiveUnitMetricsPortName, spec.Predictors[0].ComponentSpecs[1].Spec.Containers[0].Ports)
g.Expect(metricPort).NotTo(BeNil())
g.Expect(metricPort.ContainerPort).To(Equal(constants.FirstMetricsPortNumber + 1))

Expand Down Expand Up @@ -392,8 +391,6 @@ func TestMetricsPortAddedTwoComponentSpecsTwoContainers(t *testing.T) {
}

func TestOverrideMetricsPortName(t *testing.T) {
os.Setenv(ENV_PREDICTIVE_UNIT_METRICS_PORT_NAME, "myMetricsPort")
defer os.Unsetenv(ENV_PREDICTIVE_UNIT_METRICS_PORT_NAME)
g := NewGomegaWithT(t)
scheme := runtime.NewScheme()
C = fake.NewFakeClientWithScheme(scheme)
Expand All @@ -410,11 +407,12 @@ func TestOverrideMetricsPortName(t *testing.T) {
},
}

envPredictiveUnitMetricsPortName = "myMetricsPort"
spec.DefaultSeldonDeployment("mydep", "default")
// Metrics
metricPort := GetPort("myMetricsPort", spec.Predictors[0].ComponentSpecs[0].Spec.Containers[0].Ports)
g.Expect(metricPort).NotTo(BeNil())
g.Expect(metricPort.ContainerPort).To(Equal(constants.FirstMetricsPortNumber))
customMetricsPort := GetPort("myMetricsPort", spec.Predictors[0].ComponentSpecs[0].Spec.Containers[0].Ports)
g.Expect(customMetricsPort).NotTo(BeNil())
g.Expect(customMetricsPort.ContainerPort).To(Equal(constants.FirstMetricsPortNumber))

defaultMetricsPort := GetPort(constants.DefaultMetricsPortName, spec.Predictors[0].ComponentSpecs[0].Spec.Containers[0].Ports)
g.Expect(defaultMetricsPort).To(BeNil())
Expand Down Expand Up @@ -456,7 +454,7 @@ func TestPortUseExisting(t *testing.T) {
}

spec.DefaultSeldonDeployment("mydep", "default")
metricPort := GetPort(constants.DefaultMetricsPortName, spec.Predictors[0].ComponentSpecs[0].Spec.Containers[0].Ports)
metricPort := GetPort(envPredictiveUnitMetricsPortName, spec.Predictors[0].ComponentSpecs[0].Spec.Containers[0].Ports)
g.Expect(metricPort).NotTo(BeNil())
g.Expect(metricPort.ContainerPort).To(Equal(containerPortMetrics))

Expand Down

0 comments on commit a98a323

Please sign in to comment.