Skip to content

Commit

Permalink
store/sources: Add missing agents list to source model
Browse files Browse the repository at this point in the history
Fix bug when associated agents are not shown in the api response.

Signed-off-by: Cosmin Tupangiu <[email protected]>
  • Loading branch information
tupyy authored and machacekondra committed Jan 7, 2025
1 parent f758631 commit 7953ba0
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 77 deletions.
45 changes: 22 additions & 23 deletions api/v1alpha1/agent/spec.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions api/v1alpha1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ components:
updatedAt:
type: string
format: date-time
name:
type: string
agents:
type: array
items:
Expand Down
62 changes: 31 additions & 31 deletions api/v1alpha1/spec.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 6 additions & 21 deletions api/v1alpha1/types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/cli/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ func printTable(response interface{}, kind string, id *uuid.UUID) error {
}

func printSourcesTable(w *tabwriter.Writer, sources ...api.Source) {
fmt.Fprintln(w, "ID\tNAME\tSTATUS")
fmt.Fprintln(w, "ID")
for _, s := range sources {
fmt.Fprintf(w, "%s\t%s\t%s\n", s.Id, s.Name, s.Status)
fmt.Fprintf(w, "%s\n", s.Id)
}
}
19 changes: 19 additions & 0 deletions internal/store/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,32 @@ var _ = Describe("source store", Ordered, func() {
Expect(sources).To(HaveLen(2))
})

It("successfully list all the sources -- with agents", func() {
sourceID := uuid.NewString()
agentID := uuid.NewString()
tx := gormdb.Exec(fmt.Sprintf(insertAgentStm, agentID, "not-connected", "status-info-1", "cred_url-1"))
Expect(tx.Error).To(BeNil())
tx = gormdb.Exec(fmt.Sprintf(insertSourceStm, sourceID))
Expect(tx.Error).To(BeNil())
tx = gormdb.Exec(fmt.Sprintf("UPDATE agents set source_id = '%s';", sourceID))
Expect(tx.Error).To(BeNil())

sources, err := s.Source().List(context.TODO())
Expect(err).To(BeNil())
Expect(sources).To(HaveLen(1))
agents := *sources[0].Agents
Expect(agents).To(HaveLen(1))
Expect(agents[0].Id.String()).To(Equal(agentID))
})

It("list all sources -- no sources", func() {
sources, err := s.Source().List(context.TODO())
Expect(err).To(BeNil())
Expect(sources).To(HaveLen(0))
})

AfterEach(func() {
gormdb.Exec("DELETE from agents;")
gormdb.Exec("DELETE from sources;")
})
})
Expand Down

0 comments on commit 7953ba0

Please sign in to comment.