Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lint CI + replace travis with GH workflow #150

Merged
merged 4 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/golang-ci-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Golang CI Workflow

on: push

jobs:
ci:
name: golang-ci
runs-on: ubuntu-latest
env:
COVERAGE_PROFILE_OUTPUT_LOCATION: "./profile.cov"
PGDATABASE: arborist_test
PGUSER: postgres
PGPASSWORD: postgres
PGHOST: localhost
PGPORT: 5432
PGSSLMODE: disable
services:
postgres:
image: postgres:9.6
env:
POSTGRES_DB: ${{ env.PGDATABASE }}
POSTGRES_USER: ${{ env.PGUSER }}
POSTGRES_PASSWORD: ${{ env.PGPASSWORD }}
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Setup database
shell: bash
run: ./migrations/latest
- name: Run tests, lint code, install goveralls
uses: uc-cdis/.github/.github/actions/golang-ci@master
with:
GO_VERSION: "1.17"
TESTS_LOCATION: ./arborist/
COVERAGE_PROFILE_OUTPUT_LOCATION: ${{ env.COVERAGE_PROFILE_OUTPUT_LOCATION }}
- name: Send coverage to coveralls using goveralls
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goveralls -coverprofile=${{ env.COVERAGE_PROFILE_OUTPUT_LOCATION }} -service=github
38 changes: 0 additions & 38 deletions .github/workflows/golangci-lint.yml

This file was deleted.

13 changes: 13 additions & 0 deletions .github/workflows/image_build_push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Build and Push Image

on: push

jobs:
ci:
name: Build and Push Image
uses: uc-cdis/.github/.github/workflows/image_build_push.yaml@master
secrets:
ECR_AWS_ACCESS_KEY_ID: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }}
ECR_AWS_SECRET_ACCESS_KEY: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }}
QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }}
QUAY_ROBOT_TOKEN: ${{ secrets.QUAY_ROBOT_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*.dll
*.so
*.dylib
bin/

# Test binary, built with `go test -c`
*.test
Expand Down
32 changes: 0 additions & 32 deletions .travis.yml

This file was deleted.

4 changes: 0 additions & 4 deletions arborist/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import (
"net/http"
)

type responseJSON interface {
write(w http.ResponseWriter, r *http.Request) error
}

type jsonResponse struct {
content interface{}
code int
Expand Down
76 changes: 47 additions & 29 deletions arborist/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,16 @@ func TestServer(t *testing.T) {
return result
}

getTagForResource := func(path string) string {
getTagForResource := func(path string) (string, error) {
var tags []string
db.Select(&tags, "SELECT tag FROM resource WHERE path = $1", arborist.FormatPathForDb(path))
err := db.Select(&tags, "SELECT tag FROM resource WHERE path = $1", arborist.FormatPathForDb(path))
if err != nil {
return "", err
}
if len(tags) == 0 {
return ""
return "", nil
}
return tags[0]
return tags[0], nil
}

createRoleBytes := func(t *testing.T, body []byte) {
Expand All @@ -371,7 +374,7 @@ func TestServer(t *testing.T) {
httpError(t, w, "couldn't create policy")
}
result := struct {
_ interface{} `json:"created"`
I interface{} `json:"created"`
}{}
err = json.Unmarshal(w.Body.Bytes(), &result)
if err != nil {
Expand All @@ -387,7 +390,7 @@ func TestServer(t *testing.T) {
httpError(t, w, "couldn't create group")
}
result := struct {
_ interface{} `json:"created"`
I interface{} `json:"created"`
}{}
err = json.Unmarshal(w.Body.Bytes(), &result)
if err != nil {
Expand Down Expand Up @@ -930,7 +933,7 @@ func TestServer(t *testing.T) {
httpError(t, w, "couldn't create resource")
}
expected := struct {
_ interface{} `json:"created"`
I interface{} `json:"created"`
}{}
err = json.Unmarshal(w.Body.Bytes(), &expected)
if err != nil {
Expand All @@ -956,7 +959,7 @@ func TestServer(t *testing.T) {
httpError(t, w, "couldn't create resource")
}
expected := struct {
_ interface{} `json:"created"`
I interface{} `json:"created"`
}{}
err = json.Unmarshal(w.Body.Bytes(), &expected)
if err != nil {
Expand Down Expand Up @@ -1001,7 +1004,7 @@ func TestServer(t *testing.T) {
httpError(t, w, "couldn't create resource")
}
expected = struct {
_ interface{} `json:"created"`
I interface{} `json:"created"`
}{}
err = json.Unmarshal(w.Body.Bytes(), &expected)
if err != nil {
Expand Down Expand Up @@ -1076,14 +1079,20 @@ func TestServer(t *testing.T) {
httpError(t, w, "couldn't create resource using PUT")
}
expected := struct {
_ interface{} `json:"created"`
I interface{} `json:"created"`
}{}
err = json.Unmarshal(w.Body.Bytes(), &expected)
if err != nil {
httpError(t, w, "couldn't read response from resource creation")
}
escherTag := getTagForResource("Godel.Escher")
bachTag := getTagForResource("Godel.Escher.Bach")
escherTag, err := getTagForResource("Godel.Escher")
if err != nil {
httpError(t, w, "couldn't get tag for resource Godel.Escher")
}
bachTag, err := getTagForResource("Godel.Escher.Bach")
if err != nil {
httpError(t, w, "couldn't get tag for resource Godel.Escher.Bach")
}
// now PUT over the same resource, but keep the subresources
w = httptest.NewRecorder()
body = []byte(`{
Expand All @@ -1098,8 +1107,14 @@ func TestServer(t *testing.T) {
if w.Code != http.StatusCreated {
httpError(t, w, "couldn't update resource using PUT")
}
newEscherTag := getTagForResource("Godel.Escher")
newBachTag := getTagForResource("Godel.Escher.Bach")
newEscherTag, err := getTagForResource("Godel.Escher")
if err != nil {
httpError(t, w, "couldn't get tag for resource Godel.Escher")
}
newBachTag, err := getTagForResource("Godel.Escher.Bach")
if err != nil {
httpError(t, w, "couldn't get tag for resource Godel.Escher.Bach")
}
assert.Equal(t, escherTag, newEscherTag, "subresource tag changed after PUT")
assert.Equal(t, bachTag, newBachTag, "subresource tag changed after PUT")
getResourceWithPath(t, "/Godel,/completeness_theorem")
Expand Down Expand Up @@ -1207,7 +1222,7 @@ func TestServer(t *testing.T) {
}
// make one-off struct to read the response into
result := struct {
_ interface{} `json:"created"`
I interface{} `json:"created"`
}{}
err = json.Unmarshal(w.Body.Bytes(), &result)
if err != nil {
Expand All @@ -1229,7 +1244,7 @@ func TestServer(t *testing.T) {
}
// make one-off struct to read the response into
result := struct {
_ interface{} `json:"created"`
I interface{} `json:"created"`
}{}
err = json.Unmarshal(w.Body.Bytes(), &result)
if err != nil {
Expand Down Expand Up @@ -1296,7 +1311,7 @@ func TestServer(t *testing.T) {
}
// make one-off struct to read the response into
result := struct {
_ interface{} `json:"updated"`
I interface{} `json:"updated"`
}{}
err = json.Unmarshal(w.Body.Bytes(), &result)
if err != nil {
Expand Down Expand Up @@ -1425,7 +1440,7 @@ func TestServer(t *testing.T) {
httpError(t, w, "couldn't create policy")
}
result := struct {
_ interface{} `json:"created"`
I interface{} `json:"created"`
}{}
err = json.Unmarshal(w.Body.Bytes(), &result)
if err != nil {
Expand Down Expand Up @@ -1507,7 +1522,7 @@ func TestServer(t *testing.T) {
}
result := struct {
Policies struct {
policy []string `json:"policy"`
Policy []string `json:"policy"`
}
}{}
err = json.Unmarshal(w.Body.Bytes(), &result)
Expand Down Expand Up @@ -1690,7 +1705,7 @@ func TestServer(t *testing.T) {
httpError(t, w, "couldn't create user")
}
result := struct {
_ interface{} `json:"created"`
I interface{} `json:"created"`
}{}
err = json.Unmarshal(w.Body.Bytes(), &result)
if err != nil {
Expand Down Expand Up @@ -2211,7 +2226,7 @@ func TestServer(t *testing.T) {
httpError(t, w, "couldn't create client")
}
result := struct {
_ interface{} `json:"created"`
I interface{} `json:"created"`
}{}
err = json.Unmarshal(w.Body.Bytes(), &result)
if err != nil {
Expand Down Expand Up @@ -2402,7 +2417,7 @@ func TestServer(t *testing.T) {
httpError(t, w, "couldn't create group")
}
result := struct {
_ interface{} `json:"created"`
I interface{} `json:"created"`
}{}
err = json.Unmarshal(w.Body.Bytes(), &result)
if err != nil {
Expand Down Expand Up @@ -2825,7 +2840,7 @@ func TestServer(t *testing.T) {
result := struct {
Name string `json:"name"`
Users []string `json:"users"`
_ []string `json:"policies"`
P []string `json:"policies"`
}{}
err = json.Unmarshal(w.Body.Bytes(), &result)
if err != nil {
Expand Down Expand Up @@ -3129,7 +3144,10 @@ func TestServer(t *testing.T) {

t.Run("Tag", func(t *testing.T) {
w := httptest.NewRecorder()
tag := getTagForResource(resourcePath)
tag, err := getTagForResource(resourcePath)
if err != nil {
httpError(t, w, "couldn't get tag for resource")
}
body := []byte(fmt.Sprintf(
`{
"user": {"token": "%s"},
Expand Down Expand Up @@ -3806,7 +3824,7 @@ func TestServer(t *testing.T) {
if err != nil {
httpError(t, w, "couldn't read response from auth resources")
}
msg = fmt.Sprintf("got response body: %s", w.Body.String())
fmt.Printf("got response body: %s", w.Body.String())
expectedTags := make([]string, 0)
for _, resourcePath := range expectedResources {
resource := getResourceWithPath(t, resourcePath)
Expand Down Expand Up @@ -3858,7 +3876,7 @@ func TestServer(t *testing.T) {
if err != nil {
httpError(t, w, "couldn't read response from auth resources")
}
msg = fmt.Sprintf("got response body: %s", w.Body.String())
fmt.Printf("got response body: %s", w.Body.String())
expectedTags := make([]string, 0)
for _, resourcePath := range expectedResources {
resource := getResourceWithPath(t, resourcePath)
Expand Down Expand Up @@ -3906,7 +3924,7 @@ func TestServer(t *testing.T) {
if err != nil {
httpError(t, w, "couldn't read response from auth resources")
}
msg = fmt.Sprintf("got response body: %s", w.Body.String())
fmt.Printf("got response body: %s", w.Body.String())
anonymousTags := make([]string, 0)
for _, resourcePath := range anonymousResourcePaths {
resource := getResourceWithPath(t, resourcePath)
Expand Down Expand Up @@ -3982,7 +4000,7 @@ func TestServer(t *testing.T) {
if err != nil {
httpError(t, w, "couldn't read response from auth resources")
}
msg = fmt.Sprintf("got response body: %s", w.Body.String())
fmt.Printf("got response body: %s", w.Body.String())
expectedTags := make([]string, 0)
for _, resourcePath := range expectedResources {
resource := getResourceWithPath(t, resourcePath)
Expand Down Expand Up @@ -4033,7 +4051,7 @@ func TestServer(t *testing.T) {
if err != nil {
httpError(t, w, "couldn't read response from auth resources")
}
msg = fmt.Sprintf("got response body: %s", w.Body.String())
fmt.Printf("got response body: %s", w.Body.String())
expectedTags := make([]string, 0)
for _, resourcePath := range expectedResources {
resource := getResourceWithPath(t, resourcePath)
Expand Down
Loading