Skip to content

Commit 85a5aee

Browse files
committed
Improve e2e tests
Signed-off-by: Ondra Machacek <[email protected]>
1 parent f8a55e9 commit 85a5aee

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

test/e2e/e2e_agent_test.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type PlannerAgent interface {
4242
type PlannerService interface {
4343
RemoveSources() error
4444
GetSource() (*api.Source, error)
45-
GetAgent() (*api.Agent, error)
45+
GetAgent(string) (*api.Agent, error)
4646
}
4747

4848
type plannerService struct {
@@ -259,7 +259,7 @@ func NewPlannerService(configPath string) (*plannerService, error) {
259259
return &plannerService{c: c}, nil
260260
}
261261

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

273-
return &(*res.JSON200)[0], nil
273+
agent := &(*res.JSON200)[0]
274+
if agent.CredentialUrl == fmt.Sprintf("http://%s:3333", agentIp) {
275+
return agent, nil
276+
}
277+
278+
return nil, fmt.Errorf("No agents found")
274279
}
275280

276281
func (s *plannerService) GetSource() (*api.Source, error) {

test/e2e/e2e_test.go

+23-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var _ = Describe("e2e", func() {
1616
svc PlannerService
1717
agent PlannerAgent
1818
agentIP string
19+
agentID string
1920
err error
2021
systemIP = os.Getenv("PLANNER_IP")
2122
)
@@ -40,16 +41,13 @@ var _ = Describe("e2e", func() {
4041
}, "3m", "2s").Should(BeTrue())
4142

4243
Eventually(func() string {
43-
s, err := svc.GetAgent()
44-
if err != nil {
44+
s, err := svc.GetAgent(agentIP)
45+
if err != nil || s == nil {
4546
return ""
4647
}
47-
if s.CredentialUrl != "N/A" && s.CredentialUrl != "" {
48-
return s.CredentialUrl
49-
}
50-
51-
return ""
52-
}, "3m", "2s").Should(Equal(fmt.Sprintf("http://%s:3333", agentIP)))
48+
agentID = s.Id
49+
return agentID
50+
}, "3m", "2s").ShouldNot(BeEmpty())
5351
})
5452

5553
AfterEach(func() {
@@ -72,12 +70,28 @@ var _ = Describe("e2e", func() {
7270
Expect(err).To(BeNil())
7371
Expect(res.StatusCode).To(Equal(http.StatusNoContent))
7472
Eventually(func() bool {
75-
apiAgent, err := svc.GetAgent()
73+
apiAgent, err := svc.GetAgent(agentIP)
7674
if err != nil {
7775
return false
7876
}
7977
return apiAgent.Status == v1alpha1.AgentStatusUpToDate
8078
}, "1m", "2s").Should(BeTrue())
79+
s, err := svc.GetSource()
80+
Expect(err).To(BeNil())
81+
Expect(s).ToNot(BeNil())
82+
Expect(s.Inventory).ToNot(BeNil())
83+
Expect(s.Inventory.Vcenter.Id).To(Equal(s.Id.String()))
84+
})
85+
It("version endpoint is not empty", func() {
86+
version, err := agent.Version()
87+
Expect(err).To(BeNil())
88+
Expect(version).ToNot(BeEmpty())
89+
})
90+
It("Return 422 in case of wrong URL", func() {
91+
// Put the vCenter credentials with wrong URL and check it return HTTP 422 error code
92+
res, err := agent.Login("this is not URL", "user", "pass")
93+
Expect(err).To(BeNil())
94+
Expect(res.StatusCode).To(Equal(http.StatusUnprocessableEntity))
8195
})
8296
})
8397
})

0 commit comments

Comments
 (0)