mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 15:29:28 +01:00
test(be): fix dredd tests
This commit is contained in:
parent
3445d9a716
commit
106a53bcae
@ -34,7 +34,7 @@ var capabilities = map[string][]string{
|
||||
"template": {"repository", "inventory", "environment", "view"},
|
||||
"task": {"template"},
|
||||
"schedule": {"template"},
|
||||
"view": {"repository"},
|
||||
"view": {},
|
||||
}
|
||||
|
||||
func capabilityWrapper(cap string) func(t *trans.Transaction) {
|
||||
@ -100,9 +100,9 @@ func resolveCapability(caps []string, resolved []string, uid string) {
|
||||
case "template":
|
||||
res, err := store.Sql().Exec(
|
||||
"insert into project__template "+
|
||||
"(project_id, inventory_id, repository_id, environment_id, alias, playbook, arguments, override_args, description) "+
|
||||
"values (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
userProject.ID, inventoryID, repoID, environmentID, "Test-"+uid, "test-playbook.yml", "", false, "Hello, World!")
|
||||
"(project_id, inventory_id, repository_id, environment_id, alias, playbook, arguments, override_args, description, view_id) "+
|
||||
"values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
userProject.ID, inventoryID, repoID, environmentID, "Test-"+uid, "test-playbook.yml", "", false, "Hello, World!", view.ID)
|
||||
printError(err)
|
||||
templateID, _ = res.LastInsertId()
|
||||
case "task":
|
||||
|
@ -28,6 +28,7 @@ var tablesShouldBeTruncated = [...]string {
|
||||
"project__schedule",
|
||||
"project__user",
|
||||
"user",
|
||||
"project__view",
|
||||
}
|
||||
// Test Runner User
|
||||
func addTestRunnerUser() {
|
||||
|
@ -109,9 +109,9 @@ func main() {
|
||||
h.Before("schedule > /api/project/{project_id}/schedules/{schedule_id} > Updates schedule > 204 > application/json", capabilityWrapper("schedule"))
|
||||
h.Before("schedule > /api/project/{project_id}/schedules/{schedule_id} > Deletes schedule > 204 > application/json", capabilityWrapper("schedule"))
|
||||
|
||||
h.Before("view > /api/project/{project_id}/views/{view_id} > Get view > 200 > application/json", capabilityWrapper("view"))
|
||||
h.Before("view > /api/project/{project_id}/views/{view_id} > Updates view > 204 > application/json", capabilityWrapper("view"))
|
||||
h.Before("view > /api/project/{project_id}/views/{view_id} > Deletes view > 204 > application/json", capabilityWrapper("view"))
|
||||
h.Before("project > /api/project/{project_id}/views/{view_id} > Get view > 200 > application/json", capabilityWrapper("view"))
|
||||
h.Before("project > /api/project/{project_id}/views/{view_id} > Updates view > 204 > application/json", capabilityWrapper("view"))
|
||||
h.Before("project > /api/project/{project_id}/views/{view_id} > Removes view > 204 > application/json", capabilityWrapper("view"))
|
||||
|
||||
//Add these last as they normalize the requests and path values after hook processing
|
||||
h.BeforeAll(func(transactions []*trans.Transaction) {
|
||||
|
@ -380,6 +380,7 @@ definitions:
|
||||
properties:
|
||||
title:
|
||||
type: string
|
||||
example: Test
|
||||
project_id:
|
||||
type: integer
|
||||
minimum: 1
|
||||
@ -508,6 +509,13 @@ parameters:
|
||||
type: integer
|
||||
required: true
|
||||
x-example: 9
|
||||
view_id:
|
||||
name: view_id
|
||||
description: view ID
|
||||
in: path
|
||||
type: integer
|
||||
required: true
|
||||
x-example: 10
|
||||
paths:
|
||||
/ping:
|
||||
get:
|
||||
|
@ -98,7 +98,7 @@ func AddView(w http.ResponseWriter, r *http.Request) {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
helpers.WriteJSON(w, http.StatusCreated, newView)
|
||||
}
|
||||
|
||||
func SetViewPositions(w http.ResponseWriter, r *http.Request) {
|
||||
@ -158,7 +158,6 @@ func UpdateView(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
|
@ -213,7 +213,7 @@ func Route() *mux.Router {
|
||||
projectScheduleManagement.HandleFunc("/{schedule_id}", projects.RemoveSchedule).Methods("DELETE")
|
||||
|
||||
|
||||
projectViewManagement := projectAdminUsersAPI.PathPrefix("/views").Subrouter()
|
||||
projectViewManagement := projectUserAPI.PathPrefix("/views").Subrouter()
|
||||
projectViewManagement.Use(projects.ViewMiddleware)
|
||||
projectViewManagement.HandleFunc("/{view_id}", projects.GetViews).Methods("GET", "HEAD")
|
||||
projectViewManagement.HandleFunc("/{view_id}", projects.UpdateView).Methods("PUT")
|
||||
|
83
db/Store.go
83
db/Store.go
@ -30,13 +30,14 @@ type RetrieveQueryParams struct {
|
||||
// It mainly used for NoSQL implementations (currently BoltDB) to preserve same
|
||||
// data structure of different implementations and easy change it if required.
|
||||
type ObjectProperties struct {
|
||||
TableName string
|
||||
IsGlobal bool // doesn't belong to other table, for example to project or user.
|
||||
ForeignColumnSuffix string
|
||||
PrimaryColumnName string
|
||||
SortableColumns []string
|
||||
SortInverted bool // sort from high to low object ID by default. It is useful for some NoSQL implementations.
|
||||
Type reflect.Type // to which type the table bust be mapped.
|
||||
TableName string
|
||||
IsGlobal bool // doesn't belong to other table, for example to project or user.
|
||||
ForeignColumnSuffix string
|
||||
PrimaryColumnName string
|
||||
SortableColumns []string
|
||||
DefaultSortingColumn string
|
||||
SortInverted bool // sort from high to low object ID by default. It is useful for some NoSQL implementations.
|
||||
Type reflect.Type // to which type the table bust be mapped.
|
||||
}
|
||||
|
||||
var ErrNotFound = errors.New("no rows in result set")
|
||||
@ -146,41 +147,46 @@ type Store interface {
|
||||
}
|
||||
|
||||
var AccessKeyProps = ObjectProperties{
|
||||
TableName: "access_key",
|
||||
SortableColumns: []string{"name", "type"},
|
||||
ForeignColumnSuffix: "key_id",
|
||||
PrimaryColumnName: "id",
|
||||
Type: reflect.TypeOf(AccessKey{}),
|
||||
TableName: "access_key",
|
||||
SortableColumns: []string{"name", "type"},
|
||||
ForeignColumnSuffix: "key_id",
|
||||
PrimaryColumnName: "id",
|
||||
Type: reflect.TypeOf(AccessKey{}),
|
||||
DefaultSortingColumn: "name",
|
||||
}
|
||||
|
||||
var EnvironmentProps = ObjectProperties{
|
||||
TableName: "project__environment",
|
||||
SortableColumns: []string{"name"},
|
||||
ForeignColumnSuffix: "environment_id",
|
||||
PrimaryColumnName: "id",
|
||||
Type: reflect.TypeOf(Environment{}),
|
||||
TableName: "project__environment",
|
||||
SortableColumns: []string{"name"},
|
||||
ForeignColumnSuffix: "environment_id",
|
||||
PrimaryColumnName: "id",
|
||||
Type: reflect.TypeOf(Environment{}),
|
||||
DefaultSortingColumn: "name",
|
||||
}
|
||||
|
||||
var InventoryProps = ObjectProperties{
|
||||
TableName: "project__inventory",
|
||||
SortableColumns: []string{"name"},
|
||||
ForeignColumnSuffix: "inventory_id",
|
||||
PrimaryColumnName: "id",
|
||||
Type: reflect.TypeOf(Inventory{}),
|
||||
TableName: "project__inventory",
|
||||
SortableColumns: []string{"name"},
|
||||
ForeignColumnSuffix: "inventory_id",
|
||||
PrimaryColumnName: "id",
|
||||
Type: reflect.TypeOf(Inventory{}),
|
||||
DefaultSortingColumn: "name",
|
||||
}
|
||||
|
||||
var RepositoryProps = ObjectProperties{
|
||||
TableName: "project__repository",
|
||||
ForeignColumnSuffix: "repository_id",
|
||||
PrimaryColumnName: "id",
|
||||
Type: reflect.TypeOf(Repository{}),
|
||||
TableName: "project__repository",
|
||||
ForeignColumnSuffix: "repository_id",
|
||||
PrimaryColumnName: "id",
|
||||
Type: reflect.TypeOf(Repository{}),
|
||||
DefaultSortingColumn: "name",
|
||||
}
|
||||
|
||||
var TemplateProps = ObjectProperties{
|
||||
TableName: "project__template",
|
||||
SortableColumns: []string{"name"},
|
||||
PrimaryColumnName: "id",
|
||||
Type: reflect.TypeOf(Template{}),
|
||||
TableName: "project__template",
|
||||
SortableColumns: []string{"name"},
|
||||
PrimaryColumnName: "id",
|
||||
Type: reflect.TypeOf(Template{}),
|
||||
DefaultSortingColumn: "alias",
|
||||
}
|
||||
|
||||
var ScheduleProps = ObjectProperties{
|
||||
@ -196,10 +202,11 @@ var ProjectUserProps = ObjectProperties{
|
||||
}
|
||||
|
||||
var ProjectProps = ObjectProperties{
|
||||
TableName: "project",
|
||||
IsGlobal: true,
|
||||
PrimaryColumnName: "id",
|
||||
Type: reflect.TypeOf(Project{}),
|
||||
TableName: "project",
|
||||
IsGlobal: true,
|
||||
PrimaryColumnName: "id",
|
||||
Type: reflect.TypeOf(Project{}),
|
||||
DefaultSortingColumn: "name",
|
||||
}
|
||||
|
||||
var UserProps = ObjectProperties{
|
||||
@ -234,8 +241,8 @@ var TaskOutputProps = ObjectProperties{
|
||||
}
|
||||
|
||||
var ViewProps = ObjectProperties{
|
||||
TableName: "project__view",
|
||||
PrimaryColumnName: "id",
|
||||
Type: reflect.TypeOf(View{}),
|
||||
SortableColumns: []string{"position"},
|
||||
TableName: "project__view",
|
||||
PrimaryColumnName: "id",
|
||||
Type: reflect.TypeOf(View{}),
|
||||
DefaultSortingColumn: "position",
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ type View struct {
|
||||
ID int `db:"id" json:"id"`
|
||||
ProjectID int `db:"project_id" json:"project_id"`
|
||||
Title string `db:"title" json:"title"`
|
||||
Position int `db:"int" json:"int"`
|
||||
Position int `db:"position" json:"position"`
|
||||
}
|
||||
|
||||
func (view *View) Validate() error {
|
||||
|
@ -219,12 +219,14 @@ func (d *SqlDb) getObjects(projectID int, props db.ObjectProperties, params db.R
|
||||
orderDirection = "DESC"
|
||||
}
|
||||
|
||||
orderColumn := "name"
|
||||
orderColumn := props.DefaultSortingColumn
|
||||
if containsStr(props.SortableColumns, params.SortBy) {
|
||||
orderColumn = params.SortBy
|
||||
}
|
||||
|
||||
q = q.OrderBy("pe." + orderColumn + " " + orderDirection)
|
||||
if orderColumn != "" {
|
||||
q = q.OrderBy("pe." + orderColumn + " " + orderDirection)
|
||||
}
|
||||
|
||||
query, args, err := q.ToSql()
|
||||
|
||||
|
@ -57,7 +57,7 @@ func (d *SqlDb) UpdateTemplate(template db.Template) error {
|
||||
"vault_key_id=?, " +
|
||||
"`type`=?, " +
|
||||
"start_version=?," +
|
||||
"build_template_id=? " +
|
||||
"build_template_id=?, " +
|
||||
"view_id=? " +
|
||||
"where removed = false and id=? and project_id=?",
|
||||
template.InventoryID,
|
||||
|
Loading…
Reference in New Issue
Block a user