Skip to content

Commit 476a1b3

Browse files
committed
updating unit tests
1 parent 9d36799 commit 476a1b3

File tree

1 file changed

+45
-6
lines changed

1 file changed

+45
-6
lines changed

netmaster/objApi/objapi_test.go

+45-6
Original file line numberDiff line numberDiff line change
@@ -721,11 +721,14 @@ func TestServiceProviderUpdate(t *testing.T) {
721721
verifyServiceCreate(t, "default", "yellow", "redis", port, labels, "")
722722

723723
containerID := "723e55bf5b244f47c1b184cb786a1c2ad8870cc3a3db723c49ac09f68a9d1e69"
724+
container := "657355bf5b244f47c1b184cb786a14535d8870cc3a3db723c49ac09f68a9d6a5"
724725

725-
triggerProviderUpdate(t, "20.1.1.1", "orange", containerID, "default", "start", labels)
726+
createEP(t, "20.1.1.1", "orange", containerID, "default", container, labels)
727+
triggerProviderUpdate(t, "20.1.1.1", "orange", containerID, container, "default", "start", labels)
726728
verifyProviderUpdate(t, "20.1.1.1", "orange", containerID, "default", "start", "redis", labels)
727-
triggerProviderUpdate(t, "20.1.1.1", "orange", containerID, "default", "die", labels)
729+
triggerProviderUpdate(t, "20.1.1.1", "orange", containerID, container, "default", "die", labels)
728730
verifyProviderUpdate(t, "20.1.1.1", "orange", containerID, "default", "die", "redis", labels)
731+
deleteEP(t, "orange", "default", container)
729732
checkServiceDelete(t, "default", "redis")
730733
verifyServiceDelete(t, "default", "redis")
731734
deleteNetwork(t, "orange", "default")
@@ -738,17 +741,19 @@ func TestServiceProviderUpdateServiceAdd(t *testing.T) {
738741
port := []string{"80:8080:TCP"}
739742

740743
containerID := "723e55bf5b244f47c1b184cb786a1c2ad8870cc3a3db723c49ac09f68a9d1e69"
744+
container := "657355bf5b244f47c1b184cb786a14535d8870cc3a3db723c49ac09f68a9d6a5"
741745

742746
createNetwork(t, "orange", "default", "vxlan", "11.1.1.0/24", "11.1.1.254")
743-
triggerProviderUpdate(t, "20.1.1.1", "orange", containerID, "default", "start", labels)
744-
747+
createEP(t, "20.1.1.1", "orange", containerID, "default", container, labels)
748+
triggerProviderUpdate(t, "20.1.1.1", "orange", containerID, container, "default", "start", labels)
745749
createNetwork(t, "yellow", "default", "vxlan", "10.1.1.0/24", "10.1.1.254")
746750
checkServiceCreate(t, "default", "yellow", "redis", port, labels, "")
747751
verifyServiceCreate(t, "default", "yellow", "redis", port, labels, "")
748752

749753
verifyProviderUpdate(t, "20.1.1.1", "orange", containerID, "default", "start", "redis", labels)
750-
triggerProviderUpdate(t, "20.1.1.1", "orange", containerID, "default", "die", labels)
754+
triggerProviderUpdate(t, "20.1.1.1", "orange", containerID, container, "default", "die", labels)
751755
verifyProviderUpdate(t, "20.1.1.1", "orange", containerID, "default", "die", "redis", labels)
756+
deleteEP(t, "orange", "default", container)
752757
checkServiceDelete(t, "default", "redis")
753758
verifyServiceDelete(t, "default", "redis")
754759
deleteNetwork(t, "orange", "default")
@@ -842,7 +847,7 @@ func verifyServiceDelete(t *testing.T, tenant, serviceName string) {
842847
}
843848
}
844849

845-
func triggerProviderUpdate(t *testing.T, providerIP, network, containerID,
850+
func triggerProviderUpdate(t *testing.T, providerIP, network, containerID, container,
846851
tenant, event string, labels []string) {
847852

848853
providerUpdReq := master.SvcProvUpdateRequest{}
@@ -852,6 +857,7 @@ func triggerProviderUpdate(t *testing.T, providerIP, network, containerID,
852857
providerUpdReq.Network = network
853858
providerUpdReq.Event = event
854859
providerUpdReq.Labels = make(map[string]string)
860+
providerUpdReq.Container = container
855861

856862
for _, v := range labels {
857863
key := strings.Split(v, "=")[0]
@@ -995,4 +1001,37 @@ func get(getAll bool, hook func(id string) ([]core.State, error)) func(http.Resp
9951001
}
9961002
}
9971003

1004+
func createEP(t *testing.T, providerIP, network, containerID, tenant, container string, labels []string) {
1005+
1006+
epCfg := &mastercfg.CfgEndpointState{
1007+
NetID: network,
1008+
ContName: containerID,
1009+
AttachUUID: container,
1010+
IPAddress: providerIP,
1011+
}
1012+
epCfg.Labels = make(map[string]string)
1013+
for _, v := range labels {
1014+
key := strings.Split(v, "=")[0]
1015+
value := strings.Split(v, "=")[1]
1016+
epCfg.Labels[key] = value
1017+
}
1018+
epCfg.StateDriver = stateStore
1019+
netID := network + "." + tenant
1020+
epCfg.ID = netID + "-" + container
1021+
err := epCfg.Write()
1022+
if err != nil {
1023+
t.Errorf("Error creating Ep :%s", err)
1024+
}
1025+
}
1026+
func deleteEP(t *testing.T, network, tenant, container string) {
1027+
epCfg := &mastercfg.CfgEndpointState{}
1028+
epCfg.StateDriver = stateStore
1029+
netID := network + "." + tenant
1030+
epCfg.ID = netID + "-" + container
1031+
err := epCfg.Clear()
1032+
if err != nil {
1033+
t.Errorf("Error deleting Ep :%s", err)
1034+
}
1035+
}
1036+
9981037
type httpAPIFunc func(w http.ResponseWriter, r *http.Request, vars map[string]string) (interface{}, error)

0 commit comments

Comments
 (0)