Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: RedHatInsights/quickstarts
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8d29eeb9a97bb5afc50cef5de578a7dd0ea80ad8
Choose a base ref
..
head repository: RedHatInsights/quickstarts
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4834a1d6891a6c2c3e4c67ad149d5c6c468eb535
Choose a head ref
Showing with 59 additions and 69 deletions.
  1. +21 −3 cmd/spec/parameters.yaml
  2. +3 −2 cmd/spec/path.yaml
  3. +1 −10 pkg/routes/help_topic.go
  4. +2 −47 pkg/routes/quickstarts_test.go
  5. +32 −7 spec/openapi.json
24 changes: 21 additions & 3 deletions cmd/spec/parameters.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
# It is necessary to have the initial indetation!
queryParams:
Bundle:
name: bundle
description: If set, content is associated with a specific CRC bundle
ProductFamilies:
name: product-families
description: If set, content is associated with a specific CRC product families
in: query
required: false
schema:
type: string
explode: true
style: form
Content:
name: content
description: If set, content is associated with a specific CRC content
in: query
required: false
schema:
type: string
explode: true
style: form
UseCase:
name: use-case
description: If set, content is associated with a specific CRC use case
in: query
required: false
schema:
5 changes: 3 additions & 2 deletions cmd/spec/path.yaml
Original file line number Diff line number Diff line change
@@ -21,7 +21,9 @@ paths:
items:
$ref: '#/components/schemas/v1.Quickstart'
parameters:
- $ref: '#/components/schemas/queryParams/Bundle'
- $ref: '#/components/schemas/queryParams/ProductFamilies'
- $ref: '#/components/schemas/queryParams/Content'
- $ref: '#/components/schemas/queryParams/UseCase'
- $ref: '#/components/schemas/queryParams/Application'
- $ref: '#/components/schemas/queryParams/Limit'
- $ref: '#/components/schemas/queryParams/Offset'
@@ -65,7 +67,6 @@ paths:
items:
$ref: '#/components/schemas/v1.HelpTopic'
parameters:
- $ref: '#/components/schemas/queryParams/Bundle'
- $ref: '#/components/schemas/queryParams/Application'
- $ref: '#/components/schemas/queryParams/Name'
/helptopics/{name}:
11 changes: 1 addition & 10 deletions pkg/routes/help_topic.go
Original file line number Diff line number Diff line change
@@ -55,12 +55,6 @@ func concatAppendTags(slices [][]string) []string {
func GetAllHelpTopics(w http.ResponseWriter, r *http.Request) {
var helpTopic []models.HelpTopic
var tagTypes []models.TagType
// first try bundle query param
bundleQueries := r.URL.Query()["bundle"]
if len(bundleQueries) == 0 {
// if empty try bundle[] queries
bundleQueries = r.URL.Query()["bundle[]"]
}

applicationQueries := r.URL.Query()["application"]
if len(applicationQueries) == 0 {
@@ -73,9 +67,7 @@ func GetAllHelpTopics(w http.ResponseWriter, r *http.Request) {
}

var err error
if len(bundleQueries) > 0 {
tagTypes = append(tagTypes, models.BundleTag)
}

if len(applicationQueries) > 0 {
tagTypes = append(tagTypes, models.ApplicationTag)
}
@@ -85,7 +77,6 @@ func GetAllHelpTopics(w http.ResponseWriter, r *http.Request) {
* future proofing more than 2 tag queries
*/
tagQueries := make([][]string, 2)
tagQueries[0] = bundleQueries
tagQueries[1] = applicationQueries
helpTopic, err = findHelpTopics(tagTypes, concatAppendTags(tagQueries), nameQueries)
} else {
49 changes: 2 additions & 47 deletions pkg/routes/quickstarts_test.go
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ var rhelBudleTag models.Tag
var rhelContentTypeTag models.Tag
var rhelProductFamiliesTag models.Tag
var rhelUseCaseTag models.Tag
var settingsBundleTag models.Tag
var settingsContentTypeTag models.Tag
var settingsProductFamiliesTag models.Tag
var settingsUseCaseTag models.Tag
@@ -32,7 +31,6 @@ var rbacProductFamiliesTag models.Tag
var rbacContentTypeTag models.Tag
var rbacUseCaseTag models.Tag
var unusedTag models.Tag
var favoriteQuickstart models.FavoriteQuickstart

func mockQuickstart(name string) *models.Quickstart {
quickstart.Name = name
@@ -69,17 +67,13 @@ func setupRouter() *chi.Mux {
}

func setupTags() {
rhelBudleTag.Type = models.BundleTag
rhelBudleTag.Value = "rhel"
rhelProductFamiliesTag.Type = models.ProductFamilies
rhelProductFamiliesTag.Value = "rhel"
rhelContentTypeTag.Type = models.ContentType
rhelContentTypeTag.Value = "quickstart"
rhelUseCaseTag.Type = models.UseCase
rhelUseCaseTag.Value = "deploy"

settingsBundleTag.Type = models.BundleTag
settingsBundleTag.Value = "settings"
settingsProductFamiliesTag.Type = models.ProductFamilies
settingsProductFamiliesTag.Value = "settings"
settingsContentTypeTag.Type = models.ContentType
@@ -96,14 +90,10 @@ func setupTags() {
rbacUseCaseTag.Type = models.UseCase
rbacUseCaseTag.Value = "clusters"

unusedTag.Type = models.BundleTag
unusedTag.Value = "unused"

database.DB.Create(&rhelBudleTag)
database.DB.Create(&rhelContentTypeTag)
database.DB.Create(&rhelProductFamiliesTag)
database.DB.Create(&rhelUseCaseTag)
database.DB.Create(&settingsBundleTag)
database.DB.Create(&settingsProductFamiliesTag)
database.DB.Create(&settingsContentTypeTag)
database.DB.Create(&settingsUseCaseTag)
@@ -119,14 +109,14 @@ func setupTaggedQuickstarts() {
taggedQuickstart.Content = []byte(`{"tags": "all-tags"}`)

database.DB.Create(&taggedQuickstart)
database.DB.Model(&taggedQuickstart).Association("Tags").Append(&rhelBudleTag, &settingsBundleTag, &rbacApplicationTag)
database.DB.Model(&taggedQuickstart).Association("Tags").Append(&rhelBudleTag, &rbacApplicationTag)
database.DB.Save(&taggedQuickstart)

settingsQuickstart.Name = "settings-quickstart"
settingsQuickstart.Content = []byte(`{"tags": "settings"}`)

database.DB.Create(&settingsQuickstart)
database.DB.Model(&settingsQuickstart).Association("Tags").Append(&settingsBundleTag, &settingsContentTypeTag, &settingsProductFamiliesTag, &settingsUseCaseTag)
database.DB.Model(&settingsQuickstart).Association("Tags").Append(&settingsContentTypeTag, &settingsProductFamiliesTag, &settingsUseCaseTag)
database.DB.Save(&settingsQuickstart)

rhelQuickstart.Name = "rhel-quickstart"
@@ -157,41 +147,6 @@ func TestGetAll(t *testing.T) {
setupTaggedQuickstarts()
leafQuickstart := mockQuickstart("non-tags-quickstart")

t.Run("should get all quickstarts with 'rhel' or 'settings' bundle tags", func(t *testing.T) {
request, _ := http.NewRequest(http.MethodGet, "/?bundle[]=rhel&bundle[]=settings", nil)
response := httptest.NewRecorder()
router.ServeHTTP(response, request)

var payload *responsePayload
json.NewDecoder(response.Body).Decode(&payload)
assert.Equal(t, 200, response.Code)
assert.Equal(t, 3, len(payload.Data))
})

t.Run("should get all quickstarts with 'rhel' bundle tag", func(t *testing.T) {
request, _ := http.NewRequest(http.MethodGet, "/?bundle=rhel", nil)
response := httptest.NewRecorder()
router.ServeHTTP(response, request)

var payload *responsePayload
json.NewDecoder(response.Body).Decode(&payload)
assert.Equal(t, 200, response.Code)
assert.Equal(t, 2, len(payload.Data))
})

t.Run("should get all quickstarts with 'settings' bundle tag", func(t *testing.T) {
request, _ := http.NewRequest(http.MethodGet, "/?bundle=settings", nil)
response := httptest.NewRecorder()
router.ServeHTTP(response, request)

var payload *responsePayload
json.NewDecoder(response.Body).Decode(&payload)
assert.Equal(t, 200, response.Code)
assert.Equal(t, 2, len(payload.Data))
assert.Equal(t, "tagged-quickstart", payload.Data[0].Name)
assert.Equal(t, "settings-quickstart", payload.Data[1].Name)
})

t.Run("should get all quickstarts with 'rbac' application tag", func(t *testing.T) {
request, _ := http.NewRequest(http.MethodGet, "/?application=rbac", nil)
response := httptest.NewRecorder()
39 changes: 32 additions & 7 deletions spec/openapi.json
Original file line number Diff line number Diff line change
@@ -38,11 +38,11 @@
},
"style": "form"
},
"Bundle": {
"description": "If set, content is associated with a specific CRC bundle",
"Content": {
"description": "If set, content is associated with a specific CRC content",
"explode": true,
"in": "query",
"name": "bundle",
"name": "content",
"required": false,
"schema": {
"type": "string"
@@ -91,6 +91,17 @@
},
"style": "form"
},
"ProductFamilies": {
"description": "If set, content is associated with a specific CRC product families",
"explode": true,
"in": "query",
"name": "product-families",
"required": false,
"schema": {
"type": "string"
},
"style": "form"
},
"TopicName": {
"description": "identifier",
"in": "path",
@@ -99,6 +110,17 @@
"schema": {
"type": "string"
}
},
"UseCase": {
"description": "If set, content is associated with a specific CRC use case",
"explode": true,
"in": "query",
"name": "use-case",
"required": false,
"schema": {
"type": "string"
},
"style": "form"
}
},
"v1.FavoriteQuickstart": {
@@ -423,9 +445,6 @@
"/helptopics": {
"get": {
"parameters": [
{
"$ref": "#/components/schemas/queryParams/Bundle"
},
{
"$ref": "#/components/schemas/queryParams/Application"
},
@@ -507,7 +526,13 @@
"get": {
"parameters": [
{
"$ref": "#/components/schemas/queryParams/Bundle"
"$ref": "#/components/schemas/queryParams/ProductFamilies"
},
{
"$ref": "#/components/schemas/queryParams/Content"
},
{
"$ref": "#/components/schemas/queryParams/UseCase"
},
{
"$ref": "#/components/schemas/queryParams/Application"