This commit is contained in:
Andrew Davidoff 2023-04-24 19:17:20 +00:00 committed by Andrew Davidoff
parent f4eaef7e85
commit 0e259ab81f

View file

@ -17,21 +17,21 @@ limitations under the License.
package annotations package annotations
import ( import (
"net/http" "net/http"
"strings" "strings"
"github.com/onsi/ginkgo/v2" "github.com/onsi/ginkgo/v2"
"github.com/stretchr/testify/assert"
"k8s.io/ingress-nginx/test/e2e/framework" "k8s.io/ingress-nginx/test/e2e/framework"
"github.com/stretchr/testify/assert"
) )
var _ = framework.DescribeAnnotation("skip-access-log-http-statuses", func() { var _ = framework.DescribeAnnotation("skip-access-log-http-statuses", func() {
f := framework.NewDefaultFramework("skipaccessloghttpstatuses") f := framework.NewDefaultFramework("skipaccessloghttpstatuses")
ginkgo.BeforeEach(func() { ginkgo.BeforeEach(func() {
f.NewEchoDeployment() f.NewEchoDeployment()
}) })
ginkgo.It("skip-access-log-http-statuses 200 literal, 200 OK", func() { ginkgo.It("skip-access-log-http-statuses 200 literal, 200 OK", func() {
host := "skipaccessloghttpstatuses.go.foo.com" host := "skipaccessloghttpstatuses.go.foo.com"
@ -44,15 +44,15 @@ var _ = framework.DescribeAnnotation("skip-access-log-http-statuses", func() {
return strings.Contains(ngx, `~200 0;`) return strings.Contains(ngx, `~200 0;`)
}) })
f.HTTPTestClient(). f.HTTPTestClient().
GET("/prefixOne"). GET("/prefixOne").
WithHeader("Host", host). WithHeader("Host", host).
Expect(). Expect().
Status(http.StatusOK) Status(http.StatusOK)
logs, err := f.NginxLogs() logs, err := f.NginxLogs()
assert.Nil(ginkgo.GinkgoT(), err, "obtaining nginx logs") assert.Nil(ginkgo.GinkgoT(), err, "obtaining nginx logs")
assert.NotContains(ginkgo.GinkgoT(), logs, `GET / HTTP/1.1" 200`) assert.NotContains(ginkgo.GinkgoT(), logs, `GET / HTTP/1.1" 200`)
}) })
ginkgo.It("skip-access-log-http-statuses ^2.. regex, 200 OK", func() { ginkgo.It("skip-access-log-http-statuses ^2.. regex, 200 OK", func() {
@ -66,15 +66,15 @@ var _ = framework.DescribeAnnotation("skip-access-log-http-statuses", func() {
return strings.Contains(ngx, `~^2.. 0;`) return strings.Contains(ngx, `~^2.. 0;`)
}) })
f.HTTPTestClient(). f.HTTPTestClient().
GET("/prefixOne"). GET("/prefixOne").
WithHeader("Host", host). WithHeader("Host", host).
Expect(). Expect().
Status(http.StatusOK) Status(http.StatusOK)
logs, err := f.NginxLogs() logs, err := f.NginxLogs()
assert.Nil(ginkgo.GinkgoT(), err, "obtaining nginx logs") assert.Nil(ginkgo.GinkgoT(), err, "obtaining nginx logs")
assert.NotContains(ginkgo.GinkgoT(), logs, `GET / HTTP/1.1" 200`) assert.NotContains(ginkgo.GinkgoT(), logs, `GET / HTTP/1.1" 200`)
}) })
ginkgo.It("skip-access-log-http-statuses ^2.. regex, 404 Not Found", func() { ginkgo.It("skip-access-log-http-statuses ^2.. regex, 404 Not Found", func() {
@ -88,14 +88,14 @@ var _ = framework.DescribeAnnotation("skip-access-log-http-statuses", func() {
return strings.Contains(ngx, `~^2.. 0;`) return strings.Contains(ngx, `~^2.. 0;`)
}) })
f.HTTPTestClient(). f.HTTPTestClient().
GET("/404"). GET("/404").
WithHeader("Host", host). WithHeader("Host", host).
Expect(). Expect().
Status(http.StatusNotFound) Status(http.StatusNotFound)
logs, err := f.NginxLogs() logs, err := f.NginxLogs()
assert.Nil(ginkgo.GinkgoT(), err, "obtaining nginx logs") assert.Nil(ginkgo.GinkgoT(), err, "obtaining nginx logs")
assert.Contains(ginkgo.GinkgoT(), logs, `GET /404 HTTP/1.1" 404`) assert.Contains(ginkgo.GinkgoT(), logs, `GET /404 HTTP/1.1" 404`)
}) })
}) })