mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-03-28 15:15:32 +00:00
Fix tests and pipeline (#732)
* fix pipeline * use EqualStringSlice to compare slices in tests * full test coverage * tests: wait for mysql/postgres to sync ...
This commit is contained in:
parent
6d29651808
commit
071bd7418a
7 changed files with 84 additions and 2 deletions
|
@ -103,6 +103,16 @@ pipeline:
|
|||
commands:
|
||||
- ls -la dist/*.*
|
||||
- cat dist/checksums.txt
|
||||
when:
|
||||
path:
|
||||
# related config files
|
||||
- ".woodpecker/binaries.yml"
|
||||
- "nfpm/*.yml"
|
||||
# go source code
|
||||
- "**/*.go"
|
||||
- "go.*"
|
||||
# web source code
|
||||
- "web/**"
|
||||
|
||||
release:
|
||||
image: plugins/github-release
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
|
||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||
"github.com/woodpecker-ci/woodpecker/server/remote/gitea/fixtures"
|
||||
"github.com/woodpecker-ci/woodpecker/shared/utils"
|
||||
)
|
||||
|
||||
func Test_parse(t *testing.T) {
|
||||
|
@ -106,7 +107,7 @@ func Test_parse(t *testing.T) {
|
|||
g.Assert(build.Message).Equal(hook.Commits[0].Message)
|
||||
g.Assert(build.Avatar).Equal("http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87")
|
||||
g.Assert(build.Author).Equal(hook.Sender.Login)
|
||||
g.Assert(build.ChangedFiles).Equal([]string{"CHANGELOG.md", "app/controller/application.rb"})
|
||||
g.Assert(utils.EqualStringSlice(build.ChangedFiles, []string{"CHANGELOG.md", "app/controller/application.rb"})).IsTrue()
|
||||
})
|
||||
|
||||
g.It("Should return a Repo struct from a push hook", func() {
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
|
||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||
"github.com/woodpecker-ci/woodpecker/server/remote/gitea/fixtures"
|
||||
"github.com/woodpecker-ci/woodpecker/shared/utils"
|
||||
)
|
||||
|
||||
func Test_parser(t *testing.T) {
|
||||
|
@ -49,7 +50,7 @@ func Test_parser(t *testing.T) {
|
|||
g.Assert(r).IsNotNil()
|
||||
g.Assert(b).IsNotNil()
|
||||
g.Assert(b.Event).Equal(model.EventPush)
|
||||
g.Assert(b.ChangedFiles).Equal([]string{"CHANGELOG.md", "app/controller/application.rb"})
|
||||
g.Assert(utils.EqualStringSlice(b.ChangedFiles, []string{"CHANGELOG.md", "app/controller/application.rb"})).IsTrue()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -17,8 +17,10 @@ package datastore
|
|||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/schemas"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -67,5 +69,11 @@ func newTestStore(t *testing.T, tables ...interface{}) (*storage, func()) {
|
|||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
dbType := engine.Dialect().URI().DBType
|
||||
if dbType == schemas.MYSQL || dbType == schemas.POSTGRES {
|
||||
// wait for mysql/postgres to sync ...
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,11 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/schemas"
|
||||
|
||||
// blank imports to register the sql drivers
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
|
@ -84,6 +86,12 @@ func TestMigrate(t *testing.T) {
|
|||
assert.NoError(t, Migrate(engine))
|
||||
close()
|
||||
|
||||
dbType := engine.Dialect().URI().DBType
|
||||
if dbType == schemas.MYSQL || dbType == schemas.POSTGRES {
|
||||
// wait for mysql/postgres to sync ...
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
|
||||
// migrate old db
|
||||
engine, close = testDB(t, false)
|
||||
assert.NoError(t, Migrate(engine))
|
||||
|
|
|
@ -30,3 +30,29 @@ func DedupStrings(list []string) []string {
|
|||
}
|
||||
return newList
|
||||
}
|
||||
|
||||
// EqualStringSlice compare two string slices if they have equal values independ of how they are sorted
|
||||
func EqualStringSlice(l1, l2 []string) bool {
|
||||
if len(l1) != len(l2) {
|
||||
return false
|
||||
}
|
||||
|
||||
m1 := sliceToCountMap(l1)
|
||||
m2 := sliceToCountMap(l2)
|
||||
|
||||
for k, v := range m1 {
|
||||
if m2[k] != v {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func sliceToCountMap(list []string) map[string]int {
|
||||
m := make(map[string]int)
|
||||
for i := range list {
|
||||
m[list[i]]++
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
|
|
@ -46,3 +46,31 @@ func TestDedupStrings(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEqualStringSlice(t *testing.T) {
|
||||
tests := []struct {
|
||||
in1 []string
|
||||
in2 []string
|
||||
out bool
|
||||
}{{
|
||||
in1: []string{"", "ab", "12", "ab"},
|
||||
in2: []string{"12", "ab"},
|
||||
out: false,
|
||||
}, {
|
||||
in1: nil,
|
||||
in2: nil,
|
||||
out: true,
|
||||
}, {
|
||||
in1: []string{"AA", "AA", "2", " "},
|
||||
in2: []string{"2", "AA", " ", "AA"},
|
||||
out: true,
|
||||
}, {
|
||||
in1: []string{"AA", "AA", "2", " "},
|
||||
in2: []string{"2", "2", " ", "AA"},
|
||||
out: false,
|
||||
}}
|
||||
|
||||
for _, tc := range tests {
|
||||
assert.EqualValues(t, tc.out, EqualStringSlice(tc.in1, tc.in2), "could not correctly process input: '%#v', %#v", tc.in1, tc.in2)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue