Skip to content

Commit

Permalink
add unit tests and e2e tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kuromesi <[email protected]>
  • Loading branch information
Kuromesi committed Aug 24, 2023
1 parent 03c792b commit 9d40b60
Show file tree
Hide file tree
Showing 15 changed files with 553 additions and 11 deletions.
2 changes: 1 addition & 1 deletion config/crd/bases/rollouts.kruise.io_rollouts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ spec:
traffic routing
properties:
createCanaryService:
default: false
default: true
description: create a new canary service or just use
the stable service
type: boolean
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/rollouts.kruise.io_trafficroutings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ spec:
routing
properties:
createCanaryService:
default: false
default: true
description: create a new canary service or just use the stable
service
type: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ var (
Spec: v1alpha1.TrafficRoutingSpec{
ObjectRef: []v1alpha1.TrafficRoutingRef{
{
Service: "echoserver",
Service: "echoserver",
CreateCanaryService: false,
Ingress: &v1alpha1.IngressTrafficRouting{
Name: "echoserver",
},
Expand Down Expand Up @@ -379,6 +380,7 @@ func TestTrafficRoutingTest(t *testing.T) {
for _, obj := range ig {
checkObjEqual(client, t, obj)
}
manager.trafficRoutingManager.RemoveTrafficRoutingController(newTrafficRoutingContext(tr))
})
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/trafficrouting/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ func TestFinalisingTrafficRouting(t *testing.T) {
}
manager := NewTrafficRoutingManager(client)
done, err := manager.FinalisingTrafficRouting(c, cs.onlyRestoreStableService)
manager.RemoveTrafficRoutingController(c)
if err != nil {
t.Fatalf("DoTrafficRouting failed: %s", err)
}
Expand Down
12 changes: 4 additions & 8 deletions pkg/trafficrouting/network/custom/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,8 @@ func (r *customController) storeObject(obj *unstructured.Unstructured) error {
}
annotations[OriginalSpecAnnotation] = cSpec
obj.SetAnnotations(annotations)
if err := r.Update(context.TODO(), obj); err != nil {
return err
}
return nil
err := r.Update(context.TODO(), obj)
return err

Check warning on line 192 in pkg/trafficrouting/network/custom/custom.go

View check run for this annotation

Codecov / codecov/patch

pkg/trafficrouting/network/custom/custom.go#L189-L192

Added lines #L189 - L192 were not covered by tests
}

// restore an object from spec stored in OriginalSpecAnnotation
Expand All @@ -206,10 +204,8 @@ func (r *customController) restoreObject(obj *unstructured.Unstructured) error {
obj.Object["spec"] = oSpec.Spec
obj.SetAnnotations(oSpec.Annotations)
obj.SetLabels(oSpec.Labels)
if err := r.Update(context.TODO(), obj); err != nil {
return err
}
return nil
err := r.Update(context.TODO(), obj)
return err

Check warning on line 208 in pkg/trafficrouting/network/custom/custom.go

View check run for this annotation

Codecov / codecov/patch

pkg/trafficrouting/network/custom/custom.go#L201-L208

Added lines #L201 - L208 were not covered by tests
}

func (r *customController) executeLuaForCanary(spec Data, strategy *rolloutv1alpha1.TrafficRoutingStrategy, luaScript string) (Data, error) {
Expand Down
Loading

0 comments on commit 9d40b60

Please sign in to comment.