Skip to content

Commit

Permalink
adding required tests update
Browse files Browse the repository at this point in the history
  • Loading branch information
miledxz committed Feb 16, 2024
1 parent ba60c5d commit b36adc6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 107 deletions.
68 changes: 68 additions & 0 deletions internal/mode/static/nginx/runtime/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"context"
"errors"
"io/fs"
"net/http"
"testing"
"time"

"github.com/go-logr/logr"
"github.com/nginxinc/nginx-plus-go-client/client"
ngxclient "github.com/nginxinc/nginx-plus-go-client/client"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -21,6 +23,72 @@ var _ = Describe("NGINX Runtime Manager", func() {
mgr = NewManagerImpl(&ngxclient.NginxClient{}, nil, logr.New(GinkgoLogr.GetSink()))
Expect(mgr.IsPlus()).To(BeTrue())
})

Describe("ManagerImpl", Ordered, func() {
var (
mockedManager Manager
serverMocks []ngxclient.UpstreamServer
serversMock ngxclient.UpstreamServer

clientMock *ngxclient.NginxClient
)

var (
MaxConnsMock = 150
MaxFailsMock = 20
WeightMock = 10
BackupMock = false
DownMock = false
)

BeforeAll(func() {

serversMock = ngxclient.UpstreamServer{
ID: 1,
Server: "unknown",
MaxConns: &MaxConnsMock,
MaxFails: &MaxFailsMock,
FailTimeout: "test",
SlowStart: "test",
Route: "test",
Backup: &BackupMock,
Down: &DownMock,
Drain: false,
Weight: &WeightMock,
Service: "",
}

serverMocks = []ngxclient.UpstreamServer{
serversMock,
}

httpClient := &http.Client{
Transport: http.DefaultTransport,
CheckRedirect: http.DefaultClient.CheckRedirect,
Jar: http.DefaultClient.Jar,
Timeout: time.Second * 4,
}

clientMock, _ = ngxclient.NewNginxClient("test", client.WithHTTPClient(httpClient))
logrMock := logr.New(GinkgoLogr.GetSink())
mockedManager = NewManagerImpl(clientMock, nil, logrMock)

})

It("UpdateHTTPServers fails upon unknown HTTP server upstream", func() {
err := mockedManager.UpdateHTTPServers("unknown", serverMocks)
Expect(err).ToNot(BeNil())
})

Context("GetUpstreams returns empty map of upstreams", func() {
It("returns no upstreams from NGINX Plus API", func() {

upstreams, err := mockedManager.GetUpstreams()
Expect(err).To(HaveOccurred())
Expect(upstreams).To(BeEmpty())
})
})
})
})

func TestEnsureNginxRunning(t *testing.T) {
Expand Down
107 changes: 0 additions & 107 deletions internal/mode/static/nginx/runtime/runtime_manager_test.go

This file was deleted.

0 comments on commit b36adc6

Please sign in to comment.