Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Vala <mvala@redhat.com>
  • Loading branch information
sparkoo committed Sep 9, 2021
1 parent 906565e commit b86d5bf
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions controllers/devworkspace/solver/che_routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func relocatableDevWorkspaceRouting() *dwo.DevWorkspaceRouting {
},
{
Name: "e2",
TargetPort: 9999,
TargetPort: 9998,
Exposure: dw.PublicEndpointExposure,
Protocol: "http",
Path: "/2.js",
Expand All @@ -174,7 +174,7 @@ func relocatableDevWorkspaceRouting() *dwo.DevWorkspaceRouting {
},
{
Name: "e3",
TargetPort: 9999,
TargetPort: 9997,
Exposure: dw.PublicEndpointExposure,
Attributes: attributes.Attributes{
urlRewriteSupportedEndpointAttributeName: apiext.JSON{Raw: []byte("\"true\"")},
Expand Down Expand Up @@ -267,30 +267,40 @@ func TestCreateRelocatedObjects(t *testing.T) {
t.Fatal(err)
}

if len(workspaceConfig.HTTP.Routers) != 1 {
t.Fatalf("Expected exactly one traefik router but got %d", len(workspaceConfig.HTTP.Routers))
if len(workspaceConfig.HTTP.Routers) != 3 {
t.Fatalf("Expected 3 traefik routers but got %d", len(workspaceConfig.HTTP.Routers))
}

wsid := "wsid-m1-9999"
wsid := "wsid-m1-9999-e1"
if _, ok := workspaceConfig.HTTP.Routers[wsid]; !ok {
t.Fatal("traefik config doesn't contain expected workspace configuration")
}

if len(workspaceConfig.HTTP.Routers[wsid].Middlewares) != 3 {
if len(workspaceConfig.HTTP.Routers[wsid].Middlewares) != 2 {
t.Fatalf("Expected 3 middlewares in router but got '%d'", len(workspaceConfig.HTTP.Routers[wsid].Middlewares))
}

if len(workspaceConfig.HTTP.Middlewares) != 3 {
workspaceMainConfig := traefikConfig{}
if err := yaml.Unmarshal([]byte(traefikMainWorkspaceConfig), &workspaceMainConfig); err != nil {
t.Fatal(err)
}

if len(workspaceMainConfig.HTTP.Routers) != 1 {
t.Fatalf("Expected one route in main route config but got '%d'", len(workspaceMainConfig.HTTP.Routers))
}

if len(workspaceMainConfig.HTTP.Middlewares) != 3 {
t.Fatalf("Expected 3 middlewares set but got '%d'", len(workspaceConfig.HTTP.Middlewares))
}

wsid = "wsid"
mwares := []string{wsid + "-auth", wsid + "-prefix", wsid + "-header"}
for _, mware := range mwares {
if _, ok := workspaceConfig.HTTP.Middlewares[mware]; !ok {
if _, ok := workspaceMainConfig.HTTP.Middlewares[mware]; !ok {
t.Fatalf("traefik config doesn't set middleware '%s'", mware)
}
found := false
for _, r := range workspaceConfig.HTTP.Routers[wsid].Middlewares {
for _, r := range workspaceMainConfig.HTTP.Routers[wsid].Middlewares {
if r == mware {
found = true
}
Expand Down Expand Up @@ -347,10 +357,10 @@ func TestCreateSubDomainObjects(t *testing.T) {
t.Run("expectedIngresses", func(t *testing.T) {
objs := testCommon(infrastructure.Kubernetes)
if len(objs.Ingresses) != 1 {
t.Error()
t.Error("Expected 1 ingress, found ", len(objs.Ingresses))
}
if objs.Ingresses[0].Spec.Rules[0].Host != "wsid-1.down.on.earth" {
t.Error()
t.Error("Expected Ingress host 'wsid-1.down.on.earth', but got ", objs.Ingresses[0].Spec.Rules[0].Host)
}
})

Expand Down

0 comments on commit b86d5bf

Please sign in to comment.