Skip to content

Commit

Permalink
simplify ut for dag
Browse files Browse the repository at this point in the history
Signed-off-by: gang.liu <[email protected]>
  • Loading branch information
izturn authored and sunjayBhatia committed Aug 4, 2023
1 parent 984e42b commit 8dcc1e6
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 310 deletions.
62 changes: 18 additions & 44 deletions internal/dag/accessors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,26 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
)

func makeServicePort(name string, protocol v1.Protocol, port int32, extras ...int) v1.ServicePort {
p := v1.ServicePort{
Name: name,
Protocol: protocol,
Port: port,
}
if len(extras) != 0 {
p.TargetPort = intstr.FromInt(extras[0])
}
return p

}
func TestBuilderLookupService(t *testing.T) {
s1 := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "kuard",
Namespace: "default",
},
Spec: v1.ServiceSpec{
Ports: []v1.ServicePort{{
Name: "http",
Protocol: "TCP",
Port: 8080,
TargetPort: intstr.FromInt(8080),
}},
Ports: []v1.ServicePort{makeServicePort("http", "TCP", 8080, 8080)},
},
}

Expand All @@ -47,20 +54,7 @@ func TestBuilderLookupService(t *testing.T) {
Namespace: "default",
},
Spec: v1.ServiceSpec{
Ports: []v1.ServicePort{
{
Name: "http",
Protocol: "TCP",
Port: 8080,
TargetPort: intstr.FromInt(8080),
},
{
Name: "health",
Protocol: "TCP",
Port: 8998,
TargetPort: intstr.FromInt(8998),
},
},
Ports: []v1.ServicePort{makeServicePort("http", "TCP", 8080, 8080), makeServicePort("health", "TCP", 8998, 8998)},
},
}

Expand All @@ -72,12 +66,7 @@ func TestBuilderLookupService(t *testing.T) {
Spec: v1.ServiceSpec{
Type: v1.ServiceTypeExternalName,
ExternalName: "external.projectcontour.io",
Ports: []v1.ServicePort{{
Name: "http",
Protocol: "TCP",
Port: 80,
TargetPort: intstr.FromInt(80),
}},
Ports: []v1.ServicePort{makeServicePort("http", "TCP", 80, 80)},
},
}

Expand All @@ -89,12 +78,7 @@ func TestBuilderLookupService(t *testing.T) {
Spec: v1.ServiceSpec{
Type: v1.ServiceTypeExternalName,
ExternalName: "localhost",
Ports: []v1.ServicePort{{
Name: "http",
Protocol: "TCP",
Port: 80,
TargetPort: intstr.FromInt(80),
}},
Ports: []v1.ServicePort{makeServicePort("http", "TCP", 80, 80)},
},
}

Expand Down Expand Up @@ -149,18 +133,8 @@ func TestBuilderLookupService(t *testing.T) {
Weight: 1,
ServiceName: "externalnamevalid",
ServiceNamespace: "default",
ServicePort: v1.ServicePort{
Name: "http",
Protocol: "TCP",
Port: 80,
TargetPort: intstr.FromInt(80),
},
HealthPort: v1.ServicePort{
Name: "http",
Protocol: "TCP",
Port: 80,
TargetPort: intstr.FromInt(80),
},
ServicePort: makeServicePort("http", "TCP", 80, 80),
HealthPort: makeServicePort("http", "TCP", 80, 80),
},
ExternalName: "external.projectcontour.io",
},
Expand Down
Loading

0 comments on commit 8dcc1e6

Please sign in to comment.