Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve e2e tests #86

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 23 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,28 @@ 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).To(BeNil())
Expect(s).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))
})
})
})
Loading