Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into default_for_simpl…
Browse files Browse the repository at this point in the history
…e_type2
  • Loading branch information
kwk committed Aug 20, 2018
2 parents 86bba98 + b688f8f commit 2c142a8
Show file tree
Hide file tree
Showing 49 changed files with 2,431 additions and 329 deletions.
56 changes: 55 additions & 1 deletion .make/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ ALL_PKGS_EXCLUDE_PATTERN = "vendor\|account\/tenant\|app\'\|tool\/cli\|design\|c
GOANALYSIS_PKGS_EXCLUDE_PATTERN="vendor|account/tenant|app|client|tool/cli"
GOANALYSIS_DIRS=$(shell go list -f {{.Dir}} ./... | grep -v -E $(GOANALYSIS_PKGS_EXCLUDE_PATTERN))

# temporary directory for fabric8-test
FABRIC8_E2E_TEST_DIR = $(TMP_PATH)/fabric8-test

# fabric8-test reporsitory
FABRIC8_E2E_TEST_REPO = "https://github.com/fabric8io/fabric8-test.git"

#-------------------------------------------------------------------------------
# Normal test targets
#
Expand Down Expand Up @@ -187,13 +193,50 @@ test-remote-no-coverage: prebuild-check $(SOURCES)
test-migration: prebuild-check migration/sqlbindata.go migration/sqlbindata_test.go
F8_RESOURCE_DATABASE=1 F8_LOG_LEVEL=$(F8_LOG_LEVEL) go test $(GO_TEST_VERBOSITY_FLAG) github.com/fabric8-services/fabric8-wit/migration

# Starts the WIT server and waits until its running
define start-wit
echo "Starting WIT and ensuring that it is running..."; \
F8_LOG_LEVEL=ERROR ./wit+pmcd.sh &
while ! nc -z localhost 8080 < /dev/null; do \
printf .; \
sleep 5 ; \
done; \
echo "WIT is RUNNING!";
endef

.PHONY: test-e2e
## Runs the end-to-end tests WITHOUT producing coverage files for each package.
test-e2e: $(BINARY_SERVER_BIN)
$(call log-info,"Running tests: $@")
ifeq ($(OS),Windows_NT)
$(error End to end tests currently cannot run on Windows based operating systems.)
endif
$(call download-docker-compose)
ifeq ($(UNAME_S),Darwin)
@echo "Running docker-compose with macOS network settings"
$(DOCKER_COMPOSE_BIN_ALT) -f docker-compose.macos.yml up -d db auth
else
@echo "Running docker-compose with Linux network settings"
$(DOCKER_COMPOSE_BIN_ALT) up -d db auth
endif
# Start the WIT server
$(call start-wit)
# Clone the fabric8-test repo
@if [ "$(FABRIC8_E2E_TEST_DIR)" ]; then \
echo "Removing any existing dir $(FABRIC8_E2E_TEST_DIR)"; \
rm -rf $(FABRIC8_E2E_TEST_DIR); \
fi
$(GIT_BIN_NAME) clone --depth=1 $(FABRIC8_E2E_TEST_REPO) $(FABRIC8_E2E_TEST_DIR)
# Install e2e test deps and run the tests
$(FABRIC8_E2E_TEST_DIR)/EE_API_automation/cico_run_EE_tests_wit.sh

# Downloads docker-compose to tmp/docker-compose if it does not already exist.
define download-docker-compose
@if [ ! -f "$(DOCKER_COMPOSE_BIN_ALT)" ]; then \
echo "Downloading docker-compose to $(DOCKER_COMPOSE_BIN_ALT)"; \
UNAME_S=$(shell uname -s); \
UNAME_M=$(shell uname -m); \
URL="https://github.com/docker/compose/releases/download/1.11.2/docker-compose-$${UNAME_S}-$${UNAME_M}"; \
URL="https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$${UNAME_S}-$${UNAME_M}"; \
curl --silent -L $${URL} > $(DOCKER_COMPOSE_BIN_ALT); \
chmod +x $(DOCKER_COMPOSE_BIN_ALT); \
fi
Expand Down Expand Up @@ -542,3 +585,14 @@ CLEAN_TARGETS += clean-coverage-remote
## Removes remote test coverage file
clean-coverage-remote:
-@rm -f $(COV_PATH_REMOTE)

CLEAN_TARGETS += clean-e2e
.PHONY: clean-e2e
## Cleans up environment of e2e tests
clean-e2e:
## Kills the WIT process
$(shell ps aux | grep 'bin/[w]it' | awk '{print $$2}' | xargs kill)
## Removes the end-to-end (e2e) test directory
-rm -rf $(FABRIC8_E2E_TEST_DIR)


19 changes: 14 additions & 5 deletions cico_run_e2e_tests.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
#!/bin/bash

echo "The end to end tests check will be implemented in"
echo "https://github.com/fabric8-services/fabric8-wit/pull/2197 "
echo "but for the CI to execute the task in an individual job we need"
echo "to have an \".sh\" file in place."
. cico_setup.sh

exit 1
load_jenkins_vars;

install_deps;

make docker-start

make docker-build

trap "make clean-e2e" EXIT

make test-e2e

echo "CICO: ran e2e-tests"
3 changes: 2 additions & 1 deletion cico_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ function install_deps() {
docker \
make \
git \
curl
curl \
nc

service docker start

Expand Down
15 changes: 15 additions & 0 deletions controller/codebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,21 @@ func getBranch(projects []che.WorkspaceProject, codebaseURL string) string {
return ""
}

// ConvertCodebaseSimple converts a simple codebase ID into a Generic Relationship
func ConvertCodebaseSimple(request *http.Request, id interface{}) (*app.GenericData, *app.GenericLinks) {
i := fmt.Sprint(id)
data := &app.GenericData{
Type: ptr.String(APIStringTypeCodebase),
ID: &i,
}
relatedURL := rest.AbsoluteURL(request, app.CodebaseHref(i))
links := &app.GenericLinks{
Self: &relatedURL,
Related: &relatedURL,
}
return data, links
}

// ConvertCodebase converts between internal and external REST representation
func ConvertCodebase(request *http.Request, codebase codebase.Codebase, options ...CodebaseConvertFunc) *app.Codebase {
relatedURL := rest.AbsoluteURL(request, app.CodebaseHref(codebase.ID))
Expand Down
3 changes: 1 addition & 2 deletions controller/comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controller
import (
"context"
"fmt"
"html"
"net/http"

"github.com/fabric8-services/fabric8-wit/app"
Expand Down Expand Up @@ -216,7 +215,7 @@ func ConvertComment(request *http.Request, comment comment.Comment, additional .
ID: &comment.ID,
Attributes: &app.CommentAttributes{
Body: &comment.Body,
BodyRendered: ptr.String(rendering.RenderMarkupToHTML(html.EscapeString(comment.Body), comment.Markup)),
BodyRendered: ptr.String(rendering.RenderMarkupToHTML(comment.Body, comment.Markup)),
Markup: ptr.String(rendering.NilSafeGetMarkup(&comment.Markup)),
CreatedAt: &comment.CreatedAt,
UpdatedAt: &comment.UpdatedAt,
Expand Down
18 changes: 16 additions & 2 deletions controller/comments_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controller_test
import (
"context"
"fmt"
"html"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -155,7 +154,7 @@ func assertComment(t *testing.T, resultData *app.Comment, expectedIdentity accou
assert.Equal(t, expectedBody, *resultData.Attributes.Body)
require.NotNil(t, resultData.Attributes.Markup)
assert.Equal(t, expectedMarkup, *resultData.Attributes.Markup)
assert.Equal(t, rendering.RenderMarkupToHTML(html.EscapeString(expectedBody), expectedMarkup), *resultData.Attributes.BodyRendered)
assert.Equal(t, rendering.RenderMarkupToHTML(expectedBody, expectedMarkup), *resultData.Attributes.BodyRendered)
require.NotNil(t, resultData.Relationships)
require.NotNil(t, resultData.Relationships.Creator)
require.NotNil(t, resultData.Relationships.Creator.Data)
Expand Down Expand Up @@ -302,6 +301,21 @@ func (s *CommentsSuite) TestShowCommentWithEscapedScriptInjection() {
assertComment(s.T(), result.Data, s.testIdentity, "<img src=x onerror=alert('body') />", rendering.SystemMarkupPlainText)
}

func (s *CommentsSuite) TestShowCommentWithTextAndCodeblock() {
// given
fxt := tf.NewTestFixture(s.T(), s.DB, tf.CreateWorkItemEnvironment(), tf.WorkItems(1))
wiID := fxt.WorkItems[0].ID
body := "Hello, World \n```\n { \"foo\":\"bar\" } \n``` "
expectedBody := "<p>Hello, World</p>\n\n<pre><code class=\"prettyprint\"> <span class=\"pun\">{</span> <span class=\"str\">&#34;foo&#34;</span><span class=\"pun\">:</span><span class=\"str\">&#34;bar&#34;</span> <span class=\"pun\">}</span> \n</code></pre>\n"
c := s.createWorkItemComment(s.testIdentity, wiID, body, &markdownMarkup, nil)
// when
userSvc, _, _, _, commentsCtrl := s.securedControllers(s.testIdentity)
_, result := test.ShowCommentsOK(s.T(), userSvc.Context, userSvc, commentsCtrl, *c.Data.ID, nil, nil)
// then
assert.Equal(s.T(), body, *result.Data.Attributes.Body)
assert.Equal(s.T(), expectedBody, *result.Data.Attributes.BodyRendered)
}

func (s *CommentsSuite) TestUpdateCommentWithoutAuth() {
// given
fxt := tf.NewTestFixture(s.T(), s.DB, tf.CreateWorkItemEnvironment(), tf.WorkItems(1))
Expand Down
4 changes: 2 additions & 2 deletions controller/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/fabric8-services/fabric8-wit/jsonapi"
"github.com/fabric8-services/fabric8-wit/label"
"github.com/fabric8-services/fabric8-wit/login"
"github.com/fabric8-services/fabric8-wit/ptr"
"github.com/fabric8-services/fabric8-wit/rest"
"github.com/fabric8-services/fabric8-wit/space"
"github.com/goadesign/goa"
Expand Down Expand Up @@ -164,10 +165,9 @@ func ConvertLabelsSimple(request *http.Request, labelIDs []interface{}) []*app.G

// ConvertLabelSimple converts a Label ID into a Generic Relationship
func ConvertLabelSimple(request *http.Request, labelID interface{}) *app.GenericData {
t := label.APIStringTypeLabels
i := fmt.Sprint(labelID)
return &app.GenericData{
Type: &t,
Type: ptr.String(label.APIStringTypeLabels),
ID: &i,
}
}
Expand Down
17 changes: 8 additions & 9 deletions controller/test-files/event/list/ok-area.res.payload.golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
{
"attributes": {
"name": "system.area",
"newValue": null,
"oldValue": null,
"timestamp": "0001-01-01T00:00:00Z"
},
"id": "00000000-0000-0000-0000-000000000001",
Expand All @@ -27,13 +25,14 @@
}
]
},
"oldValue": {
"data": [
{
"id": "",
"type": "areas"
}
]
"workItemType": {
"data": {
"id": "00000000-0000-0000-0000-000000000004",
"type": "workitemtypes"
},
"links": {
"self": "http:///api/workitemtypes/00000000-0000-0000-0000-000000000004"
}
}
},
"type": "events"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
{
"attributes": {
"name": "system.assignees",
"newValue": null,
"oldValue": null,
"timestamp": "0001-01-01T00:00:00Z"
},
"id": "00000000-0000-0000-0000-000000000001",
Expand All @@ -27,7 +25,15 @@
}
]
},
"oldValue": {}
"workItemType": {
"data": {
"id": "00000000-0000-0000-0000-000000000003",
"type": "workitemtypes"
},
"links": {
"self": "http:///api/workitemtypes/00000000-0000-0000-0000-000000000003"
}
}
},
"type": "events"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
{
"attributes": {
"name": "system.description",
"newValue": null,
"oldValue": null,
"newValue": {
"content": "# Description is modified1",
"markup": "Markdown"
},
"timestamp": "0001-01-01T00:00:00Z"
},
"id": "00000000-0000-0000-0000-000000000001",
Expand All @@ -18,6 +20,15 @@
"related": "http:///api/users/00000000-0000-0000-0000-000000000002",
"self": "http:///api/users/00000000-0000-0000-0000-000000000002"
}
},
"workItemType": {
"data": {
"id": "00000000-0000-0000-0000-000000000003",
"type": "workitemtypes"
},
"links": {
"self": "http:///api/workitemtypes/00000000-0000-0000-0000-000000000003"
}
}
},
"type": "events"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
{
"attributes": {
"name": "system.iteration",
"newValue": null,
"oldValue": null,
"timestamp": "0001-01-01T00:00:00Z"
},
"id": "00000000-0000-0000-0000-000000000001",
Expand All @@ -27,13 +25,14 @@
}
]
},
"oldValue": {
"data": [
{
"id": "",
"type": "iterations"
}
]
"workItemType": {
"data": {
"id": "00000000-0000-0000-0000-000000000004",
"type": "workitemtypes"
},
"links": {
"self": "http:///api/workitemtypes/00000000-0000-0000-0000-000000000004"
}
}
},
"type": "events"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
"related": "http:///api/users/00000000-0000-0000-0000-000000000002",
"self": "http:///api/users/00000000-0000-0000-0000-000000000002"
}
},
"workItemType": {
"data": {
"id": "00000000-0000-0000-0000-000000000003",
"type": "workitemtypes"
},
"links": {
"self": "http:///api/workitemtypes/00000000-0000-0000-0000-000000000003"
}
}
},
"type": "events"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
"related": "http:///api/users/00000000-0000-0000-0000-000000000002",
"self": "http:///api/users/00000000-0000-0000-0000-000000000002"
}
},
"workItemType": {
"data": {
"id": "00000000-0000-0000-0000-000000000003",
"type": "workitemtypes"
},
"links": {
"self": "http:///api/workitemtypes/00000000-0000-0000-0000-000000000003"
}
}
},
"type": "events"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
{
"attributes": {
"name": "system.labels",
"newValue": null,
"oldValue": null,
"timestamp": "0001-01-01T00:00:00Z"
},
"id": "00000000-0000-0000-0000-000000000001",
Expand All @@ -31,7 +29,15 @@
}
]
},
"oldValue": {}
"workItemType": {
"data": {
"id": "00000000-0000-0000-0000-000000000005",
"type": "workitemtypes"
},
"links": {
"self": "http:///api/workitemtypes/00000000-0000-0000-0000-000000000005"
}
}
},
"type": "events"
}
Expand Down
Loading

0 comments on commit 2c142a8

Please sign in to comment.