Skip to content

Commit

Permalink
fixup! add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aslafy-z committed Nov 9, 2024
1 parent 75f96f0 commit 5249575
Showing 1 changed file with 78 additions and 6 deletions.
84 changes: 78 additions & 6 deletions pkg/kube/wrappers/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,20 @@ func TestIngressWrapper_GetURL(t *testing.T) {
},
want: "",
},
{
name: "IngressWithStatusHostnameHostButNoHostNorTLSHost",
fields: fields{
ingress: testutil.CreateIngressWithStatusHostnameHost("someIngress2", "google.com"),

Check failure on line 205 in pkg/kube/wrappers/ingress_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: testutil.CreateIngressWithStatusHostnameHost
},
want: "http://google.com",
},
{
name: "IngressWithStatusIPHostButNoHostNorTLSHost",
fields: fields{
ingress: testutil.CreateIngressWithStatusHostnameHost("someIngress2", "1.1.1.1"),

Check failure on line 212 in pkg/kube/wrappers/ingress_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: testutil.CreateIngressWithStatusHostnameHost
},
want: "http://1.1.1.1",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -271,7 +285,7 @@ func TestIngressWrapper_tryGetTLSHost(t *testing.T) {
fields: fields{
ingress: testutil.CreateIngressWithHostAndTLSHost("someIngress", "google.com", "google.com"),
},
want: "https://google.com",
want: "google.com",
want1: true,
},
{
Expand Down Expand Up @@ -335,37 +349,95 @@ func TestIngressWrapper_supportsTLS(t *testing.T) {
}
}

func TestIngressWrapper_getHost(t *testing.T) {
func TestIngressWrapper_tryGetRuleHost(t *testing.T) {
type fields struct {
ingress *v1.Ingress
}
tests := []struct {
name string
fields fields
want string
want1 bool
}{
{
name: "IngressWithEmptyHost",
fields: fields{
ingress: testutil.CreateIngressWithHost("someIngress", ""),
},
want: "http://",
want: "",
want1: false,
},
{
name: "IngressWithCorrectHost",
fields: fields{
ingress: testutil.CreateIngressWithHost("someIngress", "google.com"),
},
want: "http://google.com",
want: "google.com",
want1: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
iw := &IngressWrapper{
ingress: tt.fields.ingress,
}
if got := iw.getHost(); got != tt.want {
t.Errorf("IngressWrapper.getHost() = %v, want %v", got, tt.want)
got, got1 := iw.tryGetRuleHost()
if got != tt.want {
t.Errorf("IngressWrapper.tryGetRuleHost() got = %v, want %v", got, tt.want)
}
if got1 != tt.want1 {
t.Errorf("IngressWrapper.tryGetRuleHost() got1 = %v, want %v", got1, tt.want1)
}
})
}
}

func TestIngressWrapper_tryGetStatusHost(t *testing.T) {
type fields struct {
ingress *v1.Ingress
}
tests := []struct {
name string
fields fields
want string
want1 bool
}{
{
name: "IngressWithEmptyStatusHost",
fields: fields{
ingress: testutil.CreateIngressWithHost("someIngress", ""),
},
want: "",
want1: false,
},
{
name: "IngressWithCorrectHostnameStatusHost",
fields: fields{
ingress: testutil.CreateIngressWithStatusHostnameHost("someIngress", "google.com"),

Check failure on line 416 in pkg/kube/wrappers/ingress_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: testutil.CreateIngressWithStatusHostnameHost
},
want: "google.com",
want1: true,
},
{
name: "IngressWithCorrectIPStatusHost",
fields: fields{
ingress: testutil.CreateIngressWithStatusIPHost("someIngress", "1.1.1.1"),

Check failure on line 424 in pkg/kube/wrappers/ingress_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: testutil.CreateIngressWithStatusIPHost (typecheck)
},
want: "1.1.1.1",
want1: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
iw := &IngressWrapper{
ingress: tt.fields.ingress,
}
got, got1 := iw.tryGetStatusHost()
if got != tt.want {
t.Errorf("IngressWrapper.tryGetStatusHost() got = %v, want %v", got, tt.want)
}
if got1 != tt.want1 {
t.Errorf("IngressWrapper.tryGetStatusHost() got1 = %v, want %v", got1, tt.want1)
}
})
}
Expand Down

0 comments on commit 5249575

Please sign in to comment.