Skip to content

Commit

Permalink
backend: Update e2e tests
Browse files Browse the repository at this point in the history
This patch updates the e2e tests according to the changes that
were introduced when replacing gin with echo framework

Signed-off-by: Santhosh Nagaraj S <santhosh@kinvolk.io>
  • Loading branch information
yolossn committed Jan 21, 2022
1 parent 5bca5ea commit 57b5238
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 40 deletions.
15 changes: 10 additions & 5 deletions backend/test/api/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/kinvolk/nebraska/backend/pkg/api"
"github.com/kinvolk/nebraska/backend/pkg/codegen"
)

func TestListActivity(t *testing.T) {
Expand All @@ -29,13 +30,17 @@ func TestListActivity(t *testing.T) {
method := "GET"

// response
var activities []api.Activity
var activityResp codegen.ActivityPage

httpDo(t, url, method, nil, http.StatusOK, "json", &activities)
httpDo(t, url, method, nil, http.StatusOK, "json", &activityResp)

activities := activityResp.Activities

assert.Equal(t, len(activitiesDB), len(activities))
assert.Equal(t, activitiesDB[0].AppID, activities[0].AppID)
assert.Equal(t, activitiesDB[0].GroupID, activities[0].GroupID)
assert.Equal(t, activitiesDB[0].GroupName, activities[0].GroupName)
for i := range activitiesDB {
assert.Equal(t, activitiesDB[i].AppID.String, activities[i].AppID)
assert.Equal(t, activitiesDB[i].GroupID.String, activities[i].GroupID)
assert.Equal(t, activitiesDB[i].GroupName.String, activities[i].GroupName)
}
})
}
29 changes: 18 additions & 11 deletions backend/test/api/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/kinvolk/nebraska/backend/pkg/api"
"github.com/kinvolk/nebraska/backend/pkg/codegen"
)

func TestListApp(t *testing.T) {
Expand All @@ -29,26 +30,23 @@ func TestListApp(t *testing.T) {
url := fmt.Sprintf("%s/api/apps", testServerURL)
method := "GET"

// TODO: will require change as response struct is changed in POC2 branch
var appsResp []*api.Application

var appsResp codegen.AppsPage
httpDo(t, url, method, nil, http.StatusOK, "json", &appsResp)

assert.NotEqual(t, len(appsDB), 0)
assert.Equal(t, len(appsDB), len(appsResp))

assert.Equal(t, len(appsDB), len(appsResp.Applications))
for i := range appsDB {
assert.Equal(t, appsResp[i].ID, appsDB[i].ID)
assert.Equal(t, appsResp[i].Name, appsDB[i].Name)
assert.Equal(t, appsDB[i].ID, appsResp.Applications[i].Id)
assert.Equal(t, appsDB[i].Name, appsResp.Applications[i].Name)
}
})
}

func TestCreateApp(t *testing.T) {
// establish DB connection
db := newDBForTest(t)

t.Run("success_do_not_copy", func(t *testing.T) {
// establish DB connection
db := newDBForTest(t)

// Create App request
url := fmt.Sprintf("%s%s", testServerURL, "/api/apps")
method := "POST"
Expand All @@ -71,6 +69,9 @@ func TestCreateApp(t *testing.T) {
})

t.Run("success_with_copy", func(t *testing.T) {
// establish DB connection
db := newDBForTest(t)

app := getRandomApp(t, db)

// Create App request
Expand All @@ -85,8 +86,14 @@ func TestCreateApp(t *testing.T) {

httpDo(t, url, method, payload, http.StatusOK, "json", &application)

// close and create new db session to clear and update cached appIds
db.Close()
db, err := api.New()
require.NoError(t, err)
require.NotNil(t, db)

// check if app exists in DB
app, err := db.GetApp(application.ID)
app, err = db.GetApp(application.ID)
require.NoError(t, err)

assert.Equal(t, application.ID, app.ID)
Expand Down
15 changes: 8 additions & 7 deletions backend/test/api/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/kinvolk/nebraska/backend/pkg/api"
"github.com/kinvolk/nebraska/backend/pkg/codegen"
)

func TestListChannels(t *testing.T) {
Expand All @@ -32,15 +33,15 @@ func TestListChannels(t *testing.T) {
url := fmt.Sprintf("%s/api/apps/%s/channels", testServerURL, app.ID)
method := "GET"

// response
// TODO: will require change as response struct is changed in POC2 branch
var channels []*api.Channel
var channelsResp codegen.ChannelPage

httpDo(t, url, method, nil, http.StatusOK, "json", &channels)
httpDo(t, url, method, nil, http.StatusOK, "json", &channelsResp)

assert.NotEqual(t, 0, len(channels))
assert.Equal(t, len(channelsDB), len(channels))
assert.Equal(t, channelsDB[0].ApplicationID, channels[0].ApplicationID)
for i := range channelsDB {
assert.NotEqual(t, 0, len(channelsResp.Channels))
assert.Equal(t, len(channelsDB), len(channelsResp.Channels))
assert.Equal(t, channelsDB[i].ApplicationID, channelsResp.Channels[i].ApplicationID)
}
})
}

Expand Down
2 changes: 1 addition & 1 deletion backend/test/api/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestConfig(t *testing.T) {

httpDo(t, url, method, nil, http.StatusOK, "json", &rMap)

assert.Equal(t, "", rMap["auth_mode"])
assert.Equal(t, "noop", rMap["auth_mode"])
assert.Equal(t, "", rMap["access_management_url"])
assert.Equal(t, "", rMap["login_url"])
assert.Equal(t, "", rMap["logout_url"])
Expand Down
16 changes: 10 additions & 6 deletions backend/test/api/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/kinvolk/nebraska/backend/pkg/api"
"github.com/kinvolk/nebraska/backend/pkg/codegen"
)

func TestListGroups(t *testing.T) {
Expand All @@ -32,14 +33,17 @@ func TestListGroups(t *testing.T) {
url := fmt.Sprintf("%s/api/apps/%s/groups", testServerURL, app.ID)
method := "GET"

// response
// TODO: will require change as response struct is changed in POC2 branch
var groups []*api.Group
var groupResp codegen.GroupPage

httpDo(t, url, method, nil, http.StatusOK, "json", &groupResp)

httpDo(t, url, method, nil, http.StatusOK, "json", &groups)
assert.NotEqual(t, 0, len(groupResp.Groups))
assert.Equal(t, len(groupsDB), len(groupResp.Groups))

assert.NotEqual(t, 0, len(groups))
assert.Equal(t, len(groupsDB), len(groups))
for i := range groupsDB {
assert.Equal(t, groupsDB[i].ID, groupResp.Groups[i].Id)
assert.Equal(t, groupsDB[i].Name, groupResp.Groups[i].Name)
}
})
}

Expand Down
4 changes: 4 additions & 0 deletions backend/test/api/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api_test
import (
"encoding/json"
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"math/rand"
Expand Down Expand Up @@ -83,6 +84,9 @@ func httpDo(t *testing.T, url string, method string, payload io.Reader, statusco
require.NoError(t, err)
require.NotNil(t, req)

req.Header = http.Header{
"Content-Type": []string{fmt.Sprintf("application/%s", responseType)},
}
resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
require.NotNil(t, resp)
Expand Down
8 changes: 4 additions & 4 deletions backend/test/api/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/kinvolk/nebraska/backend/pkg/api"
"github.com/kinvolk/nebraska/backend/pkg/codegen"
)

func TestListInstances(t *testing.T) {
Expand Down Expand Up @@ -63,18 +64,17 @@ func TestGetInstanceCount(t *testing.T) {
url := fmt.Sprintf("%s/api/apps/%s/groups/%s/instancescount?duration=30d", testServerURL, appWithInstance.ID, appWithInstance.Groups[0].ID)
method := "GET"

// TODO: will require change as response struct is changed in POC2 branch
var instancesCount int
var instancesCountResp codegen.InstanceCount

httpDo(t, url, method, nil, http.StatusOK, "json", &instancesCount)
httpDo(t, url, method, nil, http.StatusOK, "json", &instancesCountResp)

count, err := db.GetInstancesCount(api.InstancesQueryParams{
ApplicationID: appWithInstance.ID,
GroupID: appWithInstance.Groups[0].ID,
}, "30d")

require.NoError(t, err)
assert.Equal(t, int(count), instancesCount)
assert.Equal(t, uint64(count), instancesCountResp.Count)
})
}

Expand Down
4 changes: 2 additions & 2 deletions backend/test/api/omaha_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestOmaha(t *testing.T) {
t.Run("success", func(t *testing.T) {
track := app.Groups[0].Track

url := fmt.Sprintf("%s/omaha", testServerURL)
url := fmt.Sprintf("%s/v1/update", testServerURL)

method := "POST"

Expand Down Expand Up @@ -52,7 +52,7 @@ func TestOmaha(t *testing.T) {
})

t.Run("large_request_body", func(t *testing.T) {
url := fmt.Sprintf("%s/omaha", testServerURL)
url := fmt.Sprintf("%s/v1/update", testServerURL)

method := "POST"

Expand Down
28 changes: 24 additions & 4 deletions backend/test/api/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import (
"strings"
"testing"

"github.com/google/uuid"
"github.com/jinzhu/copier"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/guregu/null.v4"

"github.com/kinvolk/nebraska/backend/pkg/api"
"github.com/kinvolk/nebraska/backend/pkg/codegen"
)

func TestListPackages(t *testing.T) {
Expand All @@ -34,12 +37,16 @@ func TestListPackages(t *testing.T) {

// response
// TODO: will require change as response struct is changed in POC2 branch
var packages []*api.Package
var packagesResp codegen.PackagePage

httpDo(t, url, method, nil, http.StatusOK, "json", &packages)
httpDo(t, url, method, nil, http.StatusOK, "json", &packagesResp)

assert.NotEqual(t, 0, len(packages))
assert.Equal(t, len(packagesDB), len(packages))
assert.NotEqual(t, 0, len(packagesResp.Packages))
assert.Equal(t, len(packagesDB), len(packagesResp.Packages))
for i := range packagesDB {
assert.Equal(t, packagesDB[i].ApplicationID, packagesResp.Packages[i].ApplicationID)
assert.Equal(t, packagesDB[i].ID, packagesResp.Packages[i].Id)
}
})
}

Expand Down Expand Up @@ -118,6 +125,19 @@ func TestUpdatePackage(t *testing.T) {
err = copier.Copy(&packageDB, packagesDB[0])
require.NoError(t, err)

if packageDB.ChannelsBlacklist == nil {
packageDB.ChannelsBlacklist = []string{}
}
if packageDB.Description.IsZero() {
packageDB.Description = null.StringFrom("some desc")
}
if packageDB.Size.IsZero() {
packageDB.Size = null.StringFrom("20")
}
if packageDB.Hash.IsZero() {
packageDB.Hash = null.StringFrom(uuid.New().String())
}

packageVersion := "20.2.2"
packageDB.Version = packageVersion

Expand Down

0 comments on commit 57b5238

Please sign in to comment.