Skip to content

Commit

Permalink
frontend: Add Groups stories and interface docs
Browse files Browse the repository at this point in the history
- Named files after component (GroupItem.tsx not Item.tsx)
- Separated some components into their own files

backend:
- version_breakdown was returning null instead of [] when empty
  • Loading branch information
illume committed May 10, 2022
1 parent 7249e6e commit 058947b
Show file tree
Hide file tree
Showing 28 changed files with 1,853 additions and 682 deletions.
20 changes: 20 additions & 0 deletions backend/pkg/api/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,26 @@ func TestGetGroupsFiltered(t *testing.T) {
}
}

func TestVersionBreakDownEmpty(t *testing.T) {
a := newForTest(t)
defer a.Close()

tTeam, _ := a.AddTeam(&Team{Name: "test_team"})
tApp, _ := a.AddApp(&Application{Name: "test_app", TeamID: tTeam.ID})
tPkg, _ := a.AddPackage(&Package{Type: PkgTypeOther, URL: "http://sample.url/pkg", Version: "12.1.0", ApplicationID: tApp.ID})
tChannel, _ := a.AddChannel(&Channel{Name: "test_channel", Color: "blue", ApplicationID: tApp.ID, PackageID: null.StringFrom(tPkg.ID)})
_, err := a.AddGroup(&Group{Name: "test_group1", ApplicationID: tApp.ID, ChannelID: null.StringFrom(tChannel.ID), PolicyUpdatesEnabled: true, PolicySafeMode: true, PolicyPeriodInterval: "15 minutes", PolicyMaxUpdatesPerPeriod: 2, PolicyUpdateTimeout: "60 minutes"})
assert.NoError(t, err)

groups, err := a.GetGroups(tApp.ID, 0, 0)
assert.NoError(t, err)
g := groups[0]

versionBreakdown, vbErr := a.GetGroupVersionBreakdown(g.ID)
assert.NoError(t, vbErr)
assert.Len(t, versionBreakdown, 0)
}

func TestGetVersionCountTimeline(t *testing.T) {
a := newForTest(t)
defer a.Close()
Expand Down
5 changes: 5 additions & 0 deletions backend/pkg/handler/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func (h *Handler) GetGroupInstanceStats(ctx echo.Context, appID string, groupID

func (h *Handler) GetGroupVersionBreakdown(ctx echo.Context, appID string, groupID string) error {
versionBreakdown, err := h.db.GetGroupVersionBreakdown(groupID)

if err != nil {
if err == sql.ErrNoRows {
return ctx.NoContent(http.StatusNotFound)
Expand All @@ -196,6 +197,10 @@ func (h *Handler) GetGroupVersionBreakdown(ctx echo.Context, appID string, group
return ctx.NoContent(http.StatusInternalServerError)
}

if len(versionBreakdown) == 0 {
// WAT?: because otherwise it serializes to null not []
return ctx.JSON(http.StatusOK, []string{})
}
return ctx.JSON(http.StatusOK, versionBreakdown)
}

Expand Down
5 changes: 3 additions & 2 deletions backend/test/api/flatcar_package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
"testing"

"github.com/google/uuid"
"github.com/kinvolk/nebraska/backend/pkg/config"
"github.com/kinvolk/nebraska/backend/pkg/server"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/kinvolk/nebraska/backend/pkg/config"
"github.com/kinvolk/nebraska/backend/pkg/server"
)

func TestHostFlatcarPackage(t *testing.T) {
Expand Down
Loading

0 comments on commit 058947b

Please sign in to comment.