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

Commit

Permalink
Migrate to snuyk and orb
Browse files Browse the repository at this point in the history
  • Loading branch information
gkazakov111 authored and bboykov committed Oct 15, 2020
1 parent 4c59ce8 commit 902b29a
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 159 deletions.
69 changes: 16 additions & 53 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,19 @@
version: 2
jobs:
build:
working_directory: /content-collection-unfolder
docker:
- image: golang:1
environment:
GOPATH: /go
CIRCLE_TEST_REPORTS: /tmp/test-results
CIRCLE_COVERAGE_REPORT: /tmp/coverage-results
steps:
- checkout
- run:
name: External Dependencies
command: |
GO111MODULE=off go get github.com/mattn/goveralls
GO111MODULE=off go get github.com/jstemmer/go-junit-report
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.21.0
wget https://raw.githubusercontent.com/Financial-Times/upp-coding-standard/v1.0.0/golangci-config/.golangci.yml
- run:
name: Create Test Folders
command: |
mkdir -p $CIRCLE_TEST_REPORTS
mkdir -p $CIRCLE_COVERAGE_REPORT
- run:
name: Go Build
command: go build -mod=readonly -v
- run:
name: Run linters
command: golangci-lint run --new-from-rev=$(git rev-parse origin/master) --config .golangci.yml
- run:
name: Run Tests
command: go test -mod=readonly -race -cover -coverprofile=${CIRCLE_COVERAGE_REPORT}/coverage.out ./... | go-junit-report > ${CIRCLE_TEST_REPORTS}/junit.xml
- run:
name: Upload Coverage
command: goveralls -coverprofile=${CIRCLE_COVERAGE_REPORT}/coverage.out -service=circle-ci -repotoken=${COVERALLS_TOKEN}
- store_test_results:
path: /tmp/test-results
dockerfile:
working_directory: /content-collection-unfolder
docker:
- image: docker:18
steps:
- checkout
- setup_docker_engine
- run:
name: Build Dockerfile
command: docker build .
version: 2.1

orbs:
ft-golang-ci: financial-times/golang-ci@1

workflows:
version: 2
test-and-build-docker:
tests_and_docker:
jobs:
- build
- dockerfile:
- ft-golang-ci/build-and-test:
name: build-and-test-project
- ft-golang-ci/docker-build:
name: build-docker-image
requires:
- build
- build-and-test-project
snyk-scanning:
jobs:
- ft-golang-ci/scan:
name: scan-dependencies
context: cm-team-snyk
30 changes: 15 additions & 15 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ import (
"strings"
"testing"

"github.com/Financial-Times/transactionid-utils-go"
transactionidutils "github.com/Financial-Times/transactionid-utils-go"
"github.com/stretchr/testify/assert"
)

const (
whitelistedCollection = "content-package"
inputFile = "content-collection.json"
collectionUuid = "45163790-eec9-11e6-abbc-ee7d9c5b3b90"
leadArticleUuid = "ddda0e1c-a9b2-11e7-8e2d-6debe43a48b4"
firstExistingItemUuid = "aaaac4c6-dcc6-11e6-86ac-f253db7791c6"
secondExistingItemUuid = "bbbbc4c6-dcc6-11e6-86ac-f253db7791c6"
deletedItemUuid = "d9b4c4c6-dcc6-11e6-86ac-f253db7791c6"
addedItemUuid = "d4986a58-de3b-11e6-86ac-f253db7791c6"
lastModified = "2017-01-31T15:33:21.687Z"
whitelistedCollection = "content-package"
inputFile = "content-collection.json"
collectionUUID = "45163790-eec9-11e6-abbc-ee7d9c5b3b90"
leadArticleUUID = "ddda0e1c-a9b2-11e7-8e2d-6debe43a48b4"
firstExistingItemUUID = "aaaac4c6-dcc6-11e6-86ac-f253db7791c6"
secondExistingItemUUUID = "bbbbc4c6-dcc6-11e6-86ac-f253db7791c6"
deletedItemUUID = "d9b4c4c6-dcc6-11e6-86ac-f253db7791c6"
addedItemUUUID = "d4986a58-de3b-11e6-86ac-f253db7791c6"
lastModified = "2017-01-31T15:33:21.687Z"
)

func buildRequest(t *testing.T, serverUrl string, collection string, uuid string, body []byte, tid string) *http.Request {
req, err := http.NewRequest(http.MethodPut, serverUrl+buildPath(t, collection, uuid), bytes.NewBuffer(body))
func buildRequest(t *testing.T, serverURL string, collection string, uuid string, body []byte, tid string) *http.Request {
req, err := http.NewRequest(http.MethodPut, serverURL+buildPath(t, collection, uuid), bytes.NewBuffer(body))
assert.NoError(t, err)

req.Header.Add(transactionidutils.TransactionIDHeader, tid)
Expand All @@ -37,10 +37,10 @@ func buildPath(t *testing.T, collectionType string, uuid string) string {
pathWithCollection := strings.Replace(unfolderPath, "{collectionType}", collectionType, 1)
assert.NotEqual(t, unfolderPath, pathWithCollection)

pathWithCollectionAndUuid := strings.Replace(pathWithCollection, "{uuid}", uuid, 1)
assert.NotEqual(t, pathWithCollection, pathWithCollectionAndUuid)
pathWithCollectionAndUUID := strings.Replace(pathWithCollection, "{uuid}", uuid, 1)
assert.NotEqual(t, pathWithCollection, pathWithCollectionAndUUID)

return pathWithCollectionAndUuid
return pathWithCollectionAndUUID
}

func readTestFile(t *testing.T, fileName string) []byte {
Expand Down
4 changes: 2 additions & 2 deletions healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ func (service *healthService) producerChecker() (string, error) {
return service.config.producer.ConnectivityCheck()
}

func (service *healthService) httpAvailabilityChecker(healthUri string) (string, error) {
req, err := http.NewRequest(http.MethodGet, healthUri, nil)
func (service *healthService) httpAvailabilityChecker(healthURI string) (string, error) {
req, err := http.NewRequest(http.MethodGet, healthURI, nil)
if err != nil {
msg := fmt.Sprintf("Error while creating http health check request: %v", err)
return msg, errors.New(msg)
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
res "github.com/Financial-Times/content-collection-unfolder/resolver"
logger "github.com/Financial-Times/go-logger"
"github.com/Financial-Times/message-queue-go-producer/producer"
"github.com/jawher/mow.cli"
cli "github.com/jawher/mow.cli"
)

const (
Expand All @@ -30,7 +30,7 @@ func main() {
app.Action = func() {
logger.Infof("[Startup] content-collection-unfolder is starting with service config %v", sc.toMap())

client := setupHttpClient()
client := setupHTTPClient()
producer := setupMessageProducer(sc, client)

unfolder := newUnfolder(
Expand Down Expand Up @@ -63,7 +63,7 @@ func main() {
}
}

func setupHttpClient() *http.Client {
func setupHTTPClient() *http.Client {
return &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
Expand Down
27 changes: 13 additions & 14 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
res "github.com/Financial-Times/content-collection-unfolder/resolver"
health "github.com/Financial-Times/go-fthealth/v1_1"
"github.com/Financial-Times/message-queue-go-producer/producer"
"github.com/Financial-Times/transactionid-utils-go"
transactionidutils "github.com/Financial-Times/transactionid-utils-go"
"github.com/gorilla/mux"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestEndToEndFlow(t *testing.T) {
unfolderServer := httptest.NewServer(routing.router)
defer unfolderServer.Close()

req := buildRequest(t, unfolderServer.URL, whitelistedCollection, collectionUuid, readTestFile(t, inputFile), tid)
req := buildRequest(t, unfolderServer.URL, whitelistedCollection, collectionUUID, readTestFile(t, inputFile), tid)

resp, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
Expand All @@ -139,9 +139,9 @@ func TestEndToEndFlow(t *testing.T) {

assert.Equal(t, 3, len(messageProducer.received))
allMessages := strings.Join(messageProducer.received, "")
assert.Equal(t, 2, strings.Count(allMessages, addedItemUuid))
assert.Equal(t, 2, strings.Count(allMessages, deletedItemUuid))
assert.Equal(t, 2, strings.Count(allMessages, leadArticleUuid))
assert.Equal(t, 2, strings.Count(allMessages, addedItemUUUID))
assert.Equal(t, 2, strings.Count(allMessages, deletedItemUUID))
assert.Equal(t, 2, strings.Count(allMessages, leadArticleUUID))
}

func notFoundHandler(w http.ResponseWriter, _ *http.Request) {
Expand Down Expand Up @@ -178,9 +178,9 @@ func startContentResolverServer(t *testing.T, healthHandler func(w http.Response
uuidArr := r.URL.Query()["uuid"]

assert.Equal(t, tid, transactionidutils.GetTransactionIDFromRequest(r))
assert.Contains(t, uuidArr, leadArticleUuid)
assert.Contains(t, uuidArr, addedItemUuid)
assert.Contains(t, uuidArr, deletedItemUuid)
assert.Contains(t, uuidArr, leadArticleUUID)
assert.Contains(t, uuidArr, addedItemUUUID)
assert.Contains(t, uuidArr, deletedItemUUID)

contentArr := []map[string]string{}
for _, uuid := range uuidArr {
Expand All @@ -206,11 +206,11 @@ func startRelationsResolverServer(t *testing.T, healthHandler func(w http.Respon

router.HandleFunc(relationsResolverPath, func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, tid, transactionidutils.GetTransactionIDFromRequest(r))
assert.True(t, strings.Contains(r.URL.Path, collectionUuid))
assert.True(t, strings.Contains(r.URL.Path, collectionUUID))

ccRelations := &relations.CCRelations{
ContainedIn: leadArticleUuid,
Contains: []string{firstExistingItemUuid, secondExistingItemUuid, deletedItemUuid},
ContainedIn: leadArticleUUID,
Contains: []string{firstExistingItemUUID, secondExistingItemUUUID, deletedItemUUID},
}

body, err := json.Marshal(ccRelations)
Expand Down Expand Up @@ -245,9 +245,8 @@ func (tp *testProducer) SendMessage(key string, msg producer.Message) error {
func (tp *testProducer) ConnectivityCheck() (string, error) {
if tp.healthy {
return "Ok", nil
} else {
return "", errors.New("Not healthy")
}
return "", errors.New("not healthy")
}

func startRouting(
Expand All @@ -256,7 +255,7 @@ func startRouting(
relationsResolverServer *httptest.Server,
messageProducer *testProducer) *routing {

client := setupHttpClient()
client := setupHTTPClient()
hc := &healthConfig{
appDesc: serviceDescription,
port: "8080",
Expand Down
2 changes: 1 addition & 1 deletion resolver/uuidResolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestInvalidLastModified(t *testing.T) {
assert.Error(t, err)
}

func TestInvalidUuid(t *testing.T) {
func TestInvalidUUID(t *testing.T) {
ccBytes := readTestFile(t, "content-collection-invalid-uuid.json")

r := NewUuidResolver()
Expand Down
Loading

0 comments on commit 902b29a

Please sign in to comment.