mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Merge pull request #548 from kelseyhightower/improve_kubecfg_tests
Use table testing for makePort tests
This commit is contained in:
commit
7a8e268c0e
@ -20,6 +20,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
@ -287,19 +288,24 @@ func TestLoadAuthInfo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func validatePort(t *testing.T, p api.Port, external int, internal int) {
|
|
||||||
if p.HostPort != external || p.ContainerPort != internal {
|
|
||||||
t.Errorf("Unexpected port: %#v != (%d, %d)", p, external, internal)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMakePorts(t *testing.T) {
|
func TestMakePorts(t *testing.T) {
|
||||||
ports := makePorts("8080:80,8081:8081,443:444")
|
var makePortsTests = []struct {
|
||||||
if len(ports) != 3 {
|
spec string
|
||||||
t.Errorf("Unexpected ports: %#v", ports)
|
ports []api.Port
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"8080:80,8081:8081,443:444",
|
||||||
|
[]api.Port{
|
||||||
|
api.Port{HostPort: 8080, ContainerPort: 80},
|
||||||
|
api.Port{HostPort: 8081, ContainerPort: 8081},
|
||||||
|
api.Port{HostPort: 443, ContainerPort: 444},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range makePortsTests {
|
||||||
|
ports := makePorts(tt.spec)
|
||||||
|
if !reflect.DeepEqual(ports, tt.ports) {
|
||||||
|
t.Errorf("Expected %#v, got %#v", tt.ports, ports)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
validatePort(t, ports[0], 8080, 80)
|
|
||||||
validatePort(t, ports[1], 8081, 8081)
|
|
||||||
validatePort(t, ports[2], 443, 444)
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user