-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for multiple hosts, default to no host (#110)
- Loading branch information
1 parent
cd48a2a
commit 0a859d4
Showing
6 changed files
with
98 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package local | ||
|
||
import ( | ||
"sort" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
networkingv1 "k8s.io/api/networking/v1" | ||
) | ||
|
||
func TestIngress(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
hosts []string | ||
expHosts []string | ||
}{ | ||
{ | ||
name: "nil hosts", | ||
hosts: nil, | ||
expHosts: []string{""}, | ||
}, | ||
{ | ||
name: "empty hosts", | ||
hosts: []string{}, | ||
expHosts: []string{""}, | ||
}, | ||
{ | ||
name: "single new host", | ||
hosts: []string{"example.test"}, | ||
expHosts: []string{"example.test", "localhost", "host.docker.internal"}, | ||
}, | ||
{ | ||
name: "localhost", | ||
hosts: []string{"localhost"}, | ||
expHosts: []string{"localhost", "host.docker.internal"}, | ||
}, | ||
{ | ||
name: "host.docker.internal", | ||
hosts: []string{"host.docker.internal"}, | ||
expHosts: []string{"localhost", "host.docker.internal"}, | ||
}, | ||
{ | ||
name: "multiple new hosts", | ||
hosts: []string{"abc.test", "xyz.test"}, | ||
expHosts: []string{"abc.test", "localhost", "host.docker.internal", "xyz.test"}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
actHosts := extractHosts(ingress(tt.hosts)) | ||
sort.Strings(actHosts) | ||
sort.Strings(tt.expHosts) | ||
if d := cmp.Diff(tt.expHosts, actHosts); d != "" { | ||
t.Errorf("unexpected hosts (-want, +got):\n%v", d) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
// extractHosts returns the host fields from the ingress rules. | ||
func extractHosts(ingress *networkingv1.Ingress) []string { | ||
var hosts []string | ||
for _, h := range ingress.Spec.Rules { | ||
hosts = append(hosts, h.Host) | ||
} | ||
return hosts | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters