Skip to content

Commit

Permalink
Merge pull request #319 from dictyBase/feat/geneid-test
Browse files Browse the repository at this point in the history
Auto-generated Pull Request for feat/geneid-test
  • Loading branch information
kodiakhq[bot] authored Nov 13, 2024
2 parents f676e99 + 79de3b7 commit 9739206
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: set up golang
uses: actions/setup-go@v5
with:
go-version: '~1.22'
go-version: 1.22
- run: go version
- name: unit test
run: go test -covermode=atomic -coverprofile=profile.cov -v ./...
Expand Down
18 changes: 5 additions & 13 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,8 @@ on:
branches-ignore:
- master
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: check out code
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.20.6
cache: false
- name: run linter
uses: golangci/golangci-lint-action@v6
with:
version: v1.52.2
call-lint:
uses: dictyBase/workflows/.github/workflows/golang-lint.yaml@develop
with:
repository: ${{ github.repository }}
ref: ${{ github.event.pull_request.head.sha }}
4 changes: 2 additions & 2 deletions .github/workflows/testcov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
runs-on: ubuntu-latest
services:
arangodb:
image: arangodb:3.10.9
image: arangodb:3.11
env:
ARANGO_ROOT_PASSWORD: rootpass
ports:
Expand All @@ -14,7 +14,7 @@ jobs:
- name: set up golang
uses: actions/setup-go@v5
with:
go-version: '~1.20.6'
go-version: 1.22
- name: check out code
uses: actions/checkout@v4
- name: unit test
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
cover.out
cover.out
.aider*
.env
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ linters:
- bodyclose
- bidichk
- cyclop
- depguard
- decorder
- dogsled
# - dupl
- errcheck
- funlen
- goconst
Expand Down
2 changes: 2 additions & 0 deletions CONVENTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- use at least three letters variable names
- use fmt.Sprintf for string concatenation
10 changes: 10 additions & 0 deletions dagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "modware-import",
"dependencies": [
{
"name": "golang",
"source": "github.com/dictybase-docker/dagger-of-dcr/golang@aa46f8610edad8ecfb0776e4c9fe85a486da87eb"
}
],
"engineVersion": "v0.11.9"
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

go 1.21
go 1.22

toolchain go1.22.5
4 changes: 2 additions & 2 deletions internal/app/service/strain.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ func (s *StockService) UpdateStrain(
}

// ListStrainsByIds gets a list of strains from a list of strain identifiers
func (s *StockService) ListStrainsByIds(
func (s *StockService) ListStrainsByIDs(
ctx context.Context,
r *stock.StockIdList,
) (*stock.StrainList, error) {
sl := &stock.StrainList{}
if err := r.Validate(); err != nil {
return sl, aphgrpc.HandleInvalidParamError(ctx, err)
}
mc, err := s.repo.ListStrainsByIds(r)
mc, err := s.repo.ListStrainsByIDs(r)
if err != nil {
return sl, aphgrpc.HandleGetError(ctx, err)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/repository/arangodb/plasmid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func TestListPlasmidsWithFilter(t *testing.T) {
)
_, err := repo.AddPlasmid(np)
assert.NoErrorf(err, "expect no error, received %s", err)
time.Sleep(100 * time.Millisecond)
}
sf, err := repo.ListPlasmids(
&stock.StockParameters{Limit: 10, Filter: georgeFilter},
Expand Down Expand Up @@ -176,6 +177,7 @@ func TestListPlasmids(t *testing.T) {
)
_, err := repo.AddPlasmid(np)
assert.NoErrorf(err, "expect no error adding plasmid, received %s", err)
time.Sleep(100 * time.Millisecond)
}
ls, err := repo.ListPlasmids(&stock.StockParameters{Limit: 4})
assert.NoErrorf(
Expand Down
2 changes: 1 addition & 1 deletion internal/repository/arangodb/statement/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const (
FOR stock_prop,e IN 1..1 INBOUND @strain_key GRAPH @parent_graph
RETURN e._key
`
StrainListFromIds = `
StrainListFromIDs = `
FOR id IN @ids
FOR stock_prop, e IN 1..1 OUTBOUND CONCAT(@stock_collection,"/",id) GRAPH @stock_prop_graph
LET parent = (
Expand Down
4 changes: 2 additions & 2 deletions internal/repository/arangodb/strain_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ func (ar *arangorepository) ListStrains(
return omd, nil
}

func (ar *arangorepository) ListStrainsByIds(
func (ar *arangorepository) ListStrainsByIDs(
p *stock.StockIdList,
) ([]*model.StockDoc, error) {
ms := make([]*model.StockDoc, 0)
rs, err := ar.database.SearchRows(
statement.StrainListFromIds,
statement.StrainListFromIDs,
map[string]interface{}{
"ids": p.Id,
"limit": len(p.Id),
Expand Down
56 changes: 52 additions & 4 deletions internal/repository/arangodb/strain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import (
)

const (
filterGene = `FILTER 'DDB_G0287317' IN s.genes`
filterGeneMore = `FILTER 'DDB_G098058933' IN s.genes`

filterOne = `FILTER s.depositor == '[email protected]'`
filterTwo = `FILTER s.depositor == '[email protected]'
AND s.depositor == '[email protected]'
Expand Down Expand Up @@ -92,6 +95,7 @@ func createTestStrainsWithIDs(
if err != nil {
return ids, err
}
time.Sleep(100 * time.Millisecond)
ids = append(ids, nps.StockID)
start++
}
Expand All @@ -116,6 +120,7 @@ func createTestStrains(
if err != nil {
return err
}
time.Sleep(100 * time.Millisecond)
start++
}
return nil
Expand Down Expand Up @@ -512,15 +517,15 @@ func TestListStrains(t *testing.T) {
testModelListSort(ls3, t)
}

func TestListStrainsByIds(t *testing.T) {
func TestListStrainsByIDs(t *testing.T) {
t.Parallel()
assert, repo := setUp(t)
defer tearDown(repo)
// add 10 new test strains
ids, err := createTestStrainsWithIDs(30, General, repo)
assert.NoError(err, "expect no error from creating strains")
// get first five results
ls, err := repo.ListStrainsByIds(&stock.StockIdList{Id: ids})
ls, err := repo.ListStrainsByIDs(&stock.StockIdList{Id: ids})
assert.NoError(err, "expect no error in getting strains")
assert.Len(ls, 30, "should match the provided limit number")
for _, stock := range ls {
Expand Down Expand Up @@ -554,7 +559,7 @@ func TestListStrainsByIds(t *testing.T) {
)
pids, err := createTestStrainsWithParent(30, General, repo, pm.StockID)
assert.NoError(err, "expect no error from creating strains")
pls, err := repo.ListStrainsByIds(&stock.StockIdList{Id: pids})
pls, err := repo.ListStrainsByIDs(&stock.StockIdList{Id: pids})
assert.NoError(err, "expect no error in getting 30 stocks with parents")
assert.Len(pls, 30, "should match the provided limit number")
for _, stock := range pls {
Expand All @@ -581,7 +586,7 @@ func TestListStrainsByIds(t *testing.T) {
)
}
// Non-existing ids
els, err := repo.ListStrainsByIds(
els, err := repo.ListStrainsByIDs(
&stock.StockIdList{Id: []string{"DBN589343", "DBN48473232"}},
)
assert.NoErrorf(
Expand Down Expand Up @@ -909,6 +914,49 @@ func TestEditStrain(t *testing.T) {
)
}

func TestListStrainsWithGeneFilter(t *testing.T) {
t.Parallel()
assert, repo := setUp(t)
defer tearDown(repo)
// Create test strain with specific gene
ns := newTestStrain("[email protected]", General)
ns.Data.Attributes.Genes = []string{"DDB_G0287317", "DDB_G0287318"}
_, err := repo.AddStrain(ns)
assert.NoError(err, "expect no error from creating strain with genes")

// Create additional strains without the specific gene
err = createTestStrains(5, General, repo)
assert.NoError(err, "expect no error from creating additional strains")

// Test filtering by gene
ls, err := repo.ListStrains(&stock.StockParameters{
Limit: 10,
Filter: filterGene,
})
assert.NoError(err, "expect no error in getting strains filtered by gene")
assert.Len(ls, 1, "should find exactly one strain with the specific gene")
assert.Contains(
ls[0].Genes,
"DDB_G0287317",
"returned strain should contain the filtered gene",
)
ls2, err := repo.ListStrains(&stock.StockParameters{
Limit: 10,
Filter: filterGeneMore,
})
assert.NoError(err, "expect no error in getting strains filtered by gene")
assert.Len(
ls2,
5,
"should find exactly five strains with the specific gene",
)
assert.Contains(
ls2[1].Genes,
"DDB_G098058933",
"returned strain should contain the filtered gene",
)
}

func TestEditStrainWithParent(t *testing.T) {
t.Parallel()
assert, repo := setUp(t)
Expand Down
2 changes: 1 addition & 1 deletion internal/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type StockRepository interface {
EditStrain(us *stock.StrainUpdate) (*model.StockDoc, error)
EditPlasmid(us *stock.PlasmidUpdate) (*model.StockDoc, error)
ListStrains(s *stock.StockParameters) ([]*model.StockDoc, error)
ListStrainsByIds(s *stock.StockIdList) ([]*model.StockDoc, error)
ListStrainsByIDs(s *stock.StockIdList) ([]*model.StockDoc, error)
ListPlasmids(s *stock.StockParameters) ([]*model.StockDoc, error)
LoadStrain(id string, es *stock.ExistingStrain) (*model.StockDoc, error)
LoadPlasmid(id string, ep *stock.ExistingPlasmid) (*model.StockDoc, error)
Expand Down

0 comments on commit 9739206

Please sign in to comment.