Skip to content

Commit

Permalink
Improve e2e tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ondra Machacek <[email protected]>
  • Loading branch information
machacekondra committed Nov 28, 2024
1 parent f8a55e9 commit ea25363
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
11 changes: 8 additions & 3 deletions test/e2e/e2e_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type PlannerAgent interface {
type PlannerService interface {
RemoveSources() error
GetSource() (*api.Source, error)
GetAgent() (*api.Agent, error)
GetAgent(string) (*api.Agent, error)
}

type plannerService struct {
Expand Down Expand Up @@ -259,7 +259,7 @@ func NewPlannerService(configPath string) (*plannerService, error) {
return &plannerService{c: c}, nil
}

func (s *plannerService) GetAgent() (*api.Agent, error) {
func (s *plannerService) GetAgent(agentIp string) (*api.Agent, error) {
ctx := context.TODO()
res, err := s.c.ListAgentsWithResponse(ctx)
if err != nil || res.HTTPResponse.StatusCode != 200 {
Expand All @@ -270,7 +270,12 @@ func (s *plannerService) GetAgent() (*api.Agent, error) {
return nil, fmt.Errorf("No agents found")
}

return &(*res.JSON200)[0], nil
agent := &(*res.JSON200)[0]
if agent.CredentialUrl == fmt.Sprintf("http://%s:3333", agentIp) {
return agent, nil
}

return nil, fmt.Errorf("No agents found")
}

func (s *plannerService) GetSource() (*api.Source, error) {
Expand Down
31 changes: 22 additions & 9 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var _ = Describe("e2e", func() {
svc PlannerService
agent PlannerAgent
agentIP string
agentID string
err error
systemIP = os.Getenv("PLANNER_IP")
)
Expand All @@ -40,16 +41,13 @@ var _ = Describe("e2e", func() {
}, "3m", "2s").Should(BeTrue())

Eventually(func() string {
s, err := svc.GetAgent()
if err != nil {
s, err := svc.GetAgent(agentIP)
if err != nil || s == nil {
return ""
}
if s.CredentialUrl != "N/A" && s.CredentialUrl != "" {
return s.CredentialUrl
}

return ""
}, "3m", "2s").Should(Equal(fmt.Sprintf("http://%s:3333", agentIP)))
agentID = s.Id
return agentID
}, "3m", "2s").ShouldNot(BeEmpty())
})

AfterEach(func() {
Expand All @@ -72,12 +70,27 @@ var _ = Describe("e2e", func() {
Expect(err).To(BeNil())
Expect(res.StatusCode).To(Equal(http.StatusNoContent))
Eventually(func() bool {
apiAgent, err := svc.GetAgent()
apiAgent, err := svc.GetAgent(agentIP)
if err != nil {
return false
}
return apiAgent.Status == v1alpha1.AgentStatusUpToDate
}, "1m", "2s").Should(BeTrue())
s, err := svc.GetSource()
Expect(err).ToNot(BeNil())
Expect(s.Inventory).ToNot(BeNil())
Expect(s.Inventory.Vcenter.Id).To(Equal(s.Id.String()))
})
It("version endpoint is not empty", func() {
version, err := agent.Version()
Expect(err).To(BeNil())
Expect(version).ToNot(BeEmpty())
})
It("Return 422 in case of wrong URL", func() {
// Put the vCenter credentials with wrong URL and check it return HTTP 422 error code
res, err := agent.Login("this is not URL", "user", "pass")
Expect(err).To(BeNil())
Expect(res.StatusCode).To(Equal(http.StatusUnprocessableEntity))
})
})
})

0 comments on commit ea25363

Please sign in to comment.