mirror of
https://github.com/Luzifer/duplicity-backup.git
synced 2024-12-20 18:41:21 +00:00
Convert old vendoring to go modules
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
6d3e516903
commit
fe558f1525
597 changed files with 160 additions and 404040 deletions
246
Gopkg.lock
generated
246
Gopkg.lock
generated
|
@ -1,246 +0,0 @@
|
||||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
|
||||||
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:34e09c50d26400b5e70ade7e041edb75b6aea1b1af428a8d608772555e1bbf92"
|
|
||||||
name = "github.com/Luzifer/go_helpers"
|
|
||||||
packages = [
|
|
||||||
"str",
|
|
||||||
"which",
|
|
||||||
]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "c3bea85c97943065c31d13b2193a9ef8c8488fb2"
|
|
||||||
version = "v2.8.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:f6cc072a289a686fda22819d871cd1b0407640141b2f6616dfbab957c96bf6c3"
|
|
||||||
name = "github.com/Luzifer/rconfig"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "5b80190bff90ccb9899db31e45baac7b1bede03b"
|
|
||||||
version = "v2.2.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:5a23cd3a5496a0b2da7e3b348d14e77b11a210738c398200d7d6f04ea8cf3bd8"
|
|
||||||
name = "github.com/asaskevich/govalidator"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "ccb8e960c48f04d6935e72476ae4a51028f9e22f"
|
|
||||||
version = "v9"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
digest = "1:8d485687c449a7db7d4e8e1d6526036fe38e433232416010fe3970c929134073"
|
|
||||||
name = "github.com/hpcloud/tail"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"ratelimiter",
|
|
||||||
"util",
|
|
||||||
"watch",
|
|
||||||
"winfile",
|
|
||||||
]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "a1dbeea552b7c8df4b542c66073e393de198a800"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:4059c14e87a2de3a434430340521b5feece186c1469eff0834c29a63870de3ed"
|
|
||||||
name = "github.com/konsorten/go-windows-terminal-sequences"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "5c8c8bd35d3832f5d134ae1e1e375b69a4d25242"
|
|
||||||
version = "v1.0.1"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:a4df73029d2c42fabcb6b41e327d2f87e685284ec03edf76921c267d9cfc9c23"
|
|
||||||
name = "github.com/mitchellh/go-homedir"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "ae18d6b8b3205b561c79e8e5f69bff09736185f4"
|
|
||||||
version = "v1.0.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
digest = "1:26217ee135b8157549e648efe97dff3282e4bd597a912d784db964df41067f29"
|
|
||||||
name = "github.com/nightlyone/lockfile"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "0ad87eef1443f64d3d8c50da647e2b1552851124"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:0be1cd4c73d5e22a30edcf32a18e9809a370a7a4a52c4f41a86070b34da93fef"
|
|
||||||
name = "github.com/onsi/ginkgo"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"config",
|
|
||||||
"internal/codelocation",
|
|
||||||
"internal/containernode",
|
|
||||||
"internal/failer",
|
|
||||||
"internal/leafnodes",
|
|
||||||
"internal/remote",
|
|
||||||
"internal/spec",
|
|
||||||
"internal/spec_iterator",
|
|
||||||
"internal/specrunner",
|
|
||||||
"internal/suite",
|
|
||||||
"internal/testingtproxy",
|
|
||||||
"internal/writer",
|
|
||||||
"reporters",
|
|
||||||
"reporters/stenographer",
|
|
||||||
"reporters/stenographer/support/go-colorable",
|
|
||||||
"reporters/stenographer/support/go-isatty",
|
|
||||||
"types",
|
|
||||||
]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "3774a09d95489ccaa16032e0770d08ea77ba6184"
|
|
||||||
version = "v1.6.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:95f40a9db820078d1795c7ba2d476016aca05dc4267eaf6752a925e437cb351f"
|
|
||||||
name = "github.com/onsi/gomega"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"format",
|
|
||||||
"internal/assertion",
|
|
||||||
"internal/asyncassertion",
|
|
||||||
"internal/oraclematcher",
|
|
||||||
"internal/testingtsupport",
|
|
||||||
"matchers",
|
|
||||||
"matchers/support/goraph/bipartitegraph",
|
|
||||||
"matchers/support/goraph/edge",
|
|
||||||
"matchers/support/goraph/node",
|
|
||||||
"matchers/support/goraph/util",
|
|
||||||
"types",
|
|
||||||
]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "7615b9433f86a8bdf29709bf288bc4fd0636a369"
|
|
||||||
version = "v1.4.2"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:ffe8353de82ab7608fc1fd9a246e71b231af2479727dd165e3720cc2e8918177"
|
|
||||||
name = "github.com/rifflock/lfshook"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "b9218ef580f59a2e72dad1aa33d660150445d05a"
|
|
||||||
version = "v2.4"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:01252cd79aac70f16cac02a72a1067dd136e0ad6d5b597d0129cf74c739fd8d1"
|
|
||||||
name = "github.com/sirupsen/logrus"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "a67f783a3814b8729bd2dac5780b5f78f8dbd64d"
|
|
||||||
version = "v1.1.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:9d8420bbf131d1618bde6530af37c3799340d3762cc47210c1d9532a4c3a2779"
|
|
||||||
name = "github.com/spf13/pflag"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "298182f68c66c05229eb03ac171abe6e309ee79a"
|
|
||||||
version = "v1.0.3"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
digest = "1:3f3a05ae0b95893d90b9b3b5afdb79a9b3d96e4e36e099d841ae602e4aca0da8"
|
|
||||||
name = "golang.org/x/crypto"
|
|
||||||
packages = ["ssh/terminal"]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "e3636079e1a4c1f337f212cc5cd2aca108f6c900"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
digest = "1:5193d913046443e59093d66a97a40c51f4a5ea4ceba60f3b3ecf89694de5d16f"
|
|
||||||
name = "golang.org/x/net"
|
|
||||||
packages = [
|
|
||||||
"html",
|
|
||||||
"html/atom",
|
|
||||||
"html/charset",
|
|
||||||
]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "146acd28ed5894421fb5aac80ca93bc1b1f46f87"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
digest = "1:68ca1f18d986adc1d25a28aa732806ee8f1c874cc5b606e4ba67ddd3eeb89e20"
|
|
||||||
name = "golang.org/x/sys"
|
|
||||||
packages = [
|
|
||||||
"unix",
|
|
||||||
"windows",
|
|
||||||
]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "4497e2df6f9e69048a54498c7affbbec3294ad47"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:7c61a813b250ba8bb02bebb0382e6c3d00e04da2b577dc58985b86312fb89ffd"
|
|
||||||
name = "golang.org/x/text"
|
|
||||||
packages = [
|
|
||||||
"encoding",
|
|
||||||
"encoding/charmap",
|
|
||||||
"encoding/htmlindex",
|
|
||||||
"encoding/internal",
|
|
||||||
"encoding/internal/identifier",
|
|
||||||
"encoding/japanese",
|
|
||||||
"encoding/korean",
|
|
||||||
"encoding/simplifiedchinese",
|
|
||||||
"encoding/traditionalchinese",
|
|
||||||
"encoding/unicode",
|
|
||||||
"internal/gen",
|
|
||||||
"internal/tag",
|
|
||||||
"internal/utf8internal",
|
|
||||||
"language",
|
|
||||||
"runes",
|
|
||||||
"transform",
|
|
||||||
"unicode/cldr",
|
|
||||||
]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
|
|
||||||
version = "v0.3.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:1b91ae0dc69a41d4c2ed23ea5cffb721ea63f5037ca4b81e6d6771fbb8f45129"
|
|
||||||
name = "gopkg.in/fsnotify/fsnotify.v1"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9"
|
|
||||||
version = "v1.4.7"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:63119d850a4a2aea8370aa74537a7d50923131ed207fc9aa12ddaf0b9ee94773"
|
|
||||||
name = "gopkg.in/tomb.v1"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "c131134a1947e9afd9cecfe11f4c6dff0732ae58"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "v2"
|
|
||||||
digest = "1:1ab6db2d2bd353449c5d1e976ba7a92a0ece6e83aaab3e6674f8f2f1faebb85a"
|
|
||||||
name = "gopkg.in/validator.v2"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "135c24b11c19e52befcae2ec3fca5d9b78c4e98e"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:7c95b35057a0ff2e19f707173cc1a947fa43a6eb5c4d300d196ece0334046082"
|
|
||||||
name = "gopkg.in/yaml.v2"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "NUT"
|
|
||||||
revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183"
|
|
||||||
version = "v2.2.1"
|
|
||||||
|
|
||||||
[solve-meta]
|
|
||||||
analyzer-name = "dep"
|
|
||||||
analyzer-version = 1
|
|
||||||
input-imports = [
|
|
||||||
"github.com/Luzifer/go_helpers/str",
|
|
||||||
"github.com/Luzifer/go_helpers/which",
|
|
||||||
"github.com/Luzifer/rconfig",
|
|
||||||
"github.com/asaskevich/govalidator",
|
|
||||||
"github.com/mitchellh/go-homedir",
|
|
||||||
"github.com/nightlyone/lockfile",
|
|
||||||
"github.com/onsi/ginkgo",
|
|
||||||
"github.com/onsi/gomega",
|
|
||||||
"github.com/rifflock/lfshook",
|
|
||||||
"github.com/sirupsen/logrus",
|
|
||||||
"gopkg.in/yaml.v2",
|
|
||||||
]
|
|
||||||
solver-name = "gps-cdcl"
|
|
||||||
solver-version = 1
|
|
67
Gopkg.toml
67
Gopkg.toml
|
@ -1,67 +0,0 @@
|
||||||
# Gopkg.toml example
|
|
||||||
#
|
|
||||||
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
|
|
||||||
# for detailed Gopkg.toml documentation.
|
|
||||||
#
|
|
||||||
# required = ["github.com/user/thing/cmd/thing"]
|
|
||||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
|
||||||
#
|
|
||||||
# [[constraint]]
|
|
||||||
# name = "github.com/user/project"
|
|
||||||
# version = "1.0.0"
|
|
||||||
#
|
|
||||||
# [[constraint]]
|
|
||||||
# name = "github.com/user/project2"
|
|
||||||
# branch = "dev"
|
|
||||||
# source = "github.com/myfork/project2"
|
|
||||||
#
|
|
||||||
# [[override]]
|
|
||||||
# name = "github.com/x/y"
|
|
||||||
# version = "2.4.0"
|
|
||||||
#
|
|
||||||
# [prune]
|
|
||||||
# non-go = false
|
|
||||||
# go-tests = true
|
|
||||||
# unused-packages = true
|
|
||||||
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/Luzifer/go_helpers"
|
|
||||||
version = "2.8.0"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/Luzifer/rconfig"
|
|
||||||
version = "2.2.0"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/asaskevich/govalidator"
|
|
||||||
version = "9.0.0"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/mitchellh/go-homedir"
|
|
||||||
version = "1.0.0"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/nightlyone/lockfile"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/onsi/ginkgo"
|
|
||||||
version = "1.6.0"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/onsi/gomega"
|
|
||||||
version = "1.4.2"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "gopkg.in/yaml.v2"
|
|
||||||
version = "2.2.1"
|
|
||||||
|
|
||||||
[prune]
|
|
||||||
non-go = true
|
|
||||||
go-tests = true
|
|
||||||
unused-packages = true
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/rifflock/lfshook"
|
|
||||||
version = "2.4.0"
|
|
29
go.mod
Normal file
29
go.mod
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
module github.com/Luzifer/duplicity-backup
|
||||||
|
|
||||||
|
go 1.21.0
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/Luzifer/go_helpers v1.4.0
|
||||||
|
github.com/Luzifer/rconfig v1.2.0
|
||||||
|
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
|
||||||
|
github.com/mitchellh/go-homedir v1.1.0
|
||||||
|
github.com/nightlyone/lockfile v1.0.0
|
||||||
|
github.com/onsi/ginkgo v1.16.5
|
||||||
|
github.com/onsi/gomega v1.27.10
|
||||||
|
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
|
||||||
|
github.com/sirupsen/logrus v1.9.3
|
||||||
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/fsnotify/fsnotify v1.4.9 // indirect
|
||||||
|
github.com/google/go-cmp v0.5.9 // indirect
|
||||||
|
github.com/nxadm/tail v1.4.8 // indirect
|
||||||
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
|
golang.org/x/net v0.12.0 // indirect
|
||||||
|
golang.org/x/sys v0.10.0 // indirect
|
||||||
|
golang.org/x/text v0.11.0 // indirect
|
||||||
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
|
||||||
|
gopkg.in/validator.v2 v2.0.1 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
131
go.sum
Normal file
131
go.sum
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
github.com/Luzifer/go_helpers v1.4.0 h1:Pmm058SbYewfnpP1CHda/zERoAqYoZFiBHF4l8k03Ko=
|
||||||
|
github.com/Luzifer/go_helpers v1.4.0/go.mod h1:5yUSe0FS7lIx1Uzmt0R3tdPFrSSaPfiCqaIA6u0Zn4Y=
|
||||||
|
github.com/Luzifer/rconfig v1.2.0 h1:waD1sqasGVSQSrExpLrQ9Q1JmMaltrS391VdOjWXP/I=
|
||||||
|
github.com/Luzifer/rconfig v1.2.0/go.mod h1:9pet6z2+mm/UAB0jF/rf0s62USfHNolzgR6Q4KpsJI0=
|
||||||
|
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
|
||||||
|
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||||
|
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||||
|
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||||
|
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
|
||||||
|
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||||
|
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||||
|
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
|
||||||
|
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
|
||||||
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||||
|
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||||
|
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||||
|
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||||
|
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||||
|
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
|
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
|
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||||
|
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
|
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
|
||||||
|
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||||
|
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||||
|
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
||||||
|
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||||
|
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||||
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
|
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||||
|
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||||
|
github.com/nightlyone/lockfile v1.0.0 h1:RHep2cFKK4PonZJDdEl4GmkabuhbsRMgk/k3uAmxBiA=
|
||||||
|
github.com/nightlyone/lockfile v1.0.0/go.mod h1:rywoIealpdNse2r832aiD9jRk8ErCatROs6LzC841CI=
|
||||||
|
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||||
|
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||||
|
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||||
|
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
|
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
||||||
|
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||||
|
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
|
||||||
|
github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU=
|
||||||
|
github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM=
|
||||||
|
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||||
|
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||||
|
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
|
||||||
|
github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 h1:mZHayPoR0lNmnHyvtYjDeq0zlVHn9K/ZXoy17ylucdo=
|
||||||
|
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM=
|
||||||
|
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||||
|
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||||
|
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||||
|
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
|
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||||
|
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||||
|
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
|
||||||
|
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
|
||||||
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
|
||||||
|
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
|
||||||
|
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||||
|
golang.org/x/tools v0.9.3 h1:Gn1I8+64MsuTb/HpH+LmQtNas23LhUVr3rYZ0eKuaMM=
|
||||||
|
golang.org/x/tools v0.9.3/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||||
|
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||||
|
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||||
|
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||||
|
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||||
|
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
|
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
|
||||||
|
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
|
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||||
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||||
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||||
|
gopkg.in/validator.v2 v2.0.1 h1:xF0KWyGWXm/LM2G1TrEjqOu4pa6coO9AlWSf3msVfDY=
|
||||||
|
gopkg.in/validator.v2 v2.0.1/go.mod h1:lIUZBlB3Im4s/eYp39Ry/wkR02yOPhZ9IwIRBjuPuG8=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
202
vendor/github.com/Luzifer/go_helpers/LICENSE
generated
vendored
202
vendor/github.com/Luzifer/go_helpers/LICENSE
generated
vendored
|
@ -1,202 +0,0 @@
|
||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright 2016- Knut Ahlers <knut@ahlers.me>
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
|
|
21
vendor/github.com/Luzifer/go_helpers/str/slice.go
generated
vendored
21
vendor/github.com/Luzifer/go_helpers/str/slice.go
generated
vendored
|
@ -1,21 +0,0 @@
|
||||||
package str
|
|
||||||
|
|
||||||
// AppendIfMissing adds a string to a slice when it's not present yet
|
|
||||||
func AppendIfMissing(slice []string, s string) []string {
|
|
||||||
for _, e := range slice {
|
|
||||||
if e == s {
|
|
||||||
return slice
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return append(slice, s)
|
|
||||||
}
|
|
||||||
|
|
||||||
// StringInSlice checks for the existence of a string in the slice
|
|
||||||
func StringInSlice(a string, list []string) bool {
|
|
||||||
for _, b := range list {
|
|
||||||
if b == a {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
54
vendor/github.com/Luzifer/go_helpers/which/which.go
generated
vendored
54
vendor/github.com/Luzifer/go_helpers/which/which.go
generated
vendored
|
@ -1,54 +0,0 @@
|
||||||
package which
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Common named errors to match in programs using this library
|
|
||||||
var (
|
|
||||||
ErrBinaryNotFound = errors.New("Requested binary was not found")
|
|
||||||
ErrNoSearchSpecified = errors.New("You need to specify a binary to search")
|
|
||||||
)
|
|
||||||
|
|
||||||
// FindInPath searches the specified binary in directories listed in $PATH and returns first match
|
|
||||||
func FindInPath(binary string) (string, error) {
|
|
||||||
pathEnv := os.Getenv("PATH")
|
|
||||||
if len(pathEnv) == 0 {
|
|
||||||
return "", errors.New("Found empty $PATH, not able to search $PATH")
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, part := range strings.Split(pathEnv, ":") {
|
|
||||||
if len(part) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if found, err := FindInDirectory(binary, part); err != nil {
|
|
||||||
return "", err
|
|
||||||
} else if found {
|
|
||||||
return path.Join(part, binary), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", ErrBinaryNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
// FindInDirectory checks whether the specified file is present in the directory
|
|
||||||
func FindInDirectory(binary, directory string) (bool, error) {
|
|
||||||
if len(binary) == 0 {
|
|
||||||
return false, ErrNoSearchSpecified
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := os.Stat(path.Join(directory, binary))
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case err == nil:
|
|
||||||
return true, nil
|
|
||||||
case os.IsNotExist(err):
|
|
||||||
return false, nil
|
|
||||||
default:
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
}
|
|
202
vendor/github.com/Luzifer/rconfig/LICENSE
generated
vendored
202
vendor/github.com/Luzifer/rconfig/LICENSE
generated
vendored
|
@ -1,202 +0,0 @@
|
||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright 2015- Knut Ahlers <knut@ahlers.me>
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
|
|
64
vendor/github.com/Luzifer/rconfig/autoenv.go
generated
vendored
64
vendor/github.com/Luzifer/rconfig/autoenv.go
generated
vendored
|
@ -1,64 +0,0 @@
|
||||||
package rconfig
|
|
||||||
|
|
||||||
import "strings"
|
|
||||||
|
|
||||||
type characterClass [2]rune
|
|
||||||
|
|
||||||
func (c characterClass) Contains(r rune) bool {
|
|
||||||
return c[0] <= r && c[1] >= r
|
|
||||||
}
|
|
||||||
|
|
||||||
type characterClasses []characterClass
|
|
||||||
|
|
||||||
func (c characterClasses) Contains(r rune) bool {
|
|
||||||
for _, cc := range c {
|
|
||||||
if cc.Contains(r) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
charGroupUpperLetter = characterClass{'A', 'Z'}
|
|
||||||
charGroupLowerLetter = characterClass{'a', 'z'}
|
|
||||||
charGroupNumber = characterClass{'0', '9'}
|
|
||||||
charGroupLowerNumber = characterClasses{charGroupLowerLetter, charGroupNumber}
|
|
||||||
)
|
|
||||||
|
|
||||||
func deriveEnvVarName(s string) string {
|
|
||||||
var (
|
|
||||||
words []string
|
|
||||||
word []rune
|
|
||||||
)
|
|
||||||
|
|
||||||
for _, l := range s {
|
|
||||||
switch {
|
|
||||||
case charGroupUpperLetter.Contains(l):
|
|
||||||
if len(word) > 0 && charGroupLowerNumber.Contains(word[len(word)-1]) {
|
|
||||||
words = append(words, string(word))
|
|
||||||
word = []rune{}
|
|
||||||
}
|
|
||||||
word = append(word, l)
|
|
||||||
|
|
||||||
case charGroupLowerLetter.Contains(l):
|
|
||||||
if len(word) > 1 && charGroupUpperLetter.Contains(word[len(word)-1]) {
|
|
||||||
words = append(words, string(word[0:len(word)-1]))
|
|
||||||
word = word[len(word)-1:]
|
|
||||||
}
|
|
||||||
word = append(word, l)
|
|
||||||
|
|
||||||
case charGroupNumber.Contains(l):
|
|
||||||
word = append(word, l)
|
|
||||||
|
|
||||||
default:
|
|
||||||
if len(word) > 0 {
|
|
||||||
words = append(words, string(word))
|
|
||||||
}
|
|
||||||
word = []rune{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
words = append(words, string(word))
|
|
||||||
|
|
||||||
return strings.ToUpper(strings.Join(words, "_"))
|
|
||||||
}
|
|
456
vendor/github.com/Luzifer/rconfig/config.go
generated
vendored
456
vendor/github.com/Luzifer/rconfig/config.go
generated
vendored
|
@ -1,456 +0,0 @@
|
||||||
// Package rconfig implements a CLI configuration reader with struct-embedded
|
|
||||||
// defaults, environment variables and posix compatible flag parsing using
|
|
||||||
// the pflag library.
|
|
||||||
package rconfig
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"reflect"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
|
||||||
validator "gopkg.in/validator.v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type afterFunc func() error
|
|
||||||
|
|
||||||
var (
|
|
||||||
autoEnv bool
|
|
||||||
fs *pflag.FlagSet
|
|
||||||
variableDefaults map[string]string
|
|
||||||
|
|
||||||
timeParserFormats = []string{
|
|
||||||
// Default constants
|
|
||||||
time.RFC3339Nano, time.RFC3339,
|
|
||||||
time.RFC1123Z, time.RFC1123,
|
|
||||||
time.RFC822Z, time.RFC822,
|
|
||||||
time.RFC850, time.RubyDate, time.UnixDate, time.ANSIC,
|
|
||||||
"2006-01-02 15:04:05.999999999 -0700 MST",
|
|
||||||
// More uncommon time formats
|
|
||||||
"2006-01-02 15:04:05", "2006-01-02 15:04:05Z07:00", // Simplified ISO time format
|
|
||||||
"01/02/2006 15:04:05", "01/02/2006 15:04:05Z07:00", // US time format
|
|
||||||
"02.01.2006 15:04:05", "02.01.2006 15:04:05Z07:00", // DE time format
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
variableDefaults = make(map[string]string)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse takes the pointer to a struct filled with variables which should be read
|
|
||||||
// from ENV, default or flag. The precedence in this is flag > ENV > default. So
|
|
||||||
// if a flag is specified on the CLI it will overwrite the ENV and otherwise ENV
|
|
||||||
// overwrites the default specified.
|
|
||||||
//
|
|
||||||
// For your configuration struct you can use the following struct-tags to control
|
|
||||||
// the behavior of rconfig:
|
|
||||||
//
|
|
||||||
// default: Set a default value
|
|
||||||
// vardefault: Read the default value from the variable defaults
|
|
||||||
// env: Read the value from this environment variable
|
|
||||||
// flag: Flag to read in format "long,short" (for example "listen,l")
|
|
||||||
// description: A help text for Usage output to guide your users
|
|
||||||
//
|
|
||||||
// The format you need to specify those values you can see in the example to this
|
|
||||||
// function.
|
|
||||||
//
|
|
||||||
func Parse(config interface{}) error {
|
|
||||||
return parse(config, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseAndValidate works exactly like Parse but implements an additional run of
|
|
||||||
// the go-validator package on the configuration struct. Therefore additonal struct
|
|
||||||
// tags are supported like described in the readme file of the go-validator package:
|
|
||||||
//
|
|
||||||
// https://github.com/go-validator/validator/tree/v2#usage
|
|
||||||
func ParseAndValidate(config interface{}) error {
|
|
||||||
return parseAndValidate(config, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Args returns the non-flag command-line arguments.
|
|
||||||
func Args() []string {
|
|
||||||
return fs.Args()
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddTimeParserFormats adds custom formats to parse time.Time fields
|
|
||||||
func AddTimeParserFormats(f ...string) {
|
|
||||||
timeParserFormats = append(timeParserFormats, f...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AutoEnv enables or disables automated env variable guessing. If no `env` struct
|
|
||||||
// tag was set and AutoEnv is enabled the env variable name is derived from the
|
|
||||||
// name of the field: `MyFieldName` will get `MY_FIELD_NAME`
|
|
||||||
func AutoEnv(enable bool) {
|
|
||||||
autoEnv = enable
|
|
||||||
}
|
|
||||||
|
|
||||||
// Usage prints a basic usage with the corresponding defaults for the flags to
|
|
||||||
// os.Stdout. The defaults are derived from the `default` struct-tag and the ENV.
|
|
||||||
func Usage() {
|
|
||||||
if fs != nil && fs.Parsed() {
|
|
||||||
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
|
|
||||||
fs.PrintDefaults()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetVariableDefaults presets the parser with a map of default values to be used
|
|
||||||
// when specifying the vardefault tag
|
|
||||||
func SetVariableDefaults(defaults map[string]string) {
|
|
||||||
variableDefaults = defaults
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseAndValidate(in interface{}, args []string) error {
|
|
||||||
if err := parse(in, args); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return validator.Validate(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func parse(in interface{}, args []string) error {
|
|
||||||
if args == nil {
|
|
||||||
args = os.Args
|
|
||||||
}
|
|
||||||
|
|
||||||
fs = pflag.NewFlagSet(os.Args[0], pflag.ExitOnError)
|
|
||||||
afterFuncs, err := execTags(in, fs)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := fs.Parse(args); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if afterFuncs != nil {
|
|
||||||
for _, f := range afterFuncs {
|
|
||||||
if err := f(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func execTags(in interface{}, fs *pflag.FlagSet) ([]afterFunc, error) {
|
|
||||||
if reflect.TypeOf(in).Kind() != reflect.Ptr {
|
|
||||||
return nil, errors.New("Calling parser with non-pointer")
|
|
||||||
}
|
|
||||||
|
|
||||||
if reflect.ValueOf(in).Elem().Kind() != reflect.Struct {
|
|
||||||
return nil, errors.New("Calling parser with pointer to non-struct")
|
|
||||||
}
|
|
||||||
|
|
||||||
afterFuncs := []afterFunc{}
|
|
||||||
|
|
||||||
st := reflect.ValueOf(in).Elem()
|
|
||||||
for i := 0; i < st.NumField(); i++ {
|
|
||||||
valField := st.Field(i)
|
|
||||||
typeField := st.Type().Field(i)
|
|
||||||
|
|
||||||
if typeField.Tag.Get("default") == "" && typeField.Tag.Get("env") == "" && typeField.Tag.Get("flag") == "" && typeField.Type.Kind() != reflect.Struct {
|
|
||||||
// None of our supported tags is present and it's not a sub-struct
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
value := varDefault(typeField.Tag.Get("vardefault"), typeField.Tag.Get("default"))
|
|
||||||
value = envDefault(typeField, value)
|
|
||||||
parts := strings.Split(typeField.Tag.Get("flag"), ",")
|
|
||||||
|
|
||||||
switch typeField.Type {
|
|
||||||
case reflect.TypeOf(time.Duration(0)):
|
|
||||||
v, err := time.ParseDuration(value)
|
|
||||||
if err != nil {
|
|
||||||
if value == "" {
|
|
||||||
v = time.Duration(0)
|
|
||||||
} else {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if typeField.Tag.Get("flag") != "" {
|
|
||||||
if len(parts) == 1 {
|
|
||||||
fs.DurationVar(valField.Addr().Interface().(*time.Duration), parts[0], v, typeField.Tag.Get("description"))
|
|
||||||
} else {
|
|
||||||
fs.DurationVarP(valField.Addr().Interface().(*time.Duration), parts[0], parts[1], v, typeField.Tag.Get("description"))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
valField.Set(reflect.ValueOf(v))
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
|
|
||||||
case reflect.TypeOf(time.Time{}):
|
|
||||||
var sVar string
|
|
||||||
|
|
||||||
if typeField.Tag.Get("flag") != "" {
|
|
||||||
if len(parts) == 1 {
|
|
||||||
fs.StringVar(&sVar, parts[0], value, typeField.Tag.Get("description"))
|
|
||||||
} else {
|
|
||||||
fs.StringVarP(&sVar, parts[0], parts[1], value, typeField.Tag.Get("description"))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sVar = value
|
|
||||||
}
|
|
||||||
|
|
||||||
afterFuncs = append(afterFuncs, func(valField reflect.Value, sVar *string) func() error {
|
|
||||||
return func() error {
|
|
||||||
if *sVar == "" {
|
|
||||||
// No time, no problem
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check whether we could have a timestamp
|
|
||||||
if ts, err := strconv.ParseInt(*sVar, 10, 64); err == nil {
|
|
||||||
t := time.Unix(ts, 0)
|
|
||||||
valField.Set(reflect.ValueOf(t))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// We haven't so lets walk through possible time formats
|
|
||||||
matched := false
|
|
||||||
for _, tf := range timeParserFormats {
|
|
||||||
if t, err := time.Parse(tf, *sVar); err == nil {
|
|
||||||
matched = true
|
|
||||||
valField.Set(reflect.ValueOf(t))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !matched {
|
|
||||||
return fmt.Errorf("Value %q did not match expected time formats", *sVar)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}(valField, &sVar))
|
|
||||||
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
switch typeField.Type.Kind() {
|
|
||||||
case reflect.String:
|
|
||||||
if typeField.Tag.Get("flag") != "" {
|
|
||||||
if len(parts) == 1 {
|
|
||||||
fs.StringVar(valField.Addr().Interface().(*string), parts[0], value, typeField.Tag.Get("description"))
|
|
||||||
} else {
|
|
||||||
fs.StringVarP(valField.Addr().Interface().(*string), parts[0], parts[1], value, typeField.Tag.Get("description"))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
valField.SetString(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
case reflect.Bool:
|
|
||||||
v := value == "true"
|
|
||||||
if typeField.Tag.Get("flag") != "" {
|
|
||||||
if len(parts) == 1 {
|
|
||||||
fs.BoolVar(valField.Addr().Interface().(*bool), parts[0], v, typeField.Tag.Get("description"))
|
|
||||||
} else {
|
|
||||||
fs.BoolVarP(valField.Addr().Interface().(*bool), parts[0], parts[1], v, typeField.Tag.Get("description"))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
valField.SetBool(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
case reflect.Int, reflect.Int8, reflect.Int32, reflect.Int64:
|
|
||||||
vt, err := strconv.ParseInt(value, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
if value == "" {
|
|
||||||
vt = 0
|
|
||||||
} else {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if typeField.Tag.Get("flag") != "" {
|
|
||||||
registerFlagInt(typeField.Type.Kind(), fs, valField.Addr().Interface(), parts, vt, typeField.Tag.Get("description"))
|
|
||||||
} else {
|
|
||||||
valField.SetInt(vt)
|
|
||||||
}
|
|
||||||
|
|
||||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
|
||||||
vt, err := strconv.ParseUint(value, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
if value == "" {
|
|
||||||
vt = 0
|
|
||||||
} else {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if typeField.Tag.Get("flag") != "" {
|
|
||||||
registerFlagUint(typeField.Type.Kind(), fs, valField.Addr().Interface(), parts, vt, typeField.Tag.Get("description"))
|
|
||||||
} else {
|
|
||||||
valField.SetUint(vt)
|
|
||||||
}
|
|
||||||
|
|
||||||
case reflect.Float32, reflect.Float64:
|
|
||||||
vt, err := strconv.ParseFloat(value, 64)
|
|
||||||
if err != nil {
|
|
||||||
if value == "" {
|
|
||||||
vt = 0.0
|
|
||||||
} else {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if typeField.Tag.Get("flag") != "" {
|
|
||||||
registerFlagFloat(typeField.Type.Kind(), fs, valField.Addr().Interface(), parts, vt, typeField.Tag.Get("description"))
|
|
||||||
} else {
|
|
||||||
valField.SetFloat(vt)
|
|
||||||
}
|
|
||||||
|
|
||||||
case reflect.Struct:
|
|
||||||
afs, err := execTags(valField.Addr().Interface(), fs)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
afterFuncs = append(afterFuncs, afs...)
|
|
||||||
|
|
||||||
case reflect.Slice:
|
|
||||||
switch typeField.Type.Elem().Kind() {
|
|
||||||
case reflect.Int:
|
|
||||||
def := []int{}
|
|
||||||
for _, v := range strings.Split(value, ",") {
|
|
||||||
it, err := strconv.ParseInt(strings.TrimSpace(v), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
def = append(def, int(it))
|
|
||||||
}
|
|
||||||
if len(parts) == 1 {
|
|
||||||
fs.IntSliceVar(valField.Addr().Interface().(*[]int), parts[0], def, typeField.Tag.Get("description"))
|
|
||||||
} else {
|
|
||||||
fs.IntSliceVarP(valField.Addr().Interface().(*[]int), parts[0], parts[1], def, typeField.Tag.Get("description"))
|
|
||||||
}
|
|
||||||
case reflect.String:
|
|
||||||
del := typeField.Tag.Get("delimiter")
|
|
||||||
if len(del) == 0 {
|
|
||||||
del = ","
|
|
||||||
}
|
|
||||||
var def = []string{}
|
|
||||||
if value != "" {
|
|
||||||
def = strings.Split(value, del)
|
|
||||||
}
|
|
||||||
if len(parts) == 1 {
|
|
||||||
fs.StringSliceVar(valField.Addr().Interface().(*[]string), parts[0], def, typeField.Tag.Get("description"))
|
|
||||||
} else {
|
|
||||||
fs.StringSliceVarP(valField.Addr().Interface().(*[]string), parts[0], parts[1], def, typeField.Tag.Get("description"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return afterFuncs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func registerFlagFloat(t reflect.Kind, fs *pflag.FlagSet, field interface{}, parts []string, vt float64, desc string) {
|
|
||||||
switch t {
|
|
||||||
case reflect.Float32:
|
|
||||||
if len(parts) == 1 {
|
|
||||||
fs.Float32Var(field.(*float32), parts[0], float32(vt), desc)
|
|
||||||
} else {
|
|
||||||
fs.Float32VarP(field.(*float32), parts[0], parts[1], float32(vt), desc)
|
|
||||||
}
|
|
||||||
case reflect.Float64:
|
|
||||||
if len(parts) == 1 {
|
|
||||||
fs.Float64Var(field.(*float64), parts[0], float64(vt), desc)
|
|
||||||
} else {
|
|
||||||
fs.Float64VarP(field.(*float64), parts[0], parts[1], float64(vt), desc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func registerFlagInt(t reflect.Kind, fs *pflag.FlagSet, field interface{}, parts []string, vt int64, desc string) {
|
|
||||||
switch t {
|
|
||||||
case reflect.Int:
|
|
||||||
if len(parts) == 1 {
|
|
||||||
fs.IntVar(field.(*int), parts[0], int(vt), desc)
|
|
||||||
} else {
|
|
||||||
fs.IntVarP(field.(*int), parts[0], parts[1], int(vt), desc)
|
|
||||||
}
|
|
||||||
case reflect.Int8:
|
|
||||||
if len(parts) == 1 {
|
|
||||||
fs.Int8Var(field.(*int8), parts[0], int8(vt), desc)
|
|
||||||
} else {
|
|
||||||
fs.Int8VarP(field.(*int8), parts[0], parts[1], int8(vt), desc)
|
|
||||||
}
|
|
||||||
case reflect.Int32:
|
|
||||||
if len(parts) == 1 {
|
|
||||||
fs.Int32Var(field.(*int32), parts[0], int32(vt), desc)
|
|
||||||
} else {
|
|
||||||
fs.Int32VarP(field.(*int32), parts[0], parts[1], int32(vt), desc)
|
|
||||||
}
|
|
||||||
case reflect.Int64:
|
|
||||||
if len(parts) == 1 {
|
|
||||||
fs.Int64Var(field.(*int64), parts[0], int64(vt), desc)
|
|
||||||
} else {
|
|
||||||
fs.Int64VarP(field.(*int64), parts[0], parts[1], int64(vt), desc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func registerFlagUint(t reflect.Kind, fs *pflag.FlagSet, field interface{}, parts []string, vt uint64, desc string) {
|
|
||||||
switch t {
|
|
||||||
case reflect.Uint:
|
|
||||||
if len(parts) == 1 {
|
|
||||||
fs.UintVar(field.(*uint), parts[0], uint(vt), desc)
|
|
||||||
} else {
|
|
||||||
fs.UintVarP(field.(*uint), parts[0], parts[1], uint(vt), desc)
|
|
||||||
}
|
|
||||||
case reflect.Uint8:
|
|
||||||
if len(parts) == 1 {
|
|
||||||
fs.Uint8Var(field.(*uint8), parts[0], uint8(vt), desc)
|
|
||||||
} else {
|
|
||||||
fs.Uint8VarP(field.(*uint8), parts[0], parts[1], uint8(vt), desc)
|
|
||||||
}
|
|
||||||
case reflect.Uint16:
|
|
||||||
if len(parts) == 1 {
|
|
||||||
fs.Uint16Var(field.(*uint16), parts[0], uint16(vt), desc)
|
|
||||||
} else {
|
|
||||||
fs.Uint16VarP(field.(*uint16), parts[0], parts[1], uint16(vt), desc)
|
|
||||||
}
|
|
||||||
case reflect.Uint32:
|
|
||||||
if len(parts) == 1 {
|
|
||||||
fs.Uint32Var(field.(*uint32), parts[0], uint32(vt), desc)
|
|
||||||
} else {
|
|
||||||
fs.Uint32VarP(field.(*uint32), parts[0], parts[1], uint32(vt), desc)
|
|
||||||
}
|
|
||||||
case reflect.Uint64:
|
|
||||||
if len(parts) == 1 {
|
|
||||||
fs.Uint64Var(field.(*uint64), parts[0], uint64(vt), desc)
|
|
||||||
} else {
|
|
||||||
fs.Uint64VarP(field.(*uint64), parts[0], parts[1], uint64(vt), desc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func envDefault(field reflect.StructField, def string) string {
|
|
||||||
value := def
|
|
||||||
|
|
||||||
env := field.Tag.Get("env")
|
|
||||||
if env == "" && autoEnv {
|
|
||||||
env = deriveEnvVarName(field.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
if env != "" {
|
|
||||||
if e := os.Getenv(env); e != "" {
|
|
||||||
value = e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
func varDefault(name, def string) string {
|
|
||||||
value := def
|
|
||||||
|
|
||||||
if name != "" {
|
|
||||||
if v, ok := variableDefaults[name]; ok {
|
|
||||||
value = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return value
|
|
||||||
}
|
|
27
vendor/github.com/Luzifer/rconfig/vardefault_providers.go
generated
vendored
27
vendor/github.com/Luzifer/rconfig/vardefault_providers.go
generated
vendored
|
@ -1,27 +0,0 @@
|
||||||
package rconfig
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io/ioutil"
|
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
// VarDefaultsFromYAMLFile reads contents of a file and calls VarDefaultsFromYAML
|
|
||||||
func VarDefaultsFromYAMLFile(filename string) map[string]string {
|
|
||||||
data, err := ioutil.ReadFile(filename)
|
|
||||||
if err != nil {
|
|
||||||
return make(map[string]string)
|
|
||||||
}
|
|
||||||
|
|
||||||
return VarDefaultsFromYAML(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// VarDefaultsFromYAML creates a vardefaults map from YAML raw data
|
|
||||||
func VarDefaultsFromYAML(in []byte) map[string]string {
|
|
||||||
out := make(map[string]string)
|
|
||||||
err := yaml.Unmarshal(in, &out)
|
|
||||||
if err != nil {
|
|
||||||
return make(map[string]string)
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
21
vendor/github.com/asaskevich/govalidator/LICENSE
generated
vendored
21
vendor/github.com/asaskevich/govalidator/LICENSE
generated
vendored
|
@ -1,21 +0,0 @@
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2014 Alex Saskevich
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
58
vendor/github.com/asaskevich/govalidator/arrays.go
generated
vendored
58
vendor/github.com/asaskevich/govalidator/arrays.go
generated
vendored
|
@ -1,58 +0,0 @@
|
||||||
package govalidator
|
|
||||||
|
|
||||||
// Iterator is the function that accepts element of slice/array and its index
|
|
||||||
type Iterator func(interface{}, int)
|
|
||||||
|
|
||||||
// ResultIterator is the function that accepts element of slice/array and its index and returns any result
|
|
||||||
type ResultIterator func(interface{}, int) interface{}
|
|
||||||
|
|
||||||
// ConditionIterator is the function that accepts element of slice/array and its index and returns boolean
|
|
||||||
type ConditionIterator func(interface{}, int) bool
|
|
||||||
|
|
||||||
// Each iterates over the slice and apply Iterator to every item
|
|
||||||
func Each(array []interface{}, iterator Iterator) {
|
|
||||||
for index, data := range array {
|
|
||||||
iterator(data, index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Map iterates over the slice and apply ResultIterator to every item. Returns new slice as a result.
|
|
||||||
func Map(array []interface{}, iterator ResultIterator) []interface{} {
|
|
||||||
var result = make([]interface{}, len(array))
|
|
||||||
for index, data := range array {
|
|
||||||
result[index] = iterator(data, index)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find iterates over the slice and apply ConditionIterator to every item. Returns first item that meet ConditionIterator or nil otherwise.
|
|
||||||
func Find(array []interface{}, iterator ConditionIterator) interface{} {
|
|
||||||
for index, data := range array {
|
|
||||||
if iterator(data, index) {
|
|
||||||
return data
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter iterates over the slice and apply ConditionIterator to every item. Returns new slice.
|
|
||||||
func Filter(array []interface{}, iterator ConditionIterator) []interface{} {
|
|
||||||
var result = make([]interface{}, 0)
|
|
||||||
for index, data := range array {
|
|
||||||
if iterator(data, index) {
|
|
||||||
result = append(result, data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// Count iterates over the slice and apply ConditionIterator to every item. Returns count of items that meets ConditionIterator.
|
|
||||||
func Count(array []interface{}, iterator ConditionIterator) int {
|
|
||||||
count := 0
|
|
||||||
for index, data := range array {
|
|
||||||
if iterator(data, index) {
|
|
||||||
count = count + 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return count
|
|
||||||
}
|
|
64
vendor/github.com/asaskevich/govalidator/converter.go
generated
vendored
64
vendor/github.com/asaskevich/govalidator/converter.go
generated
vendored
|
@ -1,64 +0,0 @@
|
||||||
package govalidator
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ToString convert the input to a string.
|
|
||||||
func ToString(obj interface{}) string {
|
|
||||||
res := fmt.Sprintf("%v", obj)
|
|
||||||
return string(res)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToJSON convert the input to a valid JSON string
|
|
||||||
func ToJSON(obj interface{}) (string, error) {
|
|
||||||
res, err := json.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
res = []byte("")
|
|
||||||
}
|
|
||||||
return string(res), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToFloat convert the input string to a float, or 0.0 if the input is not a float.
|
|
||||||
func ToFloat(str string) (float64, error) {
|
|
||||||
res, err := strconv.ParseFloat(str, 64)
|
|
||||||
if err != nil {
|
|
||||||
res = 0.0
|
|
||||||
}
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToInt convert the input string or any int type to an integer type 64, or 0 if the input is not an integer.
|
|
||||||
func ToInt(value interface{}) (res int64, err error) {
|
|
||||||
val := reflect.ValueOf(value)
|
|
||||||
|
|
||||||
switch value.(type) {
|
|
||||||
case int, int8, int16, int32, int64:
|
|
||||||
res = val.Int()
|
|
||||||
case uint, uint8, uint16, uint32, uint64:
|
|
||||||
res = int64(val.Uint())
|
|
||||||
case string:
|
|
||||||
if IsInt(val.String()) {
|
|
||||||
res, err = strconv.ParseInt(val.String(), 0, 64)
|
|
||||||
if err != nil {
|
|
||||||
res = 0
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
err = fmt.Errorf("math: square root of negative number %g", value)
|
|
||||||
res = 0
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
err = fmt.Errorf("math: square root of negative number %g", value)
|
|
||||||
res = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToBoolean convert the input string to a boolean.
|
|
||||||
func ToBoolean(str string) (bool, error) {
|
|
||||||
return strconv.ParseBool(str)
|
|
||||||
}
|
|
36
vendor/github.com/asaskevich/govalidator/error.go
generated
vendored
36
vendor/github.com/asaskevich/govalidator/error.go
generated
vendored
|
@ -1,36 +0,0 @@
|
||||||
package govalidator
|
|
||||||
|
|
||||||
import "strings"
|
|
||||||
|
|
||||||
// Errors is an array of multiple errors and conforms to the error interface.
|
|
||||||
type Errors []error
|
|
||||||
|
|
||||||
// Errors returns itself.
|
|
||||||
func (es Errors) Errors() []error {
|
|
||||||
return es
|
|
||||||
}
|
|
||||||
|
|
||||||
func (es Errors) Error() string {
|
|
||||||
var errs []string
|
|
||||||
for _, e := range es {
|
|
||||||
errs = append(errs, e.Error())
|
|
||||||
}
|
|
||||||
return strings.Join(errs, ";")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error encapsulates a name, an error and whether there's a custom error message or not.
|
|
||||||
type Error struct {
|
|
||||||
Name string
|
|
||||||
Err error
|
|
||||||
CustomErrorMessageExists bool
|
|
||||||
|
|
||||||
// Validator indicates the name of the validator that failed
|
|
||||||
Validator string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e Error) Error() string {
|
|
||||||
if e.CustomErrorMessageExists {
|
|
||||||
return e.Err.Error()
|
|
||||||
}
|
|
||||||
return e.Name + ": " + e.Err.Error()
|
|
||||||
}
|
|
97
vendor/github.com/asaskevich/govalidator/numerics.go
generated
vendored
97
vendor/github.com/asaskevich/govalidator/numerics.go
generated
vendored
|
@ -1,97 +0,0 @@
|
||||||
package govalidator
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math"
|
|
||||||
"reflect"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Abs returns absolute value of number
|
|
||||||
func Abs(value float64) float64 {
|
|
||||||
return math.Abs(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sign returns signum of number: 1 in case of value > 0, -1 in case of value < 0, 0 otherwise
|
|
||||||
func Sign(value float64) float64 {
|
|
||||||
if value > 0 {
|
|
||||||
return 1
|
|
||||||
} else if value < 0 {
|
|
||||||
return -1
|
|
||||||
} else {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsNegative returns true if value < 0
|
|
||||||
func IsNegative(value float64) bool {
|
|
||||||
return value < 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsPositive returns true if value > 0
|
|
||||||
func IsPositive(value float64) bool {
|
|
||||||
return value > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsNonNegative returns true if value >= 0
|
|
||||||
func IsNonNegative(value float64) bool {
|
|
||||||
return value >= 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsNonPositive returns true if value <= 0
|
|
||||||
func IsNonPositive(value float64) bool {
|
|
||||||
return value <= 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// InRange returns true if value lies between left and right border
|
|
||||||
func InRangeInt(value, left, right interface{}) bool {
|
|
||||||
value64, _ := ToInt(value)
|
|
||||||
left64, _ := ToInt(left)
|
|
||||||
right64, _ := ToInt(right)
|
|
||||||
if left64 > right64 {
|
|
||||||
left64, right64 = right64, left64
|
|
||||||
}
|
|
||||||
return value64 >= left64 && value64 <= right64
|
|
||||||
}
|
|
||||||
|
|
||||||
// InRange returns true if value lies between left and right border
|
|
||||||
func InRangeFloat32(value, left, right float32) bool {
|
|
||||||
if left > right {
|
|
||||||
left, right = right, left
|
|
||||||
}
|
|
||||||
return value >= left && value <= right
|
|
||||||
}
|
|
||||||
|
|
||||||
// InRange returns true if value lies between left and right border
|
|
||||||
func InRangeFloat64(value, left, right float64) bool {
|
|
||||||
if left > right {
|
|
||||||
left, right = right, left
|
|
||||||
}
|
|
||||||
return value >= left && value <= right
|
|
||||||
}
|
|
||||||
|
|
||||||
// InRange returns true if value lies between left and right border, generic type to handle int, float32 or float64, all types must the same type
|
|
||||||
func InRange(value interface{}, left interface{}, right interface{}) bool {
|
|
||||||
|
|
||||||
reflectValue := reflect.TypeOf(value).Kind()
|
|
||||||
reflectLeft := reflect.TypeOf(left).Kind()
|
|
||||||
reflectRight := reflect.TypeOf(right).Kind()
|
|
||||||
|
|
||||||
if reflectValue == reflect.Int && reflectLeft == reflect.Int && reflectRight == reflect.Int {
|
|
||||||
return InRangeInt(value.(int), left.(int), right.(int))
|
|
||||||
} else if reflectValue == reflect.Float32 && reflectLeft == reflect.Float32 && reflectRight == reflect.Float32 {
|
|
||||||
return InRangeFloat32(value.(float32), left.(float32), right.(float32))
|
|
||||||
} else if reflectValue == reflect.Float64 && reflectLeft == reflect.Float64 && reflectRight == reflect.Float64 {
|
|
||||||
return InRangeFloat64(value.(float64), left.(float64), right.(float64))
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsWhole returns true if value is whole number
|
|
||||||
func IsWhole(value float64) bool {
|
|
||||||
return math.Remainder(value, 1) == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsNatural returns true if value is natural number (positive and whole)
|
|
||||||
func IsNatural(value float64) bool {
|
|
||||||
return IsWhole(value) && IsPositive(value)
|
|
||||||
}
|
|
97
vendor/github.com/asaskevich/govalidator/patterns.go
generated
vendored
97
vendor/github.com/asaskevich/govalidator/patterns.go
generated
vendored
|
@ -1,97 +0,0 @@
|
||||||
package govalidator
|
|
||||||
|
|
||||||
import "regexp"
|
|
||||||
|
|
||||||
// Basic regular expressions for validating strings
|
|
||||||
const (
|
|
||||||
//Email string = "^(((([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+(\\.([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])([a-zA-Z]|\\d|-|\\.|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.)+(([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])([a-zA-Z]|\\d|-|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.?$"
|
|
||||||
CreditCard string = "^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11})$"
|
|
||||||
ISBN10 string = "^(?:[0-9]{9}X|[0-9]{10})$"
|
|
||||||
ISBN13 string = "^(?:[0-9]{13})$"
|
|
||||||
UUID3 string = "^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$"
|
|
||||||
UUID4 string = "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
|
|
||||||
UUID5 string = "^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
|
|
||||||
UUID string = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
|
|
||||||
Alpha string = "^[a-zA-Z]+$"
|
|
||||||
Alphanumeric string = "^[a-zA-Z0-9]+$"
|
|
||||||
Numeric string = "^[0-9]+$"
|
|
||||||
Int string = "^(?:[-+]?(?:0|[1-9][0-9]*))$"
|
|
||||||
Float string = "^(?:[-+]?(?:[0-9]+))?(?:\\.[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$"
|
|
||||||
Hexadecimal string = "^[0-9a-fA-F]+$"
|
|
||||||
Hexcolor string = "^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"
|
|
||||||
RGBcolor string = "^rgb\\(\\s*(0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*\\)$"
|
|
||||||
ASCII string = "^[\x00-\x7F]+$"
|
|
||||||
Multibyte string = "[^\x00-\x7F]"
|
|
||||||
FullWidth string = "[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]"
|
|
||||||
HalfWidth string = "[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]"
|
|
||||||
Base64 string = "^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$"
|
|
||||||
PrintableASCII string = "^[\x20-\x7E]+$"
|
|
||||||
DataURI string = "^data:.+\\/(.+);base64$"
|
|
||||||
Latitude string = "^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)$"
|
|
||||||
Longitude string = "^[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$"
|
|
||||||
DNSName string = `^([a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62}){1}(\.[a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62})*[\._]?$`
|
|
||||||
IP string = `(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))`
|
|
||||||
URLSchema string = `((ftp|tcp|udp|wss?|https?):\/\/)`
|
|
||||||
URLUsername string = `(\S+(:\S*)?@)`
|
|
||||||
URLPath string = `((\/|\?|#)[^\s]*)`
|
|
||||||
URLPort string = `(:(\d{1,5}))`
|
|
||||||
URLIP string = `([1-9]\d?|1\d\d|2[01]\d|22[0-3])(\.(1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.([0-9]\d?|1\d\d|2[0-4]\d|25[0-4]))`
|
|
||||||
URLSubdomain string = `((www\.)|([a-zA-Z0-9]([-\.][-\._a-zA-Z0-9]+)*))`
|
|
||||||
URL string = `^` + URLSchema + `?` + URLUsername + `?` + `((` + URLIP + `|(\[` + IP + `\])|(([a-zA-Z0-9]([a-zA-Z0-9-_]+)?[a-zA-Z0-9]([-\.][a-zA-Z0-9]+)*)|(` + URLSubdomain + `?))?(([a-zA-Z\x{00a1}-\x{ffff}0-9]+-?-?)*[a-zA-Z\x{00a1}-\x{ffff}0-9]+)(?:\.([a-zA-Z\x{00a1}-\x{ffff}]{1,}))?))\.?` + URLPort + `?` + URLPath + `?$`
|
|
||||||
SSN string = `^\d{3}[- ]?\d{2}[- ]?\d{4}$`
|
|
||||||
WinPath string = `^[a-zA-Z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*$`
|
|
||||||
UnixPath string = `^(/[^/\x00]*)+/?$`
|
|
||||||
Semver string = "^v?(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)(-(0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(\\.(0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\\+[0-9a-zA-Z-]+(\\.[0-9a-zA-Z-]+)*)?$"
|
|
||||||
tagName string = "valid"
|
|
||||||
hasLowerCase string = ".*[[:lower:]]"
|
|
||||||
hasUpperCase string = ".*[[:upper:]]"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Used by IsFilePath func
|
|
||||||
const (
|
|
||||||
// Unknown is unresolved OS type
|
|
||||||
Unknown = iota
|
|
||||||
// Win is Windows type
|
|
||||||
Win
|
|
||||||
// Unix is *nix OS types
|
|
||||||
Unix
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
userRegexp = regexp.MustCompile("^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~.-]+$")
|
|
||||||
hostRegexp = regexp.MustCompile("^[^\\s]+\\.[^\\s]+$")
|
|
||||||
userDotRegexp = regexp.MustCompile("(^[.]{1})|([.]{1}$)|([.]{2,})")
|
|
||||||
//rxEmail = regexp.MustCompile(Email)
|
|
||||||
rxCreditCard = regexp.MustCompile(CreditCard)
|
|
||||||
rxISBN10 = regexp.MustCompile(ISBN10)
|
|
||||||
rxISBN13 = regexp.MustCompile(ISBN13)
|
|
||||||
rxUUID3 = regexp.MustCompile(UUID3)
|
|
||||||
rxUUID4 = regexp.MustCompile(UUID4)
|
|
||||||
rxUUID5 = regexp.MustCompile(UUID5)
|
|
||||||
rxUUID = regexp.MustCompile(UUID)
|
|
||||||
rxAlpha = regexp.MustCompile(Alpha)
|
|
||||||
rxAlphanumeric = regexp.MustCompile(Alphanumeric)
|
|
||||||
rxNumeric = regexp.MustCompile(Numeric)
|
|
||||||
rxInt = regexp.MustCompile(Int)
|
|
||||||
rxFloat = regexp.MustCompile(Float)
|
|
||||||
rxHexadecimal = regexp.MustCompile(Hexadecimal)
|
|
||||||
rxHexcolor = regexp.MustCompile(Hexcolor)
|
|
||||||
rxRGBcolor = regexp.MustCompile(RGBcolor)
|
|
||||||
rxASCII = regexp.MustCompile(ASCII)
|
|
||||||
rxPrintableASCII = regexp.MustCompile(PrintableASCII)
|
|
||||||
rxMultibyte = regexp.MustCompile(Multibyte)
|
|
||||||
rxFullWidth = regexp.MustCompile(FullWidth)
|
|
||||||
rxHalfWidth = regexp.MustCompile(HalfWidth)
|
|
||||||
rxBase64 = regexp.MustCompile(Base64)
|
|
||||||
rxDataURI = regexp.MustCompile(DataURI)
|
|
||||||
rxLatitude = regexp.MustCompile(Latitude)
|
|
||||||
rxLongitude = regexp.MustCompile(Longitude)
|
|
||||||
rxDNSName = regexp.MustCompile(DNSName)
|
|
||||||
rxURL = regexp.MustCompile(URL)
|
|
||||||
rxSSN = regexp.MustCompile(SSN)
|
|
||||||
rxWinPath = regexp.MustCompile(WinPath)
|
|
||||||
rxUnixPath = regexp.MustCompile(UnixPath)
|
|
||||||
rxSemver = regexp.MustCompile(Semver)
|
|
||||||
rxHasLowerCase = regexp.MustCompile(hasLowerCase)
|
|
||||||
rxHasUpperCase = regexp.MustCompile(hasUpperCase)
|
|
||||||
)
|
|
616
vendor/github.com/asaskevich/govalidator/types.go
generated
vendored
616
vendor/github.com/asaskevich/govalidator/types.go
generated
vendored
|
@ -1,616 +0,0 @@
|
||||||
package govalidator
|
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
"regexp"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Validator is a wrapper for a validator function that returns bool and accepts string.
|
|
||||||
type Validator func(str string) bool
|
|
||||||
|
|
||||||
// CustomTypeValidator is a wrapper for validator functions that returns bool and accepts any type.
|
|
||||||
// The second parameter should be the context (in the case of validating a struct: the whole object being validated).
|
|
||||||
type CustomTypeValidator func(i interface{}, o interface{}) bool
|
|
||||||
|
|
||||||
// ParamValidator is a wrapper for validator functions that accepts additional parameters.
|
|
||||||
type ParamValidator func(str string, params ...string) bool
|
|
||||||
type tagOptionsMap map[string]string
|
|
||||||
|
|
||||||
// UnsupportedTypeError is a wrapper for reflect.Type
|
|
||||||
type UnsupportedTypeError struct {
|
|
||||||
Type reflect.Type
|
|
||||||
}
|
|
||||||
|
|
||||||
// stringValues is a slice of reflect.Value holding *reflect.StringValue.
|
|
||||||
// It implements the methods to sort by string.
|
|
||||||
type stringValues []reflect.Value
|
|
||||||
|
|
||||||
// ParamTagMap is a map of functions accept variants parameters
|
|
||||||
var ParamTagMap = map[string]ParamValidator{
|
|
||||||
"length": ByteLength,
|
|
||||||
"range": Range,
|
|
||||||
"runelength": RuneLength,
|
|
||||||
"stringlength": StringLength,
|
|
||||||
"matches": StringMatches,
|
|
||||||
"in": isInRaw,
|
|
||||||
"rsapub": IsRsaPub,
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParamTagRegexMap maps param tags to their respective regexes.
|
|
||||||
var ParamTagRegexMap = map[string]*regexp.Regexp{
|
|
||||||
"range": regexp.MustCompile("^range\\((\\d+)\\|(\\d+)\\)$"),
|
|
||||||
"length": regexp.MustCompile("^length\\((\\d+)\\|(\\d+)\\)$"),
|
|
||||||
"runelength": regexp.MustCompile("^runelength\\((\\d+)\\|(\\d+)\\)$"),
|
|
||||||
"stringlength": regexp.MustCompile("^stringlength\\((\\d+)\\|(\\d+)\\)$"),
|
|
||||||
"in": regexp.MustCompile(`^in\((.*)\)`),
|
|
||||||
"matches": regexp.MustCompile(`^matches\((.+)\)$`),
|
|
||||||
"rsapub": regexp.MustCompile("^rsapub\\((\\d+)\\)$"),
|
|
||||||
}
|
|
||||||
|
|
||||||
type customTypeTagMap struct {
|
|
||||||
validators map[string]CustomTypeValidator
|
|
||||||
|
|
||||||
sync.RWMutex
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tm *customTypeTagMap) Get(name string) (CustomTypeValidator, bool) {
|
|
||||||
tm.RLock()
|
|
||||||
defer tm.RUnlock()
|
|
||||||
v, ok := tm.validators[name]
|
|
||||||
return v, ok
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tm *customTypeTagMap) Set(name string, ctv CustomTypeValidator) {
|
|
||||||
tm.Lock()
|
|
||||||
defer tm.Unlock()
|
|
||||||
tm.validators[name] = ctv
|
|
||||||
}
|
|
||||||
|
|
||||||
// CustomTypeTagMap is a map of functions that can be used as tags for ValidateStruct function.
|
|
||||||
// Use this to validate compound or custom types that need to be handled as a whole, e.g.
|
|
||||||
// `type UUID [16]byte` (this would be handled as an array of bytes).
|
|
||||||
var CustomTypeTagMap = &customTypeTagMap{validators: make(map[string]CustomTypeValidator)}
|
|
||||||
|
|
||||||
// TagMap is a map of functions, that can be used as tags for ValidateStruct function.
|
|
||||||
var TagMap = map[string]Validator{
|
|
||||||
"email": IsEmail,
|
|
||||||
"url": IsURL,
|
|
||||||
"dialstring": IsDialString,
|
|
||||||
"requrl": IsRequestURL,
|
|
||||||
"requri": IsRequestURI,
|
|
||||||
"alpha": IsAlpha,
|
|
||||||
"utfletter": IsUTFLetter,
|
|
||||||
"alphanum": IsAlphanumeric,
|
|
||||||
"utfletternum": IsUTFLetterNumeric,
|
|
||||||
"numeric": IsNumeric,
|
|
||||||
"utfnumeric": IsUTFNumeric,
|
|
||||||
"utfdigit": IsUTFDigit,
|
|
||||||
"hexadecimal": IsHexadecimal,
|
|
||||||
"hexcolor": IsHexcolor,
|
|
||||||
"rgbcolor": IsRGBcolor,
|
|
||||||
"lowercase": IsLowerCase,
|
|
||||||
"uppercase": IsUpperCase,
|
|
||||||
"int": IsInt,
|
|
||||||
"float": IsFloat,
|
|
||||||
"null": IsNull,
|
|
||||||
"uuid": IsUUID,
|
|
||||||
"uuidv3": IsUUIDv3,
|
|
||||||
"uuidv4": IsUUIDv4,
|
|
||||||
"uuidv5": IsUUIDv5,
|
|
||||||
"creditcard": IsCreditCard,
|
|
||||||
"isbn10": IsISBN10,
|
|
||||||
"isbn13": IsISBN13,
|
|
||||||
"json": IsJSON,
|
|
||||||
"multibyte": IsMultibyte,
|
|
||||||
"ascii": IsASCII,
|
|
||||||
"printableascii": IsPrintableASCII,
|
|
||||||
"fullwidth": IsFullWidth,
|
|
||||||
"halfwidth": IsHalfWidth,
|
|
||||||
"variablewidth": IsVariableWidth,
|
|
||||||
"base64": IsBase64,
|
|
||||||
"datauri": IsDataURI,
|
|
||||||
"ip": IsIP,
|
|
||||||
"port": IsPort,
|
|
||||||
"ipv4": IsIPv4,
|
|
||||||
"ipv6": IsIPv6,
|
|
||||||
"dns": IsDNSName,
|
|
||||||
"host": IsHost,
|
|
||||||
"mac": IsMAC,
|
|
||||||
"latitude": IsLatitude,
|
|
||||||
"longitude": IsLongitude,
|
|
||||||
"ssn": IsSSN,
|
|
||||||
"semver": IsSemver,
|
|
||||||
"rfc3339": IsRFC3339,
|
|
||||||
"rfc3339WithoutZone": IsRFC3339WithoutZone,
|
|
||||||
"ISO3166Alpha2": IsISO3166Alpha2,
|
|
||||||
"ISO3166Alpha3": IsISO3166Alpha3,
|
|
||||||
"ISO4217": IsISO4217,
|
|
||||||
}
|
|
||||||
|
|
||||||
// ISO3166Entry stores country codes
|
|
||||||
type ISO3166Entry struct {
|
|
||||||
EnglishShortName string
|
|
||||||
FrenchShortName string
|
|
||||||
Alpha2Code string
|
|
||||||
Alpha3Code string
|
|
||||||
Numeric string
|
|
||||||
}
|
|
||||||
|
|
||||||
//ISO3166List based on https://www.iso.org/obp/ui/#search/code/ Code Type "Officially Assigned Codes"
|
|
||||||
var ISO3166List = []ISO3166Entry{
|
|
||||||
{"Afghanistan", "Afghanistan (l')", "AF", "AFG", "004"},
|
|
||||||
{"Albania", "Albanie (l')", "AL", "ALB", "008"},
|
|
||||||
{"Antarctica", "Antarctique (l')", "AQ", "ATA", "010"},
|
|
||||||
{"Algeria", "Algérie (l')", "DZ", "DZA", "012"},
|
|
||||||
{"American Samoa", "Samoa américaines (les)", "AS", "ASM", "016"},
|
|
||||||
{"Andorra", "Andorre (l')", "AD", "AND", "020"},
|
|
||||||
{"Angola", "Angola (l')", "AO", "AGO", "024"},
|
|
||||||
{"Antigua and Barbuda", "Antigua-et-Barbuda", "AG", "ATG", "028"},
|
|
||||||
{"Azerbaijan", "Azerbaïdjan (l')", "AZ", "AZE", "031"},
|
|
||||||
{"Argentina", "Argentine (l')", "AR", "ARG", "032"},
|
|
||||||
{"Australia", "Australie (l')", "AU", "AUS", "036"},
|
|
||||||
{"Austria", "Autriche (l')", "AT", "AUT", "040"},
|
|
||||||
{"Bahamas (the)", "Bahamas (les)", "BS", "BHS", "044"},
|
|
||||||
{"Bahrain", "Bahreïn", "BH", "BHR", "048"},
|
|
||||||
{"Bangladesh", "Bangladesh (le)", "BD", "BGD", "050"},
|
|
||||||
{"Armenia", "Arménie (l')", "AM", "ARM", "051"},
|
|
||||||
{"Barbados", "Barbade (la)", "BB", "BRB", "052"},
|
|
||||||
{"Belgium", "Belgique (la)", "BE", "BEL", "056"},
|
|
||||||
{"Bermuda", "Bermudes (les)", "BM", "BMU", "060"},
|
|
||||||
{"Bhutan", "Bhoutan (le)", "BT", "BTN", "064"},
|
|
||||||
{"Bolivia (Plurinational State of)", "Bolivie (État plurinational de)", "BO", "BOL", "068"},
|
|
||||||
{"Bosnia and Herzegovina", "Bosnie-Herzégovine (la)", "BA", "BIH", "070"},
|
|
||||||
{"Botswana", "Botswana (le)", "BW", "BWA", "072"},
|
|
||||||
{"Bouvet Island", "Bouvet (l'Île)", "BV", "BVT", "074"},
|
|
||||||
{"Brazil", "Brésil (le)", "BR", "BRA", "076"},
|
|
||||||
{"Belize", "Belize (le)", "BZ", "BLZ", "084"},
|
|
||||||
{"British Indian Ocean Territory (the)", "Indien (le Territoire britannique de l'océan)", "IO", "IOT", "086"},
|
|
||||||
{"Solomon Islands", "Salomon (Îles)", "SB", "SLB", "090"},
|
|
||||||
{"Virgin Islands (British)", "Vierges britanniques (les Îles)", "VG", "VGB", "092"},
|
|
||||||
{"Brunei Darussalam", "Brunéi Darussalam (le)", "BN", "BRN", "096"},
|
|
||||||
{"Bulgaria", "Bulgarie (la)", "BG", "BGR", "100"},
|
|
||||||
{"Myanmar", "Myanmar (le)", "MM", "MMR", "104"},
|
|
||||||
{"Burundi", "Burundi (le)", "BI", "BDI", "108"},
|
|
||||||
{"Belarus", "Bélarus (le)", "BY", "BLR", "112"},
|
|
||||||
{"Cambodia", "Cambodge (le)", "KH", "KHM", "116"},
|
|
||||||
{"Cameroon", "Cameroun (le)", "CM", "CMR", "120"},
|
|
||||||
{"Canada", "Canada (le)", "CA", "CAN", "124"},
|
|
||||||
{"Cabo Verde", "Cabo Verde", "CV", "CPV", "132"},
|
|
||||||
{"Cayman Islands (the)", "Caïmans (les Îles)", "KY", "CYM", "136"},
|
|
||||||
{"Central African Republic (the)", "République centrafricaine (la)", "CF", "CAF", "140"},
|
|
||||||
{"Sri Lanka", "Sri Lanka", "LK", "LKA", "144"},
|
|
||||||
{"Chad", "Tchad (le)", "TD", "TCD", "148"},
|
|
||||||
{"Chile", "Chili (le)", "CL", "CHL", "152"},
|
|
||||||
{"China", "Chine (la)", "CN", "CHN", "156"},
|
|
||||||
{"Taiwan (Province of China)", "Taïwan (Province de Chine)", "TW", "TWN", "158"},
|
|
||||||
{"Christmas Island", "Christmas (l'Île)", "CX", "CXR", "162"},
|
|
||||||
{"Cocos (Keeling) Islands (the)", "Cocos (les Îles)/ Keeling (les Îles)", "CC", "CCK", "166"},
|
|
||||||
{"Colombia", "Colombie (la)", "CO", "COL", "170"},
|
|
||||||
{"Comoros (the)", "Comores (les)", "KM", "COM", "174"},
|
|
||||||
{"Mayotte", "Mayotte", "YT", "MYT", "175"},
|
|
||||||
{"Congo (the)", "Congo (le)", "CG", "COG", "178"},
|
|
||||||
{"Congo (the Democratic Republic of the)", "Congo (la République démocratique du)", "CD", "COD", "180"},
|
|
||||||
{"Cook Islands (the)", "Cook (les Îles)", "CK", "COK", "184"},
|
|
||||||
{"Costa Rica", "Costa Rica (le)", "CR", "CRI", "188"},
|
|
||||||
{"Croatia", "Croatie (la)", "HR", "HRV", "191"},
|
|
||||||
{"Cuba", "Cuba", "CU", "CUB", "192"},
|
|
||||||
{"Cyprus", "Chypre", "CY", "CYP", "196"},
|
|
||||||
{"Czech Republic (the)", "tchèque (la République)", "CZ", "CZE", "203"},
|
|
||||||
{"Benin", "Bénin (le)", "BJ", "BEN", "204"},
|
|
||||||
{"Denmark", "Danemark (le)", "DK", "DNK", "208"},
|
|
||||||
{"Dominica", "Dominique (la)", "DM", "DMA", "212"},
|
|
||||||
{"Dominican Republic (the)", "dominicaine (la République)", "DO", "DOM", "214"},
|
|
||||||
{"Ecuador", "Équateur (l')", "EC", "ECU", "218"},
|
|
||||||
{"El Salvador", "El Salvador", "SV", "SLV", "222"},
|
|
||||||
{"Equatorial Guinea", "Guinée équatoriale (la)", "GQ", "GNQ", "226"},
|
|
||||||
{"Ethiopia", "Éthiopie (l')", "ET", "ETH", "231"},
|
|
||||||
{"Eritrea", "Érythrée (l')", "ER", "ERI", "232"},
|
|
||||||
{"Estonia", "Estonie (l')", "EE", "EST", "233"},
|
|
||||||
{"Faroe Islands (the)", "Féroé (les Îles)", "FO", "FRO", "234"},
|
|
||||||
{"Falkland Islands (the) [Malvinas]", "Falkland (les Îles)/Malouines (les Îles)", "FK", "FLK", "238"},
|
|
||||||
{"South Georgia and the South Sandwich Islands", "Géorgie du Sud-et-les Îles Sandwich du Sud (la)", "GS", "SGS", "239"},
|
|
||||||
{"Fiji", "Fidji (les)", "FJ", "FJI", "242"},
|
|
||||||
{"Finland", "Finlande (la)", "FI", "FIN", "246"},
|
|
||||||
{"Åland Islands", "Åland(les Îles)", "AX", "ALA", "248"},
|
|
||||||
{"France", "France (la)", "FR", "FRA", "250"},
|
|
||||||
{"French Guiana", "Guyane française (la )", "GF", "GUF", "254"},
|
|
||||||
{"French Polynesia", "Polynésie française (la)", "PF", "PYF", "258"},
|
|
||||||
{"French Southern Territories (the)", "Terres australes françaises (les)", "TF", "ATF", "260"},
|
|
||||||
{"Djibouti", "Djibouti", "DJ", "DJI", "262"},
|
|
||||||
{"Gabon", "Gabon (le)", "GA", "GAB", "266"},
|
|
||||||
{"Georgia", "Géorgie (la)", "GE", "GEO", "268"},
|
|
||||||
{"Gambia (the)", "Gambie (la)", "GM", "GMB", "270"},
|
|
||||||
{"Palestine, State of", "Palestine, État de", "PS", "PSE", "275"},
|
|
||||||
{"Germany", "Allemagne (l')", "DE", "DEU", "276"},
|
|
||||||
{"Ghana", "Ghana (le)", "GH", "GHA", "288"},
|
|
||||||
{"Gibraltar", "Gibraltar", "GI", "GIB", "292"},
|
|
||||||
{"Kiribati", "Kiribati", "KI", "KIR", "296"},
|
|
||||||
{"Greece", "Grèce (la)", "GR", "GRC", "300"},
|
|
||||||
{"Greenland", "Groenland (le)", "GL", "GRL", "304"},
|
|
||||||
{"Grenada", "Grenade (la)", "GD", "GRD", "308"},
|
|
||||||
{"Guadeloupe", "Guadeloupe (la)", "GP", "GLP", "312"},
|
|
||||||
{"Guam", "Guam", "GU", "GUM", "316"},
|
|
||||||
{"Guatemala", "Guatemala (le)", "GT", "GTM", "320"},
|
|
||||||
{"Guinea", "Guinée (la)", "GN", "GIN", "324"},
|
|
||||||
{"Guyana", "Guyana (le)", "GY", "GUY", "328"},
|
|
||||||
{"Haiti", "Haïti", "HT", "HTI", "332"},
|
|
||||||
{"Heard Island and McDonald Islands", "Heard-et-Îles MacDonald (l'Île)", "HM", "HMD", "334"},
|
|
||||||
{"Holy See (the)", "Saint-Siège (le)", "VA", "VAT", "336"},
|
|
||||||
{"Honduras", "Honduras (le)", "HN", "HND", "340"},
|
|
||||||
{"Hong Kong", "Hong Kong", "HK", "HKG", "344"},
|
|
||||||
{"Hungary", "Hongrie (la)", "HU", "HUN", "348"},
|
|
||||||
{"Iceland", "Islande (l')", "IS", "ISL", "352"},
|
|
||||||
{"India", "Inde (l')", "IN", "IND", "356"},
|
|
||||||
{"Indonesia", "Indonésie (l')", "ID", "IDN", "360"},
|
|
||||||
{"Iran (Islamic Republic of)", "Iran (République Islamique d')", "IR", "IRN", "364"},
|
|
||||||
{"Iraq", "Iraq (l')", "IQ", "IRQ", "368"},
|
|
||||||
{"Ireland", "Irlande (l')", "IE", "IRL", "372"},
|
|
||||||
{"Israel", "Israël", "IL", "ISR", "376"},
|
|
||||||
{"Italy", "Italie (l')", "IT", "ITA", "380"},
|
|
||||||
{"Côte d'Ivoire", "Côte d'Ivoire (la)", "CI", "CIV", "384"},
|
|
||||||
{"Jamaica", "Jamaïque (la)", "JM", "JAM", "388"},
|
|
||||||
{"Japan", "Japon (le)", "JP", "JPN", "392"},
|
|
||||||
{"Kazakhstan", "Kazakhstan (le)", "KZ", "KAZ", "398"},
|
|
||||||
{"Jordan", "Jordanie (la)", "JO", "JOR", "400"},
|
|
||||||
{"Kenya", "Kenya (le)", "KE", "KEN", "404"},
|
|
||||||
{"Korea (the Democratic People's Republic of)", "Corée (la République populaire démocratique de)", "KP", "PRK", "408"},
|
|
||||||
{"Korea (the Republic of)", "Corée (la République de)", "KR", "KOR", "410"},
|
|
||||||
{"Kuwait", "Koweït (le)", "KW", "KWT", "414"},
|
|
||||||
{"Kyrgyzstan", "Kirghizistan (le)", "KG", "KGZ", "417"},
|
|
||||||
{"Lao People's Democratic Republic (the)", "Lao, République démocratique populaire", "LA", "LAO", "418"},
|
|
||||||
{"Lebanon", "Liban (le)", "LB", "LBN", "422"},
|
|
||||||
{"Lesotho", "Lesotho (le)", "LS", "LSO", "426"},
|
|
||||||
{"Latvia", "Lettonie (la)", "LV", "LVA", "428"},
|
|
||||||
{"Liberia", "Libéria (le)", "LR", "LBR", "430"},
|
|
||||||
{"Libya", "Libye (la)", "LY", "LBY", "434"},
|
|
||||||
{"Liechtenstein", "Liechtenstein (le)", "LI", "LIE", "438"},
|
|
||||||
{"Lithuania", "Lituanie (la)", "LT", "LTU", "440"},
|
|
||||||
{"Luxembourg", "Luxembourg (le)", "LU", "LUX", "442"},
|
|
||||||
{"Macao", "Macao", "MO", "MAC", "446"},
|
|
||||||
{"Madagascar", "Madagascar", "MG", "MDG", "450"},
|
|
||||||
{"Malawi", "Malawi (le)", "MW", "MWI", "454"},
|
|
||||||
{"Malaysia", "Malaisie (la)", "MY", "MYS", "458"},
|
|
||||||
{"Maldives", "Maldives (les)", "MV", "MDV", "462"},
|
|
||||||
{"Mali", "Mali (le)", "ML", "MLI", "466"},
|
|
||||||
{"Malta", "Malte", "MT", "MLT", "470"},
|
|
||||||
{"Martinique", "Martinique (la)", "MQ", "MTQ", "474"},
|
|
||||||
{"Mauritania", "Mauritanie (la)", "MR", "MRT", "478"},
|
|
||||||
{"Mauritius", "Maurice", "MU", "MUS", "480"},
|
|
||||||
{"Mexico", "Mexique (le)", "MX", "MEX", "484"},
|
|
||||||
{"Monaco", "Monaco", "MC", "MCO", "492"},
|
|
||||||
{"Mongolia", "Mongolie (la)", "MN", "MNG", "496"},
|
|
||||||
{"Moldova (the Republic of)", "Moldova , République de", "MD", "MDA", "498"},
|
|
||||||
{"Montenegro", "Monténégro (le)", "ME", "MNE", "499"},
|
|
||||||
{"Montserrat", "Montserrat", "MS", "MSR", "500"},
|
|
||||||
{"Morocco", "Maroc (le)", "MA", "MAR", "504"},
|
|
||||||
{"Mozambique", "Mozambique (le)", "MZ", "MOZ", "508"},
|
|
||||||
{"Oman", "Oman", "OM", "OMN", "512"},
|
|
||||||
{"Namibia", "Namibie (la)", "NA", "NAM", "516"},
|
|
||||||
{"Nauru", "Nauru", "NR", "NRU", "520"},
|
|
||||||
{"Nepal", "Népal (le)", "NP", "NPL", "524"},
|
|
||||||
{"Netherlands (the)", "Pays-Bas (les)", "NL", "NLD", "528"},
|
|
||||||
{"Curaçao", "Curaçao", "CW", "CUW", "531"},
|
|
||||||
{"Aruba", "Aruba", "AW", "ABW", "533"},
|
|
||||||
{"Sint Maarten (Dutch part)", "Saint-Martin (partie néerlandaise)", "SX", "SXM", "534"},
|
|
||||||
{"Bonaire, Sint Eustatius and Saba", "Bonaire, Saint-Eustache et Saba", "BQ", "BES", "535"},
|
|
||||||
{"New Caledonia", "Nouvelle-Calédonie (la)", "NC", "NCL", "540"},
|
|
||||||
{"Vanuatu", "Vanuatu (le)", "VU", "VUT", "548"},
|
|
||||||
{"New Zealand", "Nouvelle-Zélande (la)", "NZ", "NZL", "554"},
|
|
||||||
{"Nicaragua", "Nicaragua (le)", "NI", "NIC", "558"},
|
|
||||||
{"Niger (the)", "Niger (le)", "NE", "NER", "562"},
|
|
||||||
{"Nigeria", "Nigéria (le)", "NG", "NGA", "566"},
|
|
||||||
{"Niue", "Niue", "NU", "NIU", "570"},
|
|
||||||
{"Norfolk Island", "Norfolk (l'Île)", "NF", "NFK", "574"},
|
|
||||||
{"Norway", "Norvège (la)", "NO", "NOR", "578"},
|
|
||||||
{"Northern Mariana Islands (the)", "Mariannes du Nord (les Îles)", "MP", "MNP", "580"},
|
|
||||||
{"United States Minor Outlying Islands (the)", "Îles mineures éloignées des États-Unis (les)", "UM", "UMI", "581"},
|
|
||||||
{"Micronesia (Federated States of)", "Micronésie (États fédérés de)", "FM", "FSM", "583"},
|
|
||||||
{"Marshall Islands (the)", "Marshall (Îles)", "MH", "MHL", "584"},
|
|
||||||
{"Palau", "Palaos (les)", "PW", "PLW", "585"},
|
|
||||||
{"Pakistan", "Pakistan (le)", "PK", "PAK", "586"},
|
|
||||||
{"Panama", "Panama (le)", "PA", "PAN", "591"},
|
|
||||||
{"Papua New Guinea", "Papouasie-Nouvelle-Guinée (la)", "PG", "PNG", "598"},
|
|
||||||
{"Paraguay", "Paraguay (le)", "PY", "PRY", "600"},
|
|
||||||
{"Peru", "Pérou (le)", "PE", "PER", "604"},
|
|
||||||
{"Philippines (the)", "Philippines (les)", "PH", "PHL", "608"},
|
|
||||||
{"Pitcairn", "Pitcairn", "PN", "PCN", "612"},
|
|
||||||
{"Poland", "Pologne (la)", "PL", "POL", "616"},
|
|
||||||
{"Portugal", "Portugal (le)", "PT", "PRT", "620"},
|
|
||||||
{"Guinea-Bissau", "Guinée-Bissau (la)", "GW", "GNB", "624"},
|
|
||||||
{"Timor-Leste", "Timor-Leste (le)", "TL", "TLS", "626"},
|
|
||||||
{"Puerto Rico", "Porto Rico", "PR", "PRI", "630"},
|
|
||||||
{"Qatar", "Qatar (le)", "QA", "QAT", "634"},
|
|
||||||
{"Réunion", "Réunion (La)", "RE", "REU", "638"},
|
|
||||||
{"Romania", "Roumanie (la)", "RO", "ROU", "642"},
|
|
||||||
{"Russian Federation (the)", "Russie (la Fédération de)", "RU", "RUS", "643"},
|
|
||||||
{"Rwanda", "Rwanda (le)", "RW", "RWA", "646"},
|
|
||||||
{"Saint Barthélemy", "Saint-Barthélemy", "BL", "BLM", "652"},
|
|
||||||
{"Saint Helena, Ascension and Tristan da Cunha", "Sainte-Hélène, Ascension et Tristan da Cunha", "SH", "SHN", "654"},
|
|
||||||
{"Saint Kitts and Nevis", "Saint-Kitts-et-Nevis", "KN", "KNA", "659"},
|
|
||||||
{"Anguilla", "Anguilla", "AI", "AIA", "660"},
|
|
||||||
{"Saint Lucia", "Sainte-Lucie", "LC", "LCA", "662"},
|
|
||||||
{"Saint Martin (French part)", "Saint-Martin (partie française)", "MF", "MAF", "663"},
|
|
||||||
{"Saint Pierre and Miquelon", "Saint-Pierre-et-Miquelon", "PM", "SPM", "666"},
|
|
||||||
{"Saint Vincent and the Grenadines", "Saint-Vincent-et-les Grenadines", "VC", "VCT", "670"},
|
|
||||||
{"San Marino", "Saint-Marin", "SM", "SMR", "674"},
|
|
||||||
{"Sao Tome and Principe", "Sao Tomé-et-Principe", "ST", "STP", "678"},
|
|
||||||
{"Saudi Arabia", "Arabie saoudite (l')", "SA", "SAU", "682"},
|
|
||||||
{"Senegal", "Sénégal (le)", "SN", "SEN", "686"},
|
|
||||||
{"Serbia", "Serbie (la)", "RS", "SRB", "688"},
|
|
||||||
{"Seychelles", "Seychelles (les)", "SC", "SYC", "690"},
|
|
||||||
{"Sierra Leone", "Sierra Leone (la)", "SL", "SLE", "694"},
|
|
||||||
{"Singapore", "Singapour", "SG", "SGP", "702"},
|
|
||||||
{"Slovakia", "Slovaquie (la)", "SK", "SVK", "703"},
|
|
||||||
{"Viet Nam", "Viet Nam (le)", "VN", "VNM", "704"},
|
|
||||||
{"Slovenia", "Slovénie (la)", "SI", "SVN", "705"},
|
|
||||||
{"Somalia", "Somalie (la)", "SO", "SOM", "706"},
|
|
||||||
{"South Africa", "Afrique du Sud (l')", "ZA", "ZAF", "710"},
|
|
||||||
{"Zimbabwe", "Zimbabwe (le)", "ZW", "ZWE", "716"},
|
|
||||||
{"Spain", "Espagne (l')", "ES", "ESP", "724"},
|
|
||||||
{"South Sudan", "Soudan du Sud (le)", "SS", "SSD", "728"},
|
|
||||||
{"Sudan (the)", "Soudan (le)", "SD", "SDN", "729"},
|
|
||||||
{"Western Sahara*", "Sahara occidental (le)*", "EH", "ESH", "732"},
|
|
||||||
{"Suriname", "Suriname (le)", "SR", "SUR", "740"},
|
|
||||||
{"Svalbard and Jan Mayen", "Svalbard et l'Île Jan Mayen (le)", "SJ", "SJM", "744"},
|
|
||||||
{"Swaziland", "Swaziland (le)", "SZ", "SWZ", "748"},
|
|
||||||
{"Sweden", "Suède (la)", "SE", "SWE", "752"},
|
|
||||||
{"Switzerland", "Suisse (la)", "CH", "CHE", "756"},
|
|
||||||
{"Syrian Arab Republic", "République arabe syrienne (la)", "SY", "SYR", "760"},
|
|
||||||
{"Tajikistan", "Tadjikistan (le)", "TJ", "TJK", "762"},
|
|
||||||
{"Thailand", "Thaïlande (la)", "TH", "THA", "764"},
|
|
||||||
{"Togo", "Togo (le)", "TG", "TGO", "768"},
|
|
||||||
{"Tokelau", "Tokelau (les)", "TK", "TKL", "772"},
|
|
||||||
{"Tonga", "Tonga (les)", "TO", "TON", "776"},
|
|
||||||
{"Trinidad and Tobago", "Trinité-et-Tobago (la)", "TT", "TTO", "780"},
|
|
||||||
{"United Arab Emirates (the)", "Émirats arabes unis (les)", "AE", "ARE", "784"},
|
|
||||||
{"Tunisia", "Tunisie (la)", "TN", "TUN", "788"},
|
|
||||||
{"Turkey", "Turquie (la)", "TR", "TUR", "792"},
|
|
||||||
{"Turkmenistan", "Turkménistan (le)", "TM", "TKM", "795"},
|
|
||||||
{"Turks and Caicos Islands (the)", "Turks-et-Caïcos (les Îles)", "TC", "TCA", "796"},
|
|
||||||
{"Tuvalu", "Tuvalu (les)", "TV", "TUV", "798"},
|
|
||||||
{"Uganda", "Ouganda (l')", "UG", "UGA", "800"},
|
|
||||||
{"Ukraine", "Ukraine (l')", "UA", "UKR", "804"},
|
|
||||||
{"Macedonia (the former Yugoslav Republic of)", "Macédoine (l'ex‑République yougoslave de)", "MK", "MKD", "807"},
|
|
||||||
{"Egypt", "Égypte (l')", "EG", "EGY", "818"},
|
|
||||||
{"United Kingdom of Great Britain and Northern Ireland (the)", "Royaume-Uni de Grande-Bretagne et d'Irlande du Nord (le)", "GB", "GBR", "826"},
|
|
||||||
{"Guernsey", "Guernesey", "GG", "GGY", "831"},
|
|
||||||
{"Jersey", "Jersey", "JE", "JEY", "832"},
|
|
||||||
{"Isle of Man", "Île de Man", "IM", "IMN", "833"},
|
|
||||||
{"Tanzania, United Republic of", "Tanzanie, République-Unie de", "TZ", "TZA", "834"},
|
|
||||||
{"United States of America (the)", "États-Unis d'Amérique (les)", "US", "USA", "840"},
|
|
||||||
{"Virgin Islands (U.S.)", "Vierges des États-Unis (les Îles)", "VI", "VIR", "850"},
|
|
||||||
{"Burkina Faso", "Burkina Faso (le)", "BF", "BFA", "854"},
|
|
||||||
{"Uruguay", "Uruguay (l')", "UY", "URY", "858"},
|
|
||||||
{"Uzbekistan", "Ouzbékistan (l')", "UZ", "UZB", "860"},
|
|
||||||
{"Venezuela (Bolivarian Republic of)", "Venezuela (République bolivarienne du)", "VE", "VEN", "862"},
|
|
||||||
{"Wallis and Futuna", "Wallis-et-Futuna", "WF", "WLF", "876"},
|
|
||||||
{"Samoa", "Samoa (le)", "WS", "WSM", "882"},
|
|
||||||
{"Yemen", "Yémen (le)", "YE", "YEM", "887"},
|
|
||||||
{"Zambia", "Zambie (la)", "ZM", "ZMB", "894"},
|
|
||||||
}
|
|
||||||
|
|
||||||
// ISO4217List is the list of ISO currency codes
|
|
||||||
var ISO4217List = []string{
|
|
||||||
"AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN",
|
|
||||||
"BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BOV", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD",
|
|
||||||
"CAD", "CDF", "CHE", "CHF", "CHW", "CLF", "CLP", "CNY", "COP", "COU", "CRC", "CUC", "CUP", "CVE", "CZK",
|
|
||||||
"DJF", "DKK", "DOP", "DZD",
|
|
||||||
"EGP", "ERN", "ETB", "EUR",
|
|
||||||
"FJD", "FKP",
|
|
||||||
"GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD",
|
|
||||||
"HKD", "HNL", "HRK", "HTG", "HUF",
|
|
||||||
"IDR", "ILS", "INR", "IQD", "IRR", "ISK",
|
|
||||||
"JMD", "JOD", "JPY",
|
|
||||||
"KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT",
|
|
||||||
"LAK", "LBP", "LKR", "LRD", "LSL", "LYD",
|
|
||||||
"MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MUR", "MVR", "MWK", "MXN", "MXV", "MYR", "MZN",
|
|
||||||
"NAD", "NGN", "NIO", "NOK", "NPR", "NZD",
|
|
||||||
"OMR",
|
|
||||||
"PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG",
|
|
||||||
"QAR",
|
|
||||||
"RON", "RSD", "RUB", "RWF",
|
|
||||||
"SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STD", "SVC", "SYP", "SZL",
|
|
||||||
"THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS",
|
|
||||||
"UAH", "UGX", "USD", "USN", "UYI", "UYU", "UZS",
|
|
||||||
"VEF", "VND", "VUV",
|
|
||||||
"WST",
|
|
||||||
"XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XOF", "XPD", "XPF", "XPT", "XSU", "XTS", "XUA", "XXX",
|
|
||||||
"YER",
|
|
||||||
"ZAR", "ZMW", "ZWL",
|
|
||||||
}
|
|
||||||
|
|
||||||
// ISO693Entry stores ISO language codes
|
|
||||||
type ISO693Entry struct {
|
|
||||||
Alpha3bCode string
|
|
||||||
Alpha2Code string
|
|
||||||
English string
|
|
||||||
}
|
|
||||||
|
|
||||||
//ISO693List based on http://data.okfn.org/data/core/language-codes/r/language-codes-3b2.json
|
|
||||||
var ISO693List = []ISO693Entry{
|
|
||||||
{Alpha3bCode: "aar", Alpha2Code: "aa", English: "Afar"},
|
|
||||||
{Alpha3bCode: "abk", Alpha2Code: "ab", English: "Abkhazian"},
|
|
||||||
{Alpha3bCode: "afr", Alpha2Code: "af", English: "Afrikaans"},
|
|
||||||
{Alpha3bCode: "aka", Alpha2Code: "ak", English: "Akan"},
|
|
||||||
{Alpha3bCode: "alb", Alpha2Code: "sq", English: "Albanian"},
|
|
||||||
{Alpha3bCode: "amh", Alpha2Code: "am", English: "Amharic"},
|
|
||||||
{Alpha3bCode: "ara", Alpha2Code: "ar", English: "Arabic"},
|
|
||||||
{Alpha3bCode: "arg", Alpha2Code: "an", English: "Aragonese"},
|
|
||||||
{Alpha3bCode: "arm", Alpha2Code: "hy", English: "Armenian"},
|
|
||||||
{Alpha3bCode: "asm", Alpha2Code: "as", English: "Assamese"},
|
|
||||||
{Alpha3bCode: "ava", Alpha2Code: "av", English: "Avaric"},
|
|
||||||
{Alpha3bCode: "ave", Alpha2Code: "ae", English: "Avestan"},
|
|
||||||
{Alpha3bCode: "aym", Alpha2Code: "ay", English: "Aymara"},
|
|
||||||
{Alpha3bCode: "aze", Alpha2Code: "az", English: "Azerbaijani"},
|
|
||||||
{Alpha3bCode: "bak", Alpha2Code: "ba", English: "Bashkir"},
|
|
||||||
{Alpha3bCode: "bam", Alpha2Code: "bm", English: "Bambara"},
|
|
||||||
{Alpha3bCode: "baq", Alpha2Code: "eu", English: "Basque"},
|
|
||||||
{Alpha3bCode: "bel", Alpha2Code: "be", English: "Belarusian"},
|
|
||||||
{Alpha3bCode: "ben", Alpha2Code: "bn", English: "Bengali"},
|
|
||||||
{Alpha3bCode: "bih", Alpha2Code: "bh", English: "Bihari languages"},
|
|
||||||
{Alpha3bCode: "bis", Alpha2Code: "bi", English: "Bislama"},
|
|
||||||
{Alpha3bCode: "bos", Alpha2Code: "bs", English: "Bosnian"},
|
|
||||||
{Alpha3bCode: "bre", Alpha2Code: "br", English: "Breton"},
|
|
||||||
{Alpha3bCode: "bul", Alpha2Code: "bg", English: "Bulgarian"},
|
|
||||||
{Alpha3bCode: "bur", Alpha2Code: "my", English: "Burmese"},
|
|
||||||
{Alpha3bCode: "cat", Alpha2Code: "ca", English: "Catalan; Valencian"},
|
|
||||||
{Alpha3bCode: "cha", Alpha2Code: "ch", English: "Chamorro"},
|
|
||||||
{Alpha3bCode: "che", Alpha2Code: "ce", English: "Chechen"},
|
|
||||||
{Alpha3bCode: "chi", Alpha2Code: "zh", English: "Chinese"},
|
|
||||||
{Alpha3bCode: "chu", Alpha2Code: "cu", English: "Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic"},
|
|
||||||
{Alpha3bCode: "chv", Alpha2Code: "cv", English: "Chuvash"},
|
|
||||||
{Alpha3bCode: "cor", Alpha2Code: "kw", English: "Cornish"},
|
|
||||||
{Alpha3bCode: "cos", Alpha2Code: "co", English: "Corsican"},
|
|
||||||
{Alpha3bCode: "cre", Alpha2Code: "cr", English: "Cree"},
|
|
||||||
{Alpha3bCode: "cze", Alpha2Code: "cs", English: "Czech"},
|
|
||||||
{Alpha3bCode: "dan", Alpha2Code: "da", English: "Danish"},
|
|
||||||
{Alpha3bCode: "div", Alpha2Code: "dv", English: "Divehi; Dhivehi; Maldivian"},
|
|
||||||
{Alpha3bCode: "dut", Alpha2Code: "nl", English: "Dutch; Flemish"},
|
|
||||||
{Alpha3bCode: "dzo", Alpha2Code: "dz", English: "Dzongkha"},
|
|
||||||
{Alpha3bCode: "eng", Alpha2Code: "en", English: "English"},
|
|
||||||
{Alpha3bCode: "epo", Alpha2Code: "eo", English: "Esperanto"},
|
|
||||||
{Alpha3bCode: "est", Alpha2Code: "et", English: "Estonian"},
|
|
||||||
{Alpha3bCode: "ewe", Alpha2Code: "ee", English: "Ewe"},
|
|
||||||
{Alpha3bCode: "fao", Alpha2Code: "fo", English: "Faroese"},
|
|
||||||
{Alpha3bCode: "fij", Alpha2Code: "fj", English: "Fijian"},
|
|
||||||
{Alpha3bCode: "fin", Alpha2Code: "fi", English: "Finnish"},
|
|
||||||
{Alpha3bCode: "fre", Alpha2Code: "fr", English: "French"},
|
|
||||||
{Alpha3bCode: "fry", Alpha2Code: "fy", English: "Western Frisian"},
|
|
||||||
{Alpha3bCode: "ful", Alpha2Code: "ff", English: "Fulah"},
|
|
||||||
{Alpha3bCode: "geo", Alpha2Code: "ka", English: "Georgian"},
|
|
||||||
{Alpha3bCode: "ger", Alpha2Code: "de", English: "German"},
|
|
||||||
{Alpha3bCode: "gla", Alpha2Code: "gd", English: "Gaelic; Scottish Gaelic"},
|
|
||||||
{Alpha3bCode: "gle", Alpha2Code: "ga", English: "Irish"},
|
|
||||||
{Alpha3bCode: "glg", Alpha2Code: "gl", English: "Galician"},
|
|
||||||
{Alpha3bCode: "glv", Alpha2Code: "gv", English: "Manx"},
|
|
||||||
{Alpha3bCode: "gre", Alpha2Code: "el", English: "Greek, Modern (1453-)"},
|
|
||||||
{Alpha3bCode: "grn", Alpha2Code: "gn", English: "Guarani"},
|
|
||||||
{Alpha3bCode: "guj", Alpha2Code: "gu", English: "Gujarati"},
|
|
||||||
{Alpha3bCode: "hat", Alpha2Code: "ht", English: "Haitian; Haitian Creole"},
|
|
||||||
{Alpha3bCode: "hau", Alpha2Code: "ha", English: "Hausa"},
|
|
||||||
{Alpha3bCode: "heb", Alpha2Code: "he", English: "Hebrew"},
|
|
||||||
{Alpha3bCode: "her", Alpha2Code: "hz", English: "Herero"},
|
|
||||||
{Alpha3bCode: "hin", Alpha2Code: "hi", English: "Hindi"},
|
|
||||||
{Alpha3bCode: "hmo", Alpha2Code: "ho", English: "Hiri Motu"},
|
|
||||||
{Alpha3bCode: "hrv", Alpha2Code: "hr", English: "Croatian"},
|
|
||||||
{Alpha3bCode: "hun", Alpha2Code: "hu", English: "Hungarian"},
|
|
||||||
{Alpha3bCode: "ibo", Alpha2Code: "ig", English: "Igbo"},
|
|
||||||
{Alpha3bCode: "ice", Alpha2Code: "is", English: "Icelandic"},
|
|
||||||
{Alpha3bCode: "ido", Alpha2Code: "io", English: "Ido"},
|
|
||||||
{Alpha3bCode: "iii", Alpha2Code: "ii", English: "Sichuan Yi; Nuosu"},
|
|
||||||
{Alpha3bCode: "iku", Alpha2Code: "iu", English: "Inuktitut"},
|
|
||||||
{Alpha3bCode: "ile", Alpha2Code: "ie", English: "Interlingue; Occidental"},
|
|
||||||
{Alpha3bCode: "ina", Alpha2Code: "ia", English: "Interlingua (International Auxiliary Language Association)"},
|
|
||||||
{Alpha3bCode: "ind", Alpha2Code: "id", English: "Indonesian"},
|
|
||||||
{Alpha3bCode: "ipk", Alpha2Code: "ik", English: "Inupiaq"},
|
|
||||||
{Alpha3bCode: "ita", Alpha2Code: "it", English: "Italian"},
|
|
||||||
{Alpha3bCode: "jav", Alpha2Code: "jv", English: "Javanese"},
|
|
||||||
{Alpha3bCode: "jpn", Alpha2Code: "ja", English: "Japanese"},
|
|
||||||
{Alpha3bCode: "kal", Alpha2Code: "kl", English: "Kalaallisut; Greenlandic"},
|
|
||||||
{Alpha3bCode: "kan", Alpha2Code: "kn", English: "Kannada"},
|
|
||||||
{Alpha3bCode: "kas", Alpha2Code: "ks", English: "Kashmiri"},
|
|
||||||
{Alpha3bCode: "kau", Alpha2Code: "kr", English: "Kanuri"},
|
|
||||||
{Alpha3bCode: "kaz", Alpha2Code: "kk", English: "Kazakh"},
|
|
||||||
{Alpha3bCode: "khm", Alpha2Code: "km", English: "Central Khmer"},
|
|
||||||
{Alpha3bCode: "kik", Alpha2Code: "ki", English: "Kikuyu; Gikuyu"},
|
|
||||||
{Alpha3bCode: "kin", Alpha2Code: "rw", English: "Kinyarwanda"},
|
|
||||||
{Alpha3bCode: "kir", Alpha2Code: "ky", English: "Kirghiz; Kyrgyz"},
|
|
||||||
{Alpha3bCode: "kom", Alpha2Code: "kv", English: "Komi"},
|
|
||||||
{Alpha3bCode: "kon", Alpha2Code: "kg", English: "Kongo"},
|
|
||||||
{Alpha3bCode: "kor", Alpha2Code: "ko", English: "Korean"},
|
|
||||||
{Alpha3bCode: "kua", Alpha2Code: "kj", English: "Kuanyama; Kwanyama"},
|
|
||||||
{Alpha3bCode: "kur", Alpha2Code: "ku", English: "Kurdish"},
|
|
||||||
{Alpha3bCode: "lao", Alpha2Code: "lo", English: "Lao"},
|
|
||||||
{Alpha3bCode: "lat", Alpha2Code: "la", English: "Latin"},
|
|
||||||
{Alpha3bCode: "lav", Alpha2Code: "lv", English: "Latvian"},
|
|
||||||
{Alpha3bCode: "lim", Alpha2Code: "li", English: "Limburgan; Limburger; Limburgish"},
|
|
||||||
{Alpha3bCode: "lin", Alpha2Code: "ln", English: "Lingala"},
|
|
||||||
{Alpha3bCode: "lit", Alpha2Code: "lt", English: "Lithuanian"},
|
|
||||||
{Alpha3bCode: "ltz", Alpha2Code: "lb", English: "Luxembourgish; Letzeburgesch"},
|
|
||||||
{Alpha3bCode: "lub", Alpha2Code: "lu", English: "Luba-Katanga"},
|
|
||||||
{Alpha3bCode: "lug", Alpha2Code: "lg", English: "Ganda"},
|
|
||||||
{Alpha3bCode: "mac", Alpha2Code: "mk", English: "Macedonian"},
|
|
||||||
{Alpha3bCode: "mah", Alpha2Code: "mh", English: "Marshallese"},
|
|
||||||
{Alpha3bCode: "mal", Alpha2Code: "ml", English: "Malayalam"},
|
|
||||||
{Alpha3bCode: "mao", Alpha2Code: "mi", English: "Maori"},
|
|
||||||
{Alpha3bCode: "mar", Alpha2Code: "mr", English: "Marathi"},
|
|
||||||
{Alpha3bCode: "may", Alpha2Code: "ms", English: "Malay"},
|
|
||||||
{Alpha3bCode: "mlg", Alpha2Code: "mg", English: "Malagasy"},
|
|
||||||
{Alpha3bCode: "mlt", Alpha2Code: "mt", English: "Maltese"},
|
|
||||||
{Alpha3bCode: "mon", Alpha2Code: "mn", English: "Mongolian"},
|
|
||||||
{Alpha3bCode: "nau", Alpha2Code: "na", English: "Nauru"},
|
|
||||||
{Alpha3bCode: "nav", Alpha2Code: "nv", English: "Navajo; Navaho"},
|
|
||||||
{Alpha3bCode: "nbl", Alpha2Code: "nr", English: "Ndebele, South; South Ndebele"},
|
|
||||||
{Alpha3bCode: "nde", Alpha2Code: "nd", English: "Ndebele, North; North Ndebele"},
|
|
||||||
{Alpha3bCode: "ndo", Alpha2Code: "ng", English: "Ndonga"},
|
|
||||||
{Alpha3bCode: "nep", Alpha2Code: "ne", English: "Nepali"},
|
|
||||||
{Alpha3bCode: "nno", Alpha2Code: "nn", English: "Norwegian Nynorsk; Nynorsk, Norwegian"},
|
|
||||||
{Alpha3bCode: "nob", Alpha2Code: "nb", English: "Bokmål, Norwegian; Norwegian Bokmål"},
|
|
||||||
{Alpha3bCode: "nor", Alpha2Code: "no", English: "Norwegian"},
|
|
||||||
{Alpha3bCode: "nya", Alpha2Code: "ny", English: "Chichewa; Chewa; Nyanja"},
|
|
||||||
{Alpha3bCode: "oci", Alpha2Code: "oc", English: "Occitan (post 1500); Provençal"},
|
|
||||||
{Alpha3bCode: "oji", Alpha2Code: "oj", English: "Ojibwa"},
|
|
||||||
{Alpha3bCode: "ori", Alpha2Code: "or", English: "Oriya"},
|
|
||||||
{Alpha3bCode: "orm", Alpha2Code: "om", English: "Oromo"},
|
|
||||||
{Alpha3bCode: "oss", Alpha2Code: "os", English: "Ossetian; Ossetic"},
|
|
||||||
{Alpha3bCode: "pan", Alpha2Code: "pa", English: "Panjabi; Punjabi"},
|
|
||||||
{Alpha3bCode: "per", Alpha2Code: "fa", English: "Persian"},
|
|
||||||
{Alpha3bCode: "pli", Alpha2Code: "pi", English: "Pali"},
|
|
||||||
{Alpha3bCode: "pol", Alpha2Code: "pl", English: "Polish"},
|
|
||||||
{Alpha3bCode: "por", Alpha2Code: "pt", English: "Portuguese"},
|
|
||||||
{Alpha3bCode: "pus", Alpha2Code: "ps", English: "Pushto; Pashto"},
|
|
||||||
{Alpha3bCode: "que", Alpha2Code: "qu", English: "Quechua"},
|
|
||||||
{Alpha3bCode: "roh", Alpha2Code: "rm", English: "Romansh"},
|
|
||||||
{Alpha3bCode: "rum", Alpha2Code: "ro", English: "Romanian; Moldavian; Moldovan"},
|
|
||||||
{Alpha3bCode: "run", Alpha2Code: "rn", English: "Rundi"},
|
|
||||||
{Alpha3bCode: "rus", Alpha2Code: "ru", English: "Russian"},
|
|
||||||
{Alpha3bCode: "sag", Alpha2Code: "sg", English: "Sango"},
|
|
||||||
{Alpha3bCode: "san", Alpha2Code: "sa", English: "Sanskrit"},
|
|
||||||
{Alpha3bCode: "sin", Alpha2Code: "si", English: "Sinhala; Sinhalese"},
|
|
||||||
{Alpha3bCode: "slo", Alpha2Code: "sk", English: "Slovak"},
|
|
||||||
{Alpha3bCode: "slv", Alpha2Code: "sl", English: "Slovenian"},
|
|
||||||
{Alpha3bCode: "sme", Alpha2Code: "se", English: "Northern Sami"},
|
|
||||||
{Alpha3bCode: "smo", Alpha2Code: "sm", English: "Samoan"},
|
|
||||||
{Alpha3bCode: "sna", Alpha2Code: "sn", English: "Shona"},
|
|
||||||
{Alpha3bCode: "snd", Alpha2Code: "sd", English: "Sindhi"},
|
|
||||||
{Alpha3bCode: "som", Alpha2Code: "so", English: "Somali"},
|
|
||||||
{Alpha3bCode: "sot", Alpha2Code: "st", English: "Sotho, Southern"},
|
|
||||||
{Alpha3bCode: "spa", Alpha2Code: "es", English: "Spanish; Castilian"},
|
|
||||||
{Alpha3bCode: "srd", Alpha2Code: "sc", English: "Sardinian"},
|
|
||||||
{Alpha3bCode: "srp", Alpha2Code: "sr", English: "Serbian"},
|
|
||||||
{Alpha3bCode: "ssw", Alpha2Code: "ss", English: "Swati"},
|
|
||||||
{Alpha3bCode: "sun", Alpha2Code: "su", English: "Sundanese"},
|
|
||||||
{Alpha3bCode: "swa", Alpha2Code: "sw", English: "Swahili"},
|
|
||||||
{Alpha3bCode: "swe", Alpha2Code: "sv", English: "Swedish"},
|
|
||||||
{Alpha3bCode: "tah", Alpha2Code: "ty", English: "Tahitian"},
|
|
||||||
{Alpha3bCode: "tam", Alpha2Code: "ta", English: "Tamil"},
|
|
||||||
{Alpha3bCode: "tat", Alpha2Code: "tt", English: "Tatar"},
|
|
||||||
{Alpha3bCode: "tel", Alpha2Code: "te", English: "Telugu"},
|
|
||||||
{Alpha3bCode: "tgk", Alpha2Code: "tg", English: "Tajik"},
|
|
||||||
{Alpha3bCode: "tgl", Alpha2Code: "tl", English: "Tagalog"},
|
|
||||||
{Alpha3bCode: "tha", Alpha2Code: "th", English: "Thai"},
|
|
||||||
{Alpha3bCode: "tib", Alpha2Code: "bo", English: "Tibetan"},
|
|
||||||
{Alpha3bCode: "tir", Alpha2Code: "ti", English: "Tigrinya"},
|
|
||||||
{Alpha3bCode: "ton", Alpha2Code: "to", English: "Tonga (Tonga Islands)"},
|
|
||||||
{Alpha3bCode: "tsn", Alpha2Code: "tn", English: "Tswana"},
|
|
||||||
{Alpha3bCode: "tso", Alpha2Code: "ts", English: "Tsonga"},
|
|
||||||
{Alpha3bCode: "tuk", Alpha2Code: "tk", English: "Turkmen"},
|
|
||||||
{Alpha3bCode: "tur", Alpha2Code: "tr", English: "Turkish"},
|
|
||||||
{Alpha3bCode: "twi", Alpha2Code: "tw", English: "Twi"},
|
|
||||||
{Alpha3bCode: "uig", Alpha2Code: "ug", English: "Uighur; Uyghur"},
|
|
||||||
{Alpha3bCode: "ukr", Alpha2Code: "uk", English: "Ukrainian"},
|
|
||||||
{Alpha3bCode: "urd", Alpha2Code: "ur", English: "Urdu"},
|
|
||||||
{Alpha3bCode: "uzb", Alpha2Code: "uz", English: "Uzbek"},
|
|
||||||
{Alpha3bCode: "ven", Alpha2Code: "ve", English: "Venda"},
|
|
||||||
{Alpha3bCode: "vie", Alpha2Code: "vi", English: "Vietnamese"},
|
|
||||||
{Alpha3bCode: "vol", Alpha2Code: "vo", English: "Volapük"},
|
|
||||||
{Alpha3bCode: "wel", Alpha2Code: "cy", English: "Welsh"},
|
|
||||||
{Alpha3bCode: "wln", Alpha2Code: "wa", English: "Walloon"},
|
|
||||||
{Alpha3bCode: "wol", Alpha2Code: "wo", English: "Wolof"},
|
|
||||||
{Alpha3bCode: "xho", Alpha2Code: "xh", English: "Xhosa"},
|
|
||||||
{Alpha3bCode: "yid", Alpha2Code: "yi", English: "Yiddish"},
|
|
||||||
{Alpha3bCode: "yor", Alpha2Code: "yo", English: "Yoruba"},
|
|
||||||
{Alpha3bCode: "zha", Alpha2Code: "za", English: "Zhuang; Chuang"},
|
|
||||||
{Alpha3bCode: "zul", Alpha2Code: "zu", English: "Zulu"},
|
|
||||||
}
|
|
264
vendor/github.com/asaskevich/govalidator/utils.go
generated
vendored
264
vendor/github.com/asaskevich/govalidator/utils.go
generated
vendored
|
@ -1,264 +0,0 @@
|
||||||
package govalidator
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"html"
|
|
||||||
"math"
|
|
||||||
"path"
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
"unicode"
|
|
||||||
"unicode/utf8"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Contains check if the string contains the substring.
|
|
||||||
func Contains(str, substring string) bool {
|
|
||||||
return strings.Contains(str, substring)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Matches check if string matches the pattern (pattern is regular expression)
|
|
||||||
// In case of error return false
|
|
||||||
func Matches(str, pattern string) bool {
|
|
||||||
match, _ := regexp.MatchString(pattern, str)
|
|
||||||
return match
|
|
||||||
}
|
|
||||||
|
|
||||||
// LeftTrim trim characters from the left-side of the input.
|
|
||||||
// If second argument is empty, it's will be remove leading spaces.
|
|
||||||
func LeftTrim(str, chars string) string {
|
|
||||||
if chars == "" {
|
|
||||||
return strings.TrimLeftFunc(str, unicode.IsSpace)
|
|
||||||
}
|
|
||||||
r, _ := regexp.Compile("^[" + chars + "]+")
|
|
||||||
return r.ReplaceAllString(str, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
// RightTrim trim characters from the right-side of the input.
|
|
||||||
// If second argument is empty, it's will be remove spaces.
|
|
||||||
func RightTrim(str, chars string) string {
|
|
||||||
if chars == "" {
|
|
||||||
return strings.TrimRightFunc(str, unicode.IsSpace)
|
|
||||||
}
|
|
||||||
r, _ := regexp.Compile("[" + chars + "]+$")
|
|
||||||
return r.ReplaceAllString(str, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trim trim characters from both sides of the input.
|
|
||||||
// If second argument is empty, it's will be remove spaces.
|
|
||||||
func Trim(str, chars string) string {
|
|
||||||
return LeftTrim(RightTrim(str, chars), chars)
|
|
||||||
}
|
|
||||||
|
|
||||||
// WhiteList remove characters that do not appear in the whitelist.
|
|
||||||
func WhiteList(str, chars string) string {
|
|
||||||
pattern := "[^" + chars + "]+"
|
|
||||||
r, _ := regexp.Compile(pattern)
|
|
||||||
return r.ReplaceAllString(str, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
// BlackList remove characters that appear in the blacklist.
|
|
||||||
func BlackList(str, chars string) string {
|
|
||||||
pattern := "[" + chars + "]+"
|
|
||||||
r, _ := regexp.Compile(pattern)
|
|
||||||
return r.ReplaceAllString(str, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
// StripLow remove characters with a numerical value < 32 and 127, mostly control characters.
|
|
||||||
// If keep_new_lines is true, newline characters are preserved (\n and \r, hex 0xA and 0xD).
|
|
||||||
func StripLow(str string, keepNewLines bool) string {
|
|
||||||
chars := ""
|
|
||||||
if keepNewLines {
|
|
||||||
chars = "\x00-\x09\x0B\x0C\x0E-\x1F\x7F"
|
|
||||||
} else {
|
|
||||||
chars = "\x00-\x1F\x7F"
|
|
||||||
}
|
|
||||||
return BlackList(str, chars)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReplacePattern replace regular expression pattern in string
|
|
||||||
func ReplacePattern(str, pattern, replace string) string {
|
|
||||||
r, _ := regexp.Compile(pattern)
|
|
||||||
return r.ReplaceAllString(str, replace)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Escape replace <, >, & and " with HTML entities.
|
|
||||||
var Escape = html.EscapeString
|
|
||||||
|
|
||||||
func addSegment(inrune, segment []rune) []rune {
|
|
||||||
if len(segment) == 0 {
|
|
||||||
return inrune
|
|
||||||
}
|
|
||||||
if len(inrune) != 0 {
|
|
||||||
inrune = append(inrune, '_')
|
|
||||||
}
|
|
||||||
inrune = append(inrune, segment...)
|
|
||||||
return inrune
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnderscoreToCamelCase converts from underscore separated form to camel case form.
|
|
||||||
// Ex.: my_func => MyFunc
|
|
||||||
func UnderscoreToCamelCase(s string) string {
|
|
||||||
return strings.Replace(strings.Title(strings.Replace(strings.ToLower(s), "_", " ", -1)), " ", "", -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CamelCaseToUnderscore converts from camel case form to underscore separated form.
|
|
||||||
// Ex.: MyFunc => my_func
|
|
||||||
func CamelCaseToUnderscore(str string) string {
|
|
||||||
var output []rune
|
|
||||||
var segment []rune
|
|
||||||
for _, r := range str {
|
|
||||||
|
|
||||||
// not treat number as separate segment
|
|
||||||
if !unicode.IsLower(r) && string(r) != "_" && !unicode.IsNumber(r) {
|
|
||||||
output = addSegment(output, segment)
|
|
||||||
segment = nil
|
|
||||||
}
|
|
||||||
segment = append(segment, unicode.ToLower(r))
|
|
||||||
}
|
|
||||||
output = addSegment(output, segment)
|
|
||||||
return string(output)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reverse return reversed string
|
|
||||||
func Reverse(s string) string {
|
|
||||||
r := []rune(s)
|
|
||||||
for i, j := 0, len(r)-1; i < j; i, j = i+1, j-1 {
|
|
||||||
r[i], r[j] = r[j], r[i]
|
|
||||||
}
|
|
||||||
return string(r)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetLines split string by "\n" and return array of lines
|
|
||||||
func GetLines(s string) []string {
|
|
||||||
return strings.Split(s, "\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetLine return specified line of multiline string
|
|
||||||
func GetLine(s string, index int) (string, error) {
|
|
||||||
lines := GetLines(s)
|
|
||||||
if index < 0 || index >= len(lines) {
|
|
||||||
return "", errors.New("line index out of bounds")
|
|
||||||
}
|
|
||||||
return lines[index], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveTags remove all tags from HTML string
|
|
||||||
func RemoveTags(s string) string {
|
|
||||||
return ReplacePattern(s, "<[^>]*>", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
// SafeFileName return safe string that can be used in file names
|
|
||||||
func SafeFileName(str string) string {
|
|
||||||
name := strings.ToLower(str)
|
|
||||||
name = path.Clean(path.Base(name))
|
|
||||||
name = strings.Trim(name, " ")
|
|
||||||
separators, err := regexp.Compile(`[ &_=+:]`)
|
|
||||||
if err == nil {
|
|
||||||
name = separators.ReplaceAllString(name, "-")
|
|
||||||
}
|
|
||||||
legal, err := regexp.Compile(`[^[:alnum:]-.]`)
|
|
||||||
if err == nil {
|
|
||||||
name = legal.ReplaceAllString(name, "")
|
|
||||||
}
|
|
||||||
for strings.Contains(name, "--") {
|
|
||||||
name = strings.Replace(name, "--", "-", -1)
|
|
||||||
}
|
|
||||||
return name
|
|
||||||
}
|
|
||||||
|
|
||||||
// NormalizeEmail canonicalize an email address.
|
|
||||||
// The local part of the email address is lowercased for all domains; the hostname is always lowercased and
|
|
||||||
// the local part of the email address is always lowercased for hosts that are known to be case-insensitive (currently only GMail).
|
|
||||||
// Normalization follows special rules for known providers: currently, GMail addresses have dots removed in the local part and
|
|
||||||
// are stripped of tags (e.g. some.one+tag@gmail.com becomes someone@gmail.com) and all @googlemail.com addresses are
|
|
||||||
// normalized to @gmail.com.
|
|
||||||
func NormalizeEmail(str string) (string, error) {
|
|
||||||
if !IsEmail(str) {
|
|
||||||
return "", fmt.Errorf("%s is not an email", str)
|
|
||||||
}
|
|
||||||
parts := strings.Split(str, "@")
|
|
||||||
parts[0] = strings.ToLower(parts[0])
|
|
||||||
parts[1] = strings.ToLower(parts[1])
|
|
||||||
if parts[1] == "gmail.com" || parts[1] == "googlemail.com" {
|
|
||||||
parts[1] = "gmail.com"
|
|
||||||
parts[0] = strings.Split(ReplacePattern(parts[0], `\.`, ""), "+")[0]
|
|
||||||
}
|
|
||||||
return strings.Join(parts, "@"), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Truncate a string to the closest length without breaking words.
|
|
||||||
func Truncate(str string, length int, ending string) string {
|
|
||||||
var aftstr, befstr string
|
|
||||||
if len(str) > length {
|
|
||||||
words := strings.Fields(str)
|
|
||||||
before, present := 0, 0
|
|
||||||
for i := range words {
|
|
||||||
befstr = aftstr
|
|
||||||
before = present
|
|
||||||
aftstr = aftstr + words[i] + " "
|
|
||||||
present = len(aftstr)
|
|
||||||
if present > length && i != 0 {
|
|
||||||
if (length - before) < (present - length) {
|
|
||||||
return Trim(befstr, " /\\.,\"'#!?&@+-") + ending
|
|
||||||
}
|
|
||||||
return Trim(aftstr, " /\\.,\"'#!?&@+-") + ending
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return str
|
|
||||||
}
|
|
||||||
|
|
||||||
// PadLeft pad left side of string if size of string is less then indicated pad length
|
|
||||||
func PadLeft(str string, padStr string, padLen int) string {
|
|
||||||
return buildPadStr(str, padStr, padLen, true, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PadRight pad right side of string if size of string is less then indicated pad length
|
|
||||||
func PadRight(str string, padStr string, padLen int) string {
|
|
||||||
return buildPadStr(str, padStr, padLen, false, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PadBoth pad sides of string if size of string is less then indicated pad length
|
|
||||||
func PadBoth(str string, padStr string, padLen int) string {
|
|
||||||
return buildPadStr(str, padStr, padLen, true, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PadString either left, right or both sides, not the padding string can be unicode and more then one
|
|
||||||
// character
|
|
||||||
func buildPadStr(str string, padStr string, padLen int, padLeft bool, padRight bool) string {
|
|
||||||
|
|
||||||
// When padded length is less then the current string size
|
|
||||||
if padLen < utf8.RuneCountInString(str) {
|
|
||||||
return str
|
|
||||||
}
|
|
||||||
|
|
||||||
padLen -= utf8.RuneCountInString(str)
|
|
||||||
|
|
||||||
targetLen := padLen
|
|
||||||
|
|
||||||
targetLenLeft := targetLen
|
|
||||||
targetLenRight := targetLen
|
|
||||||
if padLeft && padRight {
|
|
||||||
targetLenLeft = padLen / 2
|
|
||||||
targetLenRight = padLen - targetLenLeft
|
|
||||||
}
|
|
||||||
|
|
||||||
strToRepeatLen := utf8.RuneCountInString(padStr)
|
|
||||||
|
|
||||||
repeatTimes := int(math.Ceil(float64(targetLen) / float64(strToRepeatLen)))
|
|
||||||
repeatedString := strings.Repeat(padStr, repeatTimes)
|
|
||||||
|
|
||||||
leftSide := ""
|
|
||||||
if padLeft {
|
|
||||||
leftSide = repeatedString[0:targetLenLeft]
|
|
||||||
}
|
|
||||||
|
|
||||||
rightSide := ""
|
|
||||||
if padRight {
|
|
||||||
rightSide = repeatedString[0:targetLenRight]
|
|
||||||
}
|
|
||||||
|
|
||||||
return leftSide + str + rightSide
|
|
||||||
}
|
|
1213
vendor/github.com/asaskevich/govalidator/validator.go
generated
vendored
1213
vendor/github.com/asaskevich/govalidator/validator.go
generated
vendored
File diff suppressed because it is too large
Load diff
21
vendor/github.com/hpcloud/tail/LICENSE.txt
generated
vendored
21
vendor/github.com/hpcloud/tail/LICENSE.txt
generated
vendored
|
@ -1,21 +0,0 @@
|
||||||
# The MIT License (MIT)
|
|
||||||
|
|
||||||
# © Copyright 2015 Hewlett Packard Enterprise Development LP
|
|
||||||
Copyright (c) 2014 ActiveState
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
7
vendor/github.com/hpcloud/tail/ratelimiter/Licence
generated
vendored
7
vendor/github.com/hpcloud/tail/ratelimiter/Licence
generated
vendored
|
@ -1,7 +0,0 @@
|
||||||
Copyright (C) 2013 99designs
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
97
vendor/github.com/hpcloud/tail/ratelimiter/leakybucket.go
generated
vendored
97
vendor/github.com/hpcloud/tail/ratelimiter/leakybucket.go
generated
vendored
|
@ -1,97 +0,0 @@
|
||||||
// Package ratelimiter implements the Leaky Bucket ratelimiting algorithm with memcached and in-memory backends.
|
|
||||||
package ratelimiter
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type LeakyBucket struct {
|
|
||||||
Size uint16
|
|
||||||
Fill float64
|
|
||||||
LeakInterval time.Duration // time.Duration for 1 unit of size to leak
|
|
||||||
Lastupdate time.Time
|
|
||||||
Now func() time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewLeakyBucket(size uint16, leakInterval time.Duration) *LeakyBucket {
|
|
||||||
bucket := LeakyBucket{
|
|
||||||
Size: size,
|
|
||||||
Fill: 0,
|
|
||||||
LeakInterval: leakInterval,
|
|
||||||
Now: time.Now,
|
|
||||||
Lastupdate: time.Now(),
|
|
||||||
}
|
|
||||||
|
|
||||||
return &bucket
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *LeakyBucket) updateFill() {
|
|
||||||
now := b.Now()
|
|
||||||
if b.Fill > 0 {
|
|
||||||
elapsed := now.Sub(b.Lastupdate)
|
|
||||||
|
|
||||||
b.Fill -= float64(elapsed) / float64(b.LeakInterval)
|
|
||||||
if b.Fill < 0 {
|
|
||||||
b.Fill = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
b.Lastupdate = now
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *LeakyBucket) Pour(amount uint16) bool {
|
|
||||||
b.updateFill()
|
|
||||||
|
|
||||||
var newfill float64 = b.Fill + float64(amount)
|
|
||||||
|
|
||||||
if newfill > float64(b.Size) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
b.Fill = newfill
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// The time at which this bucket will be completely drained
|
|
||||||
func (b *LeakyBucket) DrainedAt() time.Time {
|
|
||||||
return b.Lastupdate.Add(time.Duration(b.Fill * float64(b.LeakInterval)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// The duration until this bucket is completely drained
|
|
||||||
func (b *LeakyBucket) TimeToDrain() time.Duration {
|
|
||||||
return b.DrainedAt().Sub(b.Now())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *LeakyBucket) TimeSinceLastUpdate() time.Duration {
|
|
||||||
return b.Now().Sub(b.Lastupdate)
|
|
||||||
}
|
|
||||||
|
|
||||||
type LeakyBucketSer struct {
|
|
||||||
Size uint16
|
|
||||||
Fill float64
|
|
||||||
LeakInterval time.Duration // time.Duration for 1 unit of size to leak
|
|
||||||
Lastupdate time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *LeakyBucket) Serialise() *LeakyBucketSer {
|
|
||||||
bucket := LeakyBucketSer{
|
|
||||||
Size: b.Size,
|
|
||||||
Fill: b.Fill,
|
|
||||||
LeakInterval: b.LeakInterval,
|
|
||||||
Lastupdate: b.Lastupdate,
|
|
||||||
}
|
|
||||||
|
|
||||||
return &bucket
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *LeakyBucketSer) DeSerialise() *LeakyBucket {
|
|
||||||
bucket := LeakyBucket{
|
|
||||||
Size: b.Size,
|
|
||||||
Fill: b.Fill,
|
|
||||||
LeakInterval: b.LeakInterval,
|
|
||||||
Lastupdate: b.Lastupdate,
|
|
||||||
Now: time.Now,
|
|
||||||
}
|
|
||||||
|
|
||||||
return &bucket
|
|
||||||
}
|
|
60
vendor/github.com/hpcloud/tail/ratelimiter/memory.go
generated
vendored
60
vendor/github.com/hpcloud/tail/ratelimiter/memory.go
generated
vendored
|
@ -1,60 +0,0 @@
|
||||||
package ratelimiter
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
GC_SIZE int = 100
|
|
||||||
GC_PERIOD time.Duration = 60 * time.Second
|
|
||||||
)
|
|
||||||
|
|
||||||
type Memory struct {
|
|
||||||
store map[string]LeakyBucket
|
|
||||||
lastGCCollected time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewMemory() *Memory {
|
|
||||||
m := new(Memory)
|
|
||||||
m.store = make(map[string]LeakyBucket)
|
|
||||||
m.lastGCCollected = time.Now()
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Memory) GetBucketFor(key string) (*LeakyBucket, error) {
|
|
||||||
|
|
||||||
bucket, ok := m.store[key]
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("miss")
|
|
||||||
}
|
|
||||||
|
|
||||||
return &bucket, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Memory) SetBucketFor(key string, bucket LeakyBucket) error {
|
|
||||||
|
|
||||||
if len(m.store) > GC_SIZE {
|
|
||||||
m.GarbageCollect()
|
|
||||||
}
|
|
||||||
|
|
||||||
m.store[key] = bucket
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Memory) GarbageCollect() {
|
|
||||||
now := time.Now()
|
|
||||||
|
|
||||||
// rate limit GC to once per minute
|
|
||||||
if now.Unix() >= m.lastGCCollected.Add(GC_PERIOD).Unix() {
|
|
||||||
for key, bucket := range m.store {
|
|
||||||
// if the bucket is drained, then GC
|
|
||||||
if bucket.DrainedAt().Unix() < now.Unix() {
|
|
||||||
delete(m.store, key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m.lastGCCollected = now
|
|
||||||
}
|
|
||||||
}
|
|
6
vendor/github.com/hpcloud/tail/ratelimiter/storage.go
generated
vendored
6
vendor/github.com/hpcloud/tail/ratelimiter/storage.go
generated
vendored
|
@ -1,6 +0,0 @@
|
||||||
package ratelimiter
|
|
||||||
|
|
||||||
type Storage interface {
|
|
||||||
GetBucketFor(string) (*LeakyBucket, error)
|
|
||||||
SetBucketFor(string, LeakyBucket) error
|
|
||||||
}
|
|
437
vendor/github.com/hpcloud/tail/tail.go
generated
vendored
437
vendor/github.com/hpcloud/tail/tail.go
generated
vendored
|
@ -1,437 +0,0 @@
|
||||||
// Copyright (c) 2015 HPE Software Inc. All rights reserved.
|
|
||||||
// Copyright (c) 2013 ActiveState Software Inc. All rights reserved.
|
|
||||||
|
|
||||||
package tail
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/hpcloud/tail/ratelimiter"
|
|
||||||
"github.com/hpcloud/tail/util"
|
|
||||||
"github.com/hpcloud/tail/watch"
|
|
||||||
"gopkg.in/tomb.v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
ErrStop = errors.New("tail should now stop")
|
|
||||||
)
|
|
||||||
|
|
||||||
type Line struct {
|
|
||||||
Text string
|
|
||||||
Time time.Time
|
|
||||||
Err error // Error from tail
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewLine returns a Line with present time.
|
|
||||||
func NewLine(text string) *Line {
|
|
||||||
return &Line{text, time.Now(), nil}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SeekInfo represents arguments to `os.Seek`
|
|
||||||
type SeekInfo struct {
|
|
||||||
Offset int64
|
|
||||||
Whence int // os.SEEK_*
|
|
||||||
}
|
|
||||||
|
|
||||||
type logger interface {
|
|
||||||
Fatal(v ...interface{})
|
|
||||||
Fatalf(format string, v ...interface{})
|
|
||||||
Fatalln(v ...interface{})
|
|
||||||
Panic(v ...interface{})
|
|
||||||
Panicf(format string, v ...interface{})
|
|
||||||
Panicln(v ...interface{})
|
|
||||||
Print(v ...interface{})
|
|
||||||
Printf(format string, v ...interface{})
|
|
||||||
Println(v ...interface{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Config is used to specify how a file must be tailed.
|
|
||||||
type Config struct {
|
|
||||||
// File-specifc
|
|
||||||
Location *SeekInfo // Seek to this location before tailing
|
|
||||||
ReOpen bool // Reopen recreated files (tail -F)
|
|
||||||
MustExist bool // Fail early if the file does not exist
|
|
||||||
Poll bool // Poll for file changes instead of using inotify
|
|
||||||
Pipe bool // Is a named pipe (mkfifo)
|
|
||||||
RateLimiter *ratelimiter.LeakyBucket
|
|
||||||
|
|
||||||
// Generic IO
|
|
||||||
Follow bool // Continue looking for new lines (tail -f)
|
|
||||||
MaxLineSize int // If non-zero, split longer lines into multiple lines
|
|
||||||
|
|
||||||
// Logger, when nil, is set to tail.DefaultLogger
|
|
||||||
// To disable logging: set field to tail.DiscardingLogger
|
|
||||||
Logger logger
|
|
||||||
}
|
|
||||||
|
|
||||||
type Tail struct {
|
|
||||||
Filename string
|
|
||||||
Lines chan *Line
|
|
||||||
Config
|
|
||||||
|
|
||||||
file *os.File
|
|
||||||
reader *bufio.Reader
|
|
||||||
|
|
||||||
watcher watch.FileWatcher
|
|
||||||
changes *watch.FileChanges
|
|
||||||
|
|
||||||
tomb.Tomb // provides: Done, Kill, Dying
|
|
||||||
|
|
||||||
lk sync.Mutex
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
// DefaultLogger is used when Config.Logger == nil
|
|
||||||
DefaultLogger = log.New(os.Stderr, "", log.LstdFlags)
|
|
||||||
// DiscardingLogger can be used to disable logging output
|
|
||||||
DiscardingLogger = log.New(ioutil.Discard, "", 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
// TailFile begins tailing the file. Output stream is made available
|
|
||||||
// via the `Tail.Lines` channel. To handle errors during tailing,
|
|
||||||
// invoke the `Wait` or `Err` method after finishing reading from the
|
|
||||||
// `Lines` channel.
|
|
||||||
func TailFile(filename string, config Config) (*Tail, error) {
|
|
||||||
if config.ReOpen && !config.Follow {
|
|
||||||
util.Fatal("cannot set ReOpen without Follow.")
|
|
||||||
}
|
|
||||||
|
|
||||||
t := &Tail{
|
|
||||||
Filename: filename,
|
|
||||||
Lines: make(chan *Line),
|
|
||||||
Config: config,
|
|
||||||
}
|
|
||||||
|
|
||||||
// when Logger was not specified in config, use default logger
|
|
||||||
if t.Logger == nil {
|
|
||||||
t.Logger = log.New(os.Stderr, "", log.LstdFlags)
|
|
||||||
}
|
|
||||||
|
|
||||||
if t.Poll {
|
|
||||||
t.watcher = watch.NewPollingFileWatcher(filename)
|
|
||||||
} else {
|
|
||||||
t.watcher = watch.NewInotifyFileWatcher(filename)
|
|
||||||
}
|
|
||||||
|
|
||||||
if t.MustExist {
|
|
||||||
var err error
|
|
||||||
t.file, err = OpenFile(t.Filename)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
go t.tailFileSync()
|
|
||||||
|
|
||||||
return t, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the file's current position, like stdio's ftell().
|
|
||||||
// But this value is not very accurate.
|
|
||||||
// it may readed one line in the chan(tail.Lines),
|
|
||||||
// so it may lost one line.
|
|
||||||
func (tail *Tail) Tell() (offset int64, err error) {
|
|
||||||
if tail.file == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
offset, err = tail.file.Seek(0, os.SEEK_CUR)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tail.lk.Lock()
|
|
||||||
defer tail.lk.Unlock()
|
|
||||||
if tail.reader == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
offset -= int64(tail.reader.Buffered())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop stops the tailing activity.
|
|
||||||
func (tail *Tail) Stop() error {
|
|
||||||
tail.Kill(nil)
|
|
||||||
return tail.Wait()
|
|
||||||
}
|
|
||||||
|
|
||||||
// StopAtEOF stops tailing as soon as the end of the file is reached.
|
|
||||||
func (tail *Tail) StopAtEOF() error {
|
|
||||||
tail.Kill(errStopAtEOF)
|
|
||||||
return tail.Wait()
|
|
||||||
}
|
|
||||||
|
|
||||||
var errStopAtEOF = errors.New("tail: stop at eof")
|
|
||||||
|
|
||||||
func (tail *Tail) close() {
|
|
||||||
close(tail.Lines)
|
|
||||||
tail.closeFile()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tail *Tail) closeFile() {
|
|
||||||
if tail.file != nil {
|
|
||||||
tail.file.Close()
|
|
||||||
tail.file = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tail *Tail) reopen() error {
|
|
||||||
tail.closeFile()
|
|
||||||
for {
|
|
||||||
var err error
|
|
||||||
tail.file, err = OpenFile(tail.Filename)
|
|
||||||
if err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
tail.Logger.Printf("Waiting for %s to appear...", tail.Filename)
|
|
||||||
if err := tail.watcher.BlockUntilExists(&tail.Tomb); err != nil {
|
|
||||||
if err == tomb.ErrDying {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return fmt.Errorf("Failed to detect creation of %s: %s", tail.Filename, err)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
return fmt.Errorf("Unable to open file %s: %s", tail.Filename, err)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tail *Tail) readLine() (string, error) {
|
|
||||||
tail.lk.Lock()
|
|
||||||
line, err := tail.reader.ReadString('\n')
|
|
||||||
tail.lk.Unlock()
|
|
||||||
if err != nil {
|
|
||||||
// Note ReadString "returns the data read before the error" in
|
|
||||||
// case of an error, including EOF, so we return it as is. The
|
|
||||||
// caller is expected to process it if err is EOF.
|
|
||||||
return line, err
|
|
||||||
}
|
|
||||||
|
|
||||||
line = strings.TrimRight(line, "\n")
|
|
||||||
|
|
||||||
return line, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tail *Tail) tailFileSync() {
|
|
||||||
defer tail.Done()
|
|
||||||
defer tail.close()
|
|
||||||
|
|
||||||
if !tail.MustExist {
|
|
||||||
// deferred first open.
|
|
||||||
err := tail.reopen()
|
|
||||||
if err != nil {
|
|
||||||
if err != tomb.ErrDying {
|
|
||||||
tail.Kill(err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Seek to requested location on first open of the file.
|
|
||||||
if tail.Location != nil {
|
|
||||||
_, err := tail.file.Seek(tail.Location.Offset, tail.Location.Whence)
|
|
||||||
tail.Logger.Printf("Seeked %s - %+v\n", tail.Filename, tail.Location)
|
|
||||||
if err != nil {
|
|
||||||
tail.Killf("Seek error on %s: %s", tail.Filename, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tail.openReader()
|
|
||||||
|
|
||||||
var offset int64
|
|
||||||
var err error
|
|
||||||
|
|
||||||
// Read line by line.
|
|
||||||
for {
|
|
||||||
// do not seek in named pipes
|
|
||||||
if !tail.Pipe {
|
|
||||||
// grab the position in case we need to back up in the event of a half-line
|
|
||||||
offset, err = tail.Tell()
|
|
||||||
if err != nil {
|
|
||||||
tail.Kill(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
line, err := tail.readLine()
|
|
||||||
|
|
||||||
// Process `line` even if err is EOF.
|
|
||||||
if err == nil {
|
|
||||||
cooloff := !tail.sendLine(line)
|
|
||||||
if cooloff {
|
|
||||||
// Wait a second before seeking till the end of
|
|
||||||
// file when rate limit is reached.
|
|
||||||
msg := ("Too much log activity; waiting a second " +
|
|
||||||
"before resuming tailing")
|
|
||||||
tail.Lines <- &Line{msg, time.Now(), errors.New(msg)}
|
|
||||||
select {
|
|
||||||
case <-time.After(time.Second):
|
|
||||||
case <-tail.Dying():
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := tail.seekEnd(); err != nil {
|
|
||||||
tail.Kill(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if err == io.EOF {
|
|
||||||
if !tail.Follow {
|
|
||||||
if line != "" {
|
|
||||||
tail.sendLine(line)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if tail.Follow && line != "" {
|
|
||||||
// this has the potential to never return the last line if
|
|
||||||
// it's not followed by a newline; seems a fair trade here
|
|
||||||
err := tail.seekTo(SeekInfo{Offset: offset, Whence: 0})
|
|
||||||
if err != nil {
|
|
||||||
tail.Kill(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// When EOF is reached, wait for more data to become
|
|
||||||
// available. Wait strategy is based on the `tail.watcher`
|
|
||||||
// implementation (inotify or polling).
|
|
||||||
err := tail.waitForChanges()
|
|
||||||
if err != nil {
|
|
||||||
if err != ErrStop {
|
|
||||||
tail.Kill(err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// non-EOF error
|
|
||||||
tail.Killf("Error reading %s: %s", tail.Filename, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-tail.Dying():
|
|
||||||
if tail.Err() == errStopAtEOF {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// waitForChanges waits until the file has been appended, deleted,
|
|
||||||
// moved or truncated. When moved or deleted - the file will be
|
|
||||||
// reopened if ReOpen is true. Truncated files are always reopened.
|
|
||||||
func (tail *Tail) waitForChanges() error {
|
|
||||||
if tail.changes == nil {
|
|
||||||
pos, err := tail.file.Seek(0, os.SEEK_CUR)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
tail.changes, err = tail.watcher.ChangeEvents(&tail.Tomb, pos)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-tail.changes.Modified:
|
|
||||||
return nil
|
|
||||||
case <-tail.changes.Deleted:
|
|
||||||
tail.changes = nil
|
|
||||||
if tail.ReOpen {
|
|
||||||
// XXX: we must not log from a library.
|
|
||||||
tail.Logger.Printf("Re-opening moved/deleted file %s ...", tail.Filename)
|
|
||||||
if err := tail.reopen(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
tail.Logger.Printf("Successfully reopened %s", tail.Filename)
|
|
||||||
tail.openReader()
|
|
||||||
return nil
|
|
||||||
} else {
|
|
||||||
tail.Logger.Printf("Stopping tail as file no longer exists: %s", tail.Filename)
|
|
||||||
return ErrStop
|
|
||||||
}
|
|
||||||
case <-tail.changes.Truncated:
|
|
||||||
// Always reopen truncated files (Follow is true)
|
|
||||||
tail.Logger.Printf("Re-opening truncated file %s ...", tail.Filename)
|
|
||||||
if err := tail.reopen(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
tail.Logger.Printf("Successfully reopened truncated %s", tail.Filename)
|
|
||||||
tail.openReader()
|
|
||||||
return nil
|
|
||||||
case <-tail.Dying():
|
|
||||||
return ErrStop
|
|
||||||
}
|
|
||||||
panic("unreachable")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tail *Tail) openReader() {
|
|
||||||
if tail.MaxLineSize > 0 {
|
|
||||||
// add 2 to account for newline characters
|
|
||||||
tail.reader = bufio.NewReaderSize(tail.file, tail.MaxLineSize+2)
|
|
||||||
} else {
|
|
||||||
tail.reader = bufio.NewReader(tail.file)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tail *Tail) seekEnd() error {
|
|
||||||
return tail.seekTo(SeekInfo{Offset: 0, Whence: os.SEEK_END})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tail *Tail) seekTo(pos SeekInfo) error {
|
|
||||||
_, err := tail.file.Seek(pos.Offset, pos.Whence)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Seek error on %s: %s", tail.Filename, err)
|
|
||||||
}
|
|
||||||
// Reset the read buffer whenever the file is re-seek'ed
|
|
||||||
tail.reader.Reset(tail.file)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// sendLine sends the line(s) to Lines channel, splitting longer lines
|
|
||||||
// if necessary. Return false if rate limit is reached.
|
|
||||||
func (tail *Tail) sendLine(line string) bool {
|
|
||||||
now := time.Now()
|
|
||||||
lines := []string{line}
|
|
||||||
|
|
||||||
// Split longer lines
|
|
||||||
if tail.MaxLineSize > 0 && len(line) > tail.MaxLineSize {
|
|
||||||
lines = util.PartitionString(line, tail.MaxLineSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, line := range lines {
|
|
||||||
tail.Lines <- &Line{line, now, nil}
|
|
||||||
}
|
|
||||||
|
|
||||||
if tail.Config.RateLimiter != nil {
|
|
||||||
ok := tail.Config.RateLimiter.Pour(uint16(len(lines)))
|
|
||||||
if !ok {
|
|
||||||
tail.Logger.Printf("Leaky bucket full (%v); entering 1s cooloff period.\n",
|
|
||||||
tail.Filename)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cleanup removes inotify watches added by the tail package. This function is
|
|
||||||
// meant to be invoked from a process's exit handler. Linux kernel may not
|
|
||||||
// automatically remove inotify watches after the process exits.
|
|
||||||
func (tail *Tail) Cleanup() {
|
|
||||||
watch.Cleanup(tail.Filename)
|
|
||||||
}
|
|
11
vendor/github.com/hpcloud/tail/tail_posix.go
generated
vendored
11
vendor/github.com/hpcloud/tail/tail_posix.go
generated
vendored
|
@ -1,11 +0,0 @@
|
||||||
// +build linux darwin freebsd netbsd openbsd
|
|
||||||
|
|
||||||
package tail
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
func OpenFile(name string) (file *os.File, err error) {
|
|
||||||
return os.Open(name)
|
|
||||||
}
|
|
12
vendor/github.com/hpcloud/tail/tail_windows.go
generated
vendored
12
vendor/github.com/hpcloud/tail/tail_windows.go
generated
vendored
|
@ -1,12 +0,0 @@
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package tail
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/hpcloud/tail/winfile"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
func OpenFile(name string) (file *os.File, err error) {
|
|
||||||
return winfile.OpenFile(name, os.O_RDONLY, 0)
|
|
||||||
}
|
|
48
vendor/github.com/hpcloud/tail/util/util.go
generated
vendored
48
vendor/github.com/hpcloud/tail/util/util.go
generated
vendored
|
@ -1,48 +0,0 @@
|
||||||
// Copyright (c) 2015 HPE Software Inc. All rights reserved.
|
|
||||||
// Copyright (c) 2013 ActiveState Software Inc. All rights reserved.
|
|
||||||
|
|
||||||
package util
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"runtime/debug"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Logger struct {
|
|
||||||
*log.Logger
|
|
||||||
}
|
|
||||||
|
|
||||||
var LOGGER = &Logger{log.New(os.Stderr, "", log.LstdFlags)}
|
|
||||||
|
|
||||||
// fatal is like panic except it displays only the current goroutine's stack.
|
|
||||||
func Fatal(format string, v ...interface{}) {
|
|
||||||
// https://github.com/hpcloud/log/blob/master/log.go#L45
|
|
||||||
LOGGER.Output(2, fmt.Sprintf("FATAL -- "+format, v...)+"\n"+string(debug.Stack()))
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// partitionString partitions the string into chunks of given size,
|
|
||||||
// with the last chunk of variable size.
|
|
||||||
func PartitionString(s string, chunkSize int) []string {
|
|
||||||
if chunkSize <= 0 {
|
|
||||||
panic("invalid chunkSize")
|
|
||||||
}
|
|
||||||
length := len(s)
|
|
||||||
chunks := 1 + length/chunkSize
|
|
||||||
start := 0
|
|
||||||
end := chunkSize
|
|
||||||
parts := make([]string, 0, chunks)
|
|
||||||
for {
|
|
||||||
if end > length {
|
|
||||||
end = length
|
|
||||||
}
|
|
||||||
parts = append(parts, s[start:end])
|
|
||||||
if end == length {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
start, end = end, end+chunkSize
|
|
||||||
}
|
|
||||||
return parts
|
|
||||||
}
|
|
36
vendor/github.com/hpcloud/tail/watch/filechanges.go
generated
vendored
36
vendor/github.com/hpcloud/tail/watch/filechanges.go
generated
vendored
|
@ -1,36 +0,0 @@
|
||||||
package watch
|
|
||||||
|
|
||||||
type FileChanges struct {
|
|
||||||
Modified chan bool // Channel to get notified of modifications
|
|
||||||
Truncated chan bool // Channel to get notified of truncations
|
|
||||||
Deleted chan bool // Channel to get notified of deletions/renames
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewFileChanges() *FileChanges {
|
|
||||||
return &FileChanges{
|
|
||||||
make(chan bool, 1), make(chan bool, 1), make(chan bool, 1)}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fc *FileChanges) NotifyModified() {
|
|
||||||
sendOnlyIfEmpty(fc.Modified)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fc *FileChanges) NotifyTruncated() {
|
|
||||||
sendOnlyIfEmpty(fc.Truncated)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fc *FileChanges) NotifyDeleted() {
|
|
||||||
sendOnlyIfEmpty(fc.Deleted)
|
|
||||||
}
|
|
||||||
|
|
||||||
// sendOnlyIfEmpty sends on a bool channel only if the channel has no
|
|
||||||
// backlog to be read by other goroutines. This concurrency pattern
|
|
||||||
// can be used to notify other goroutines if and only if they are
|
|
||||||
// looking for it (i.e., subsequent notifications can be compressed
|
|
||||||
// into one).
|
|
||||||
func sendOnlyIfEmpty(ch chan bool) {
|
|
||||||
select {
|
|
||||||
case ch <- true:
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
135
vendor/github.com/hpcloud/tail/watch/inotify.go
generated
vendored
135
vendor/github.com/hpcloud/tail/watch/inotify.go
generated
vendored
|
@ -1,135 +0,0 @@
|
||||||
// Copyright (c) 2015 HPE Software Inc. All rights reserved.
|
|
||||||
// Copyright (c) 2013 ActiveState Software Inc. All rights reserved.
|
|
||||||
|
|
||||||
package watch
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/hpcloud/tail/util"
|
|
||||||
|
|
||||||
"gopkg.in/fsnotify/fsnotify.v1"
|
|
||||||
"gopkg.in/tomb.v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
// InotifyFileWatcher uses inotify to monitor file changes.
|
|
||||||
type InotifyFileWatcher struct {
|
|
||||||
Filename string
|
|
||||||
Size int64
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewInotifyFileWatcher(filename string) *InotifyFileWatcher {
|
|
||||||
fw := &InotifyFileWatcher{filepath.Clean(filename), 0}
|
|
||||||
return fw
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fw *InotifyFileWatcher) BlockUntilExists(t *tomb.Tomb) error {
|
|
||||||
err := WatchCreate(fw.Filename)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer RemoveWatchCreate(fw.Filename)
|
|
||||||
|
|
||||||
// Do a real check now as the file might have been created before
|
|
||||||
// calling `WatchFlags` above.
|
|
||||||
if _, err = os.Stat(fw.Filename); !os.IsNotExist(err) {
|
|
||||||
// file exists, or stat returned an error.
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
events := Events(fw.Filename)
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case evt, ok := <-events:
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("inotify watcher has been closed")
|
|
||||||
}
|
|
||||||
evtName, err := filepath.Abs(evt.Name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fwFilename, err := filepath.Abs(fw.Filename)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if evtName == fwFilename {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
case <-t.Dying():
|
|
||||||
return tomb.ErrDying
|
|
||||||
}
|
|
||||||
}
|
|
||||||
panic("unreachable")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fw *InotifyFileWatcher) ChangeEvents(t *tomb.Tomb, pos int64) (*FileChanges, error) {
|
|
||||||
err := Watch(fw.Filename)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
changes := NewFileChanges()
|
|
||||||
fw.Size = pos
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
|
|
||||||
events := Events(fw.Filename)
|
|
||||||
|
|
||||||
for {
|
|
||||||
prevSize := fw.Size
|
|
||||||
|
|
||||||
var evt fsnotify.Event
|
|
||||||
var ok bool
|
|
||||||
|
|
||||||
select {
|
|
||||||
case evt, ok = <-events:
|
|
||||||
if !ok {
|
|
||||||
RemoveWatch(fw.Filename)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case <-t.Dying():
|
|
||||||
RemoveWatch(fw.Filename)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case evt.Op&fsnotify.Remove == fsnotify.Remove:
|
|
||||||
fallthrough
|
|
||||||
|
|
||||||
case evt.Op&fsnotify.Rename == fsnotify.Rename:
|
|
||||||
RemoveWatch(fw.Filename)
|
|
||||||
changes.NotifyDeleted()
|
|
||||||
return
|
|
||||||
|
|
||||||
//With an open fd, unlink(fd) - inotify returns IN_ATTRIB (==fsnotify.Chmod)
|
|
||||||
case evt.Op&fsnotify.Chmod == fsnotify.Chmod:
|
|
||||||
fallthrough
|
|
||||||
|
|
||||||
case evt.Op&fsnotify.Write == fsnotify.Write:
|
|
||||||
fi, err := os.Stat(fw.Filename)
|
|
||||||
if err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
RemoveWatch(fw.Filename)
|
|
||||||
changes.NotifyDeleted()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// XXX: report this error back to the user
|
|
||||||
util.Fatal("Failed to stat file %v: %v", fw.Filename, err)
|
|
||||||
}
|
|
||||||
fw.Size = fi.Size()
|
|
||||||
|
|
||||||
if prevSize > 0 && prevSize > fw.Size {
|
|
||||||
changes.NotifyTruncated()
|
|
||||||
} else {
|
|
||||||
changes.NotifyModified()
|
|
||||||
}
|
|
||||||
prevSize = fw.Size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
return changes, nil
|
|
||||||
}
|
|
248
vendor/github.com/hpcloud/tail/watch/inotify_tracker.go
generated
vendored
248
vendor/github.com/hpcloud/tail/watch/inotify_tracker.go
generated
vendored
|
@ -1,248 +0,0 @@
|
||||||
// Copyright (c) 2015 HPE Software Inc. All rights reserved.
|
|
||||||
// Copyright (c) 2013 ActiveState Software Inc. All rights reserved.
|
|
||||||
|
|
||||||
package watch
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"sync"
|
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/hpcloud/tail/util"
|
|
||||||
|
|
||||||
"gopkg.in/fsnotify/fsnotify.v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
type InotifyTracker struct {
|
|
||||||
mux sync.Mutex
|
|
||||||
watcher *fsnotify.Watcher
|
|
||||||
chans map[string]chan fsnotify.Event
|
|
||||||
done map[string]chan bool
|
|
||||||
watchNums map[string]int
|
|
||||||
watch chan *watchInfo
|
|
||||||
remove chan *watchInfo
|
|
||||||
error chan error
|
|
||||||
}
|
|
||||||
|
|
||||||
type watchInfo struct {
|
|
||||||
op fsnotify.Op
|
|
||||||
fname string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *watchInfo) isCreate() bool {
|
|
||||||
return this.op == fsnotify.Create
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
// globally shared InotifyTracker; ensures only one fsnotify.Watcher is used
|
|
||||||
shared *InotifyTracker
|
|
||||||
|
|
||||||
// these are used to ensure the shared InotifyTracker is run exactly once
|
|
||||||
once = sync.Once{}
|
|
||||||
goRun = func() {
|
|
||||||
shared = &InotifyTracker{
|
|
||||||
mux: sync.Mutex{},
|
|
||||||
chans: make(map[string]chan fsnotify.Event),
|
|
||||||
done: make(map[string]chan bool),
|
|
||||||
watchNums: make(map[string]int),
|
|
||||||
watch: make(chan *watchInfo),
|
|
||||||
remove: make(chan *watchInfo),
|
|
||||||
error: make(chan error),
|
|
||||||
}
|
|
||||||
go shared.run()
|
|
||||||
}
|
|
||||||
|
|
||||||
logger = log.New(os.Stderr, "", log.LstdFlags)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Watch signals the run goroutine to begin watching the input filename
|
|
||||||
func Watch(fname string) error {
|
|
||||||
return watch(&watchInfo{
|
|
||||||
fname: fname,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Watch create signals the run goroutine to begin watching the input filename
|
|
||||||
// if call the WatchCreate function, don't call the Cleanup, call the RemoveWatchCreate
|
|
||||||
func WatchCreate(fname string) error {
|
|
||||||
return watch(&watchInfo{
|
|
||||||
op: fsnotify.Create,
|
|
||||||
fname: fname,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func watch(winfo *watchInfo) error {
|
|
||||||
// start running the shared InotifyTracker if not already running
|
|
||||||
once.Do(goRun)
|
|
||||||
|
|
||||||
winfo.fname = filepath.Clean(winfo.fname)
|
|
||||||
shared.watch <- winfo
|
|
||||||
return <-shared.error
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveWatch signals the run goroutine to remove the watch for the input filename
|
|
||||||
func RemoveWatch(fname string) error {
|
|
||||||
return remove(&watchInfo{
|
|
||||||
fname: fname,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveWatch create signals the run goroutine to remove the watch for the input filename
|
|
||||||
func RemoveWatchCreate(fname string) error {
|
|
||||||
return remove(&watchInfo{
|
|
||||||
op: fsnotify.Create,
|
|
||||||
fname: fname,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func remove(winfo *watchInfo) error {
|
|
||||||
// start running the shared InotifyTracker if not already running
|
|
||||||
once.Do(goRun)
|
|
||||||
|
|
||||||
winfo.fname = filepath.Clean(winfo.fname)
|
|
||||||
shared.mux.Lock()
|
|
||||||
done := shared.done[winfo.fname]
|
|
||||||
if done != nil {
|
|
||||||
delete(shared.done, winfo.fname)
|
|
||||||
close(done)
|
|
||||||
}
|
|
||||||
shared.mux.Unlock()
|
|
||||||
|
|
||||||
shared.remove <- winfo
|
|
||||||
return <-shared.error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Events returns a channel to which FileEvents corresponding to the input filename
|
|
||||||
// will be sent. This channel will be closed when removeWatch is called on this
|
|
||||||
// filename.
|
|
||||||
func Events(fname string) <-chan fsnotify.Event {
|
|
||||||
shared.mux.Lock()
|
|
||||||
defer shared.mux.Unlock()
|
|
||||||
|
|
||||||
return shared.chans[fname]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cleanup removes the watch for the input filename if necessary.
|
|
||||||
func Cleanup(fname string) error {
|
|
||||||
return RemoveWatch(fname)
|
|
||||||
}
|
|
||||||
|
|
||||||
// watchFlags calls fsnotify.WatchFlags for the input filename and flags, creating
|
|
||||||
// a new Watcher if the previous Watcher was closed.
|
|
||||||
func (shared *InotifyTracker) addWatch(winfo *watchInfo) error {
|
|
||||||
shared.mux.Lock()
|
|
||||||
defer shared.mux.Unlock()
|
|
||||||
|
|
||||||
if shared.chans[winfo.fname] == nil {
|
|
||||||
shared.chans[winfo.fname] = make(chan fsnotify.Event)
|
|
||||||
}
|
|
||||||
if shared.done[winfo.fname] == nil {
|
|
||||||
shared.done[winfo.fname] = make(chan bool)
|
|
||||||
}
|
|
||||||
|
|
||||||
fname := winfo.fname
|
|
||||||
if winfo.isCreate() {
|
|
||||||
// Watch for new files to be created in the parent directory.
|
|
||||||
fname = filepath.Dir(fname)
|
|
||||||
}
|
|
||||||
|
|
||||||
var err error
|
|
||||||
// already in inotify watch
|
|
||||||
if shared.watchNums[fname] == 0 {
|
|
||||||
err = shared.watcher.Add(fname)
|
|
||||||
}
|
|
||||||
if err == nil {
|
|
||||||
shared.watchNums[fname]++
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// removeWatch calls fsnotify.RemoveWatch for the input filename and closes the
|
|
||||||
// corresponding events channel.
|
|
||||||
func (shared *InotifyTracker) removeWatch(winfo *watchInfo) error {
|
|
||||||
shared.mux.Lock()
|
|
||||||
|
|
||||||
ch := shared.chans[winfo.fname]
|
|
||||||
if ch != nil {
|
|
||||||
delete(shared.chans, winfo.fname)
|
|
||||||
close(ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
fname := winfo.fname
|
|
||||||
if winfo.isCreate() {
|
|
||||||
// Watch for new files to be created in the parent directory.
|
|
||||||
fname = filepath.Dir(fname)
|
|
||||||
}
|
|
||||||
shared.watchNums[fname]--
|
|
||||||
watchNum := shared.watchNums[fname]
|
|
||||||
if watchNum == 0 {
|
|
||||||
delete(shared.watchNums, fname)
|
|
||||||
}
|
|
||||||
shared.mux.Unlock()
|
|
||||||
|
|
||||||
var err error
|
|
||||||
// If we were the last ones to watch this file, unsubscribe from inotify.
|
|
||||||
// This needs to happen after releasing the lock because fsnotify waits
|
|
||||||
// synchronously for the kernel to acknowledge the removal of the watch
|
|
||||||
// for this file, which causes us to deadlock if we still held the lock.
|
|
||||||
if watchNum == 0 {
|
|
||||||
err = shared.watcher.Remove(fname)
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// sendEvent sends the input event to the appropriate Tail.
|
|
||||||
func (shared *InotifyTracker) sendEvent(event fsnotify.Event) {
|
|
||||||
name := filepath.Clean(event.Name)
|
|
||||||
|
|
||||||
shared.mux.Lock()
|
|
||||||
ch := shared.chans[name]
|
|
||||||
done := shared.done[name]
|
|
||||||
shared.mux.Unlock()
|
|
||||||
|
|
||||||
if ch != nil && done != nil {
|
|
||||||
select {
|
|
||||||
case ch <- event:
|
|
||||||
case <-done:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// run starts the goroutine in which the shared struct reads events from its
|
|
||||||
// Watcher's Event channel and sends the events to the appropriate Tail.
|
|
||||||
func (shared *InotifyTracker) run() {
|
|
||||||
watcher, err := fsnotify.NewWatcher()
|
|
||||||
if err != nil {
|
|
||||||
util.Fatal("failed to create Watcher")
|
|
||||||
}
|
|
||||||
shared.watcher = watcher
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case winfo := <-shared.watch:
|
|
||||||
shared.error <- shared.addWatch(winfo)
|
|
||||||
|
|
||||||
case winfo := <-shared.remove:
|
|
||||||
shared.error <- shared.removeWatch(winfo)
|
|
||||||
|
|
||||||
case event, open := <-shared.watcher.Events:
|
|
||||||
if !open {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
shared.sendEvent(event)
|
|
||||||
|
|
||||||
case err, open := <-shared.watcher.Errors:
|
|
||||||
if !open {
|
|
||||||
return
|
|
||||||
} else if err != nil {
|
|
||||||
sysErr, ok := err.(*os.SyscallError)
|
|
||||||
if !ok || sysErr.Err != syscall.EINTR {
|
|
||||||
logger.Printf("Error in Watcher Error channel: %s", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
118
vendor/github.com/hpcloud/tail/watch/polling.go
generated
vendored
118
vendor/github.com/hpcloud/tail/watch/polling.go
generated
vendored
|
@ -1,118 +0,0 @@
|
||||||
// Copyright (c) 2015 HPE Software Inc. All rights reserved.
|
|
||||||
// Copyright (c) 2013 ActiveState Software Inc. All rights reserved.
|
|
||||||
|
|
||||||
package watch
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"runtime"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/hpcloud/tail/util"
|
|
||||||
"gopkg.in/tomb.v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PollingFileWatcher polls the file for changes.
|
|
||||||
type PollingFileWatcher struct {
|
|
||||||
Filename string
|
|
||||||
Size int64
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewPollingFileWatcher(filename string) *PollingFileWatcher {
|
|
||||||
fw := &PollingFileWatcher{filename, 0}
|
|
||||||
return fw
|
|
||||||
}
|
|
||||||
|
|
||||||
var POLL_DURATION time.Duration
|
|
||||||
|
|
||||||
func (fw *PollingFileWatcher) BlockUntilExists(t *tomb.Tomb) error {
|
|
||||||
for {
|
|
||||||
if _, err := os.Stat(fw.Filename); err == nil {
|
|
||||||
return nil
|
|
||||||
} else if !os.IsNotExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
select {
|
|
||||||
case <-time.After(POLL_DURATION):
|
|
||||||
continue
|
|
||||||
case <-t.Dying():
|
|
||||||
return tomb.ErrDying
|
|
||||||
}
|
|
||||||
}
|
|
||||||
panic("unreachable")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fw *PollingFileWatcher) ChangeEvents(t *tomb.Tomb, pos int64) (*FileChanges, error) {
|
|
||||||
origFi, err := os.Stat(fw.Filename)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
changes := NewFileChanges()
|
|
||||||
var prevModTime time.Time
|
|
||||||
|
|
||||||
// XXX: use tomb.Tomb to cleanly manage these goroutines. replace
|
|
||||||
// the fatal (below) with tomb's Kill.
|
|
||||||
|
|
||||||
fw.Size = pos
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
prevSize := fw.Size
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-t.Dying():
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(POLL_DURATION)
|
|
||||||
fi, err := os.Stat(fw.Filename)
|
|
||||||
if err != nil {
|
|
||||||
// Windows cannot delete a file if a handle is still open (tail keeps one open)
|
|
||||||
// so it gives access denied to anything trying to read it until all handles are released.
|
|
||||||
if os.IsNotExist(err) || (runtime.GOOS == "windows" && os.IsPermission(err)) {
|
|
||||||
// File does not exist (has been deleted).
|
|
||||||
changes.NotifyDeleted()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX: report this error back to the user
|
|
||||||
util.Fatal("Failed to stat file %v: %v", fw.Filename, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// File got moved/renamed?
|
|
||||||
if !os.SameFile(origFi, fi) {
|
|
||||||
changes.NotifyDeleted()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// File got truncated?
|
|
||||||
fw.Size = fi.Size()
|
|
||||||
if prevSize > 0 && prevSize > fw.Size {
|
|
||||||
changes.NotifyTruncated()
|
|
||||||
prevSize = fw.Size
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// File got bigger?
|
|
||||||
if prevSize > 0 && prevSize < fw.Size {
|
|
||||||
changes.NotifyModified()
|
|
||||||
prevSize = fw.Size
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
prevSize = fw.Size
|
|
||||||
|
|
||||||
// File was appended to (changed)?
|
|
||||||
modTime := fi.ModTime()
|
|
||||||
if modTime != prevModTime {
|
|
||||||
prevModTime = modTime
|
|
||||||
changes.NotifyModified()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
return changes, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
POLL_DURATION = 250 * time.Millisecond
|
|
||||||
}
|
|
20
vendor/github.com/hpcloud/tail/watch/watch.go
generated
vendored
20
vendor/github.com/hpcloud/tail/watch/watch.go
generated
vendored
|
@ -1,20 +0,0 @@
|
||||||
// Copyright (c) 2015 HPE Software Inc. All rights reserved.
|
|
||||||
// Copyright (c) 2013 ActiveState Software Inc. All rights reserved.
|
|
||||||
|
|
||||||
package watch
|
|
||||||
|
|
||||||
import "gopkg.in/tomb.v1"
|
|
||||||
|
|
||||||
// FileWatcher monitors file-level events.
|
|
||||||
type FileWatcher interface {
|
|
||||||
// BlockUntilExists blocks until the file comes into existence.
|
|
||||||
BlockUntilExists(*tomb.Tomb) error
|
|
||||||
|
|
||||||
// ChangeEvents reports on changes to a file, be it modification,
|
|
||||||
// deletion, renames or truncations. Returned FileChanges group of
|
|
||||||
// channels will be closed, thus become unusable, after a deletion
|
|
||||||
// or truncation event.
|
|
||||||
// In order to properly report truncations, ChangeEvents requires
|
|
||||||
// the caller to pass their current offset in the file.
|
|
||||||
ChangeEvents(*tomb.Tomb, int64) (*FileChanges, error)
|
|
||||||
}
|
|
92
vendor/github.com/hpcloud/tail/winfile/winfile.go
generated
vendored
92
vendor/github.com/hpcloud/tail/winfile/winfile.go
generated
vendored
|
@ -1,92 +0,0 @@
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package winfile
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// issue also described here
|
|
||||||
//https://codereview.appspot.com/8203043/
|
|
||||||
|
|
||||||
// https://github.com/jnwhiteh/golang/blob/master/src/pkg/syscall/syscall_windows.go#L218
|
|
||||||
func Open(path string, mode int, perm uint32) (fd syscall.Handle, err error) {
|
|
||||||
if len(path) == 0 {
|
|
||||||
return syscall.InvalidHandle, syscall.ERROR_FILE_NOT_FOUND
|
|
||||||
}
|
|
||||||
pathp, err := syscall.UTF16PtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return syscall.InvalidHandle, err
|
|
||||||
}
|
|
||||||
var access uint32
|
|
||||||
switch mode & (syscall.O_RDONLY | syscall.O_WRONLY | syscall.O_RDWR) {
|
|
||||||
case syscall.O_RDONLY:
|
|
||||||
access = syscall.GENERIC_READ
|
|
||||||
case syscall.O_WRONLY:
|
|
||||||
access = syscall.GENERIC_WRITE
|
|
||||||
case syscall.O_RDWR:
|
|
||||||
access = syscall.GENERIC_READ | syscall.GENERIC_WRITE
|
|
||||||
}
|
|
||||||
if mode&syscall.O_CREAT != 0 {
|
|
||||||
access |= syscall.GENERIC_WRITE
|
|
||||||
}
|
|
||||||
if mode&syscall.O_APPEND != 0 {
|
|
||||||
access &^= syscall.GENERIC_WRITE
|
|
||||||
access |= syscall.FILE_APPEND_DATA
|
|
||||||
}
|
|
||||||
sharemode := uint32(syscall.FILE_SHARE_READ | syscall.FILE_SHARE_WRITE | syscall.FILE_SHARE_DELETE)
|
|
||||||
var sa *syscall.SecurityAttributes
|
|
||||||
if mode&syscall.O_CLOEXEC == 0 {
|
|
||||||
sa = makeInheritSa()
|
|
||||||
}
|
|
||||||
var createmode uint32
|
|
||||||
switch {
|
|
||||||
case mode&(syscall.O_CREAT|syscall.O_EXCL) == (syscall.O_CREAT | syscall.O_EXCL):
|
|
||||||
createmode = syscall.CREATE_NEW
|
|
||||||
case mode&(syscall.O_CREAT|syscall.O_TRUNC) == (syscall.O_CREAT | syscall.O_TRUNC):
|
|
||||||
createmode = syscall.CREATE_ALWAYS
|
|
||||||
case mode&syscall.O_CREAT == syscall.O_CREAT:
|
|
||||||
createmode = syscall.OPEN_ALWAYS
|
|
||||||
case mode&syscall.O_TRUNC == syscall.O_TRUNC:
|
|
||||||
createmode = syscall.TRUNCATE_EXISTING
|
|
||||||
default:
|
|
||||||
createmode = syscall.OPEN_EXISTING
|
|
||||||
}
|
|
||||||
h, e := syscall.CreateFile(pathp, access, sharemode, sa, createmode, syscall.FILE_ATTRIBUTE_NORMAL, 0)
|
|
||||||
return h, e
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://github.com/jnwhiteh/golang/blob/master/src/pkg/syscall/syscall_windows.go#L211
|
|
||||||
func makeInheritSa() *syscall.SecurityAttributes {
|
|
||||||
var sa syscall.SecurityAttributes
|
|
||||||
sa.Length = uint32(unsafe.Sizeof(sa))
|
|
||||||
sa.InheritHandle = 1
|
|
||||||
return &sa
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://github.com/jnwhiteh/golang/blob/master/src/pkg/os/file_windows.go#L133
|
|
||||||
func OpenFile(name string, flag int, perm os.FileMode) (file *os.File, err error) {
|
|
||||||
r, e := Open(name, flag|syscall.O_CLOEXEC, syscallMode(perm))
|
|
||||||
if e != nil {
|
|
||||||
return nil, e
|
|
||||||
}
|
|
||||||
return os.NewFile(uintptr(r), name), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://github.com/jnwhiteh/golang/blob/master/src/pkg/os/file_posix.go#L61
|
|
||||||
func syscallMode(i os.FileMode) (o uint32) {
|
|
||||||
o |= uint32(i.Perm())
|
|
||||||
if i&os.ModeSetuid != 0 {
|
|
||||||
o |= syscall.S_ISUID
|
|
||||||
}
|
|
||||||
if i&os.ModeSetgid != 0 {
|
|
||||||
o |= syscall.S_ISGID
|
|
||||||
}
|
|
||||||
if i&os.ModeSticky != 0 {
|
|
||||||
o |= syscall.S_ISVTX
|
|
||||||
}
|
|
||||||
// No mapping for Go's ModeTemporary (plan9 only).
|
|
||||||
return
|
|
||||||
}
|
|
9
vendor/github.com/konsorten/go-windows-terminal-sequences/LICENSE
generated
vendored
9
vendor/github.com/konsorten/go-windows-terminal-sequences/LICENSE
generated
vendored
|
@ -1,9 +0,0 @@
|
||||||
(The MIT License)
|
|
||||||
|
|
||||||
Copyright (c) 2017 marvin + konsorten GmbH (open-source@konsorten.de)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
36
vendor/github.com/konsorten/go-windows-terminal-sequences/sequences.go
generated
vendored
36
vendor/github.com/konsorten/go-windows-terminal-sequences/sequences.go
generated
vendored
|
@ -1,36 +0,0 @@
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package sequences
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
kernel32Dll *syscall.LazyDLL = syscall.NewLazyDLL("Kernel32.dll")
|
|
||||||
setConsoleMode *syscall.LazyProc = kernel32Dll.NewProc("SetConsoleMode")
|
|
||||||
)
|
|
||||||
|
|
||||||
func EnableVirtualTerminalProcessing(stream syscall.Handle, enable bool) error {
|
|
||||||
const ENABLE_VIRTUAL_TERMINAL_PROCESSING uint32 = 0x4
|
|
||||||
|
|
||||||
var mode uint32
|
|
||||||
err := syscall.GetConsoleMode(syscall.Stdout, &mode)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if enable {
|
|
||||||
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING
|
|
||||||
} else {
|
|
||||||
mode &^= ENABLE_VIRTUAL_TERMINAL_PROCESSING
|
|
||||||
}
|
|
||||||
|
|
||||||
ret, _, err := setConsoleMode.Call(uintptr(unsafe.Pointer(stream)), uintptr(mode))
|
|
||||||
if ret == 0 {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
21
vendor/github.com/mitchellh/go-homedir/LICENSE
generated
vendored
21
vendor/github.com/mitchellh/go-homedir/LICENSE
generated
vendored
|
@ -1,21 +0,0 @@
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2013 Mitchell Hashimoto
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
157
vendor/github.com/mitchellh/go-homedir/homedir.go
generated
vendored
157
vendor/github.com/mitchellh/go-homedir/homedir.go
generated
vendored
|
@ -1,157 +0,0 @@
|
||||||
package homedir
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"errors"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
|
||||||
"runtime"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DisableCache will disable caching of the home directory. Caching is enabled
|
|
||||||
// by default.
|
|
||||||
var DisableCache bool
|
|
||||||
|
|
||||||
var homedirCache string
|
|
||||||
var cacheLock sync.RWMutex
|
|
||||||
|
|
||||||
// Dir returns the home directory for the executing user.
|
|
||||||
//
|
|
||||||
// This uses an OS-specific method for discovering the home directory.
|
|
||||||
// An error is returned if a home directory cannot be detected.
|
|
||||||
func Dir() (string, error) {
|
|
||||||
if !DisableCache {
|
|
||||||
cacheLock.RLock()
|
|
||||||
cached := homedirCache
|
|
||||||
cacheLock.RUnlock()
|
|
||||||
if cached != "" {
|
|
||||||
return cached, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cacheLock.Lock()
|
|
||||||
defer cacheLock.Unlock()
|
|
||||||
|
|
||||||
var result string
|
|
||||||
var err error
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
result, err = dirWindows()
|
|
||||||
} else {
|
|
||||||
// Unix-like system, so just assume Unix
|
|
||||||
result, err = dirUnix()
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
homedirCache = result
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Expand expands the path to include the home directory if the path
|
|
||||||
// is prefixed with `~`. If it isn't prefixed with `~`, the path is
|
|
||||||
// returned as-is.
|
|
||||||
func Expand(path string) (string, error) {
|
|
||||||
if len(path) == 0 {
|
|
||||||
return path, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if path[0] != '~' {
|
|
||||||
return path, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(path) > 1 && path[1] != '/' && path[1] != '\\' {
|
|
||||||
return "", errors.New("cannot expand user-specific home dir")
|
|
||||||
}
|
|
||||||
|
|
||||||
dir, err := Dir()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return filepath.Join(dir, path[1:]), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func dirUnix() (string, error) {
|
|
||||||
homeEnv := "HOME"
|
|
||||||
if runtime.GOOS == "plan9" {
|
|
||||||
// On plan9, env vars are lowercase.
|
|
||||||
homeEnv = "home"
|
|
||||||
}
|
|
||||||
|
|
||||||
// First prefer the HOME environmental variable
|
|
||||||
if home := os.Getenv(homeEnv); home != "" {
|
|
||||||
return home, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var stdout bytes.Buffer
|
|
||||||
|
|
||||||
// If that fails, try OS specific commands
|
|
||||||
if runtime.GOOS == "darwin" {
|
|
||||||
cmd := exec.Command("sh", "-c", `dscl -q . -read /Users/"$(whoami)" NFSHomeDirectory | sed 's/^[^ ]*: //'`)
|
|
||||||
cmd.Stdout = &stdout
|
|
||||||
if err := cmd.Run(); err == nil {
|
|
||||||
result := strings.TrimSpace(stdout.String())
|
|
||||||
if result != "" {
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cmd := exec.Command("getent", "passwd", strconv.Itoa(os.Getuid()))
|
|
||||||
cmd.Stdout = &stdout
|
|
||||||
if err := cmd.Run(); err != nil {
|
|
||||||
// If the error is ErrNotFound, we ignore it. Otherwise, return it.
|
|
||||||
if err != exec.ErrNotFound {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if passwd := strings.TrimSpace(stdout.String()); passwd != "" {
|
|
||||||
// username:password:uid:gid:gecos:home:shell
|
|
||||||
passwdParts := strings.SplitN(passwd, ":", 7)
|
|
||||||
if len(passwdParts) > 5 {
|
|
||||||
return passwdParts[5], nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If all else fails, try the shell
|
|
||||||
stdout.Reset()
|
|
||||||
cmd := exec.Command("sh", "-c", "cd && pwd")
|
|
||||||
cmd.Stdout = &stdout
|
|
||||||
if err := cmd.Run(); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
result := strings.TrimSpace(stdout.String())
|
|
||||||
if result == "" {
|
|
||||||
return "", errors.New("blank output when reading home directory")
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func dirWindows() (string, error) {
|
|
||||||
// First prefer the HOME environmental variable
|
|
||||||
if home := os.Getenv("HOME"); home != "" {
|
|
||||||
return home, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prefer standard environment variable USERPROFILE
|
|
||||||
if home := os.Getenv("USERPROFILE"); home != "" {
|
|
||||||
return home, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
drive := os.Getenv("HOMEDRIVE")
|
|
||||||
path := os.Getenv("HOMEPATH")
|
|
||||||
home := drive + path
|
|
||||||
if drive == "" || path == "" {
|
|
||||||
return "", errors.New("HOMEDRIVE, HOMEPATH, or USERPROFILE are blank")
|
|
||||||
}
|
|
||||||
|
|
||||||
return home, nil
|
|
||||||
}
|
|
19
vendor/github.com/nightlyone/lockfile/LICENSE
generated
vendored
19
vendor/github.com/nightlyone/lockfile/LICENSE
generated
vendored
|
@ -1,19 +0,0 @@
|
||||||
Copyright (c) 2012 Ingo Oeser
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
211
vendor/github.com/nightlyone/lockfile/lockfile.go
generated
vendored
211
vendor/github.com/nightlyone/lockfile/lockfile.go
generated
vendored
|
@ -1,211 +0,0 @@
|
||||||
// Package lockfile handles pid file based locking.
|
|
||||||
// While a sync.Mutex helps against concurrency issues within a single process,
|
|
||||||
// this package is designed to help against concurrency issues between cooperating processes
|
|
||||||
// or serializing multiple invocations of the same process. You can also combine sync.Mutex
|
|
||||||
// with Lockfile in order to serialize an action between different goroutines in a single program
|
|
||||||
// and also multiple invocations of this program.
|
|
||||||
package lockfile
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Lockfile is a pid file which can be locked
|
|
||||||
type Lockfile string
|
|
||||||
|
|
||||||
// TemporaryError is a type of error where a retry after a random amount of sleep should help to mitigate it.
|
|
||||||
type TemporaryError string
|
|
||||||
|
|
||||||
func (t TemporaryError) Error() string { return string(t) }
|
|
||||||
|
|
||||||
// Temporary returns always true.
|
|
||||||
// It exists, so you can detect it via
|
|
||||||
// if te, ok := err.(interface{ Temporary() bool }); ok {
|
|
||||||
// fmt.Println("I am a temporay error situation, so wait and retry")
|
|
||||||
// }
|
|
||||||
func (t TemporaryError) Temporary() bool { return true }
|
|
||||||
|
|
||||||
// Various errors returned by this package
|
|
||||||
var (
|
|
||||||
ErrBusy = TemporaryError("Locked by other process") // If you get this, retry after a short sleep might help
|
|
||||||
ErrNotExist = TemporaryError("Lockfile created, but doesn't exist") // If you get this, retry after a short sleep might help
|
|
||||||
ErrNeedAbsPath = errors.New("Lockfiles must be given as absolute path names")
|
|
||||||
ErrInvalidPid = errors.New("Lockfile contains invalid pid for system")
|
|
||||||
ErrDeadOwner = errors.New("Lockfile contains pid of process not existent on this system anymore")
|
|
||||||
ErrRogueDeletion = errors.New("Lockfile owned by me has been removed unexpectedly")
|
|
||||||
)
|
|
||||||
|
|
||||||
// New describes a new filename located at the given absolute path.
|
|
||||||
func New(path string) (Lockfile, error) {
|
|
||||||
if !filepath.IsAbs(path) {
|
|
||||||
return Lockfile(""), ErrNeedAbsPath
|
|
||||||
}
|
|
||||||
return Lockfile(path), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetOwner returns who owns the lockfile.
|
|
||||||
func (l Lockfile) GetOwner() (*os.Process, error) {
|
|
||||||
name := string(l)
|
|
||||||
|
|
||||||
// Ok, see, if we have a stale lockfile here
|
|
||||||
content, err := ioutil.ReadFile(name)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// try hard for pids. If no pid, the lockfile is junk anyway and we delete it.
|
|
||||||
pid, err := scanPidLine(content)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
running, err := isRunning(pid)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if running {
|
|
||||||
proc, err := os.FindProcess(pid)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return proc, nil
|
|
||||||
}
|
|
||||||
return nil, ErrDeadOwner
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// TryLock tries to own the lock.
|
|
||||||
// It Returns nil, if successful and and error describing the reason, it didn't work out.
|
|
||||||
// Please note, that existing lockfiles containing pids of dead processes
|
|
||||||
// and lockfiles containing no pid at all are simply deleted.
|
|
||||||
func (l Lockfile) TryLock() error {
|
|
||||||
name := string(l)
|
|
||||||
|
|
||||||
// This has been checked by New already. If we trigger here,
|
|
||||||
// the caller didn't use New and re-implemented it's functionality badly.
|
|
||||||
// So panic, that he might find this easily during testing.
|
|
||||||
if !filepath.IsAbs(name) {
|
|
||||||
panic(ErrNeedAbsPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
tmplock, err := ioutil.TempFile(filepath.Dir(name), filepath.Base(name)+".")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup := func() {
|
|
||||||
_ = tmplock.Close()
|
|
||||||
_ = os.Remove(tmplock.Name())
|
|
||||||
}
|
|
||||||
defer cleanup()
|
|
||||||
|
|
||||||
if err := writePidLine(tmplock, os.Getpid()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// EEXIST and similiar error codes, caught by os.IsExist, are intentionally ignored,
|
|
||||||
// as it means that someone was faster creating this link
|
|
||||||
// and ignoring this kind of error is part of the algorithm.
|
|
||||||
// The we will probably fail the pid owner check later, if this process is still alive.
|
|
||||||
// We cannot ignore ALL errors, since failure to support hard links, disk full
|
|
||||||
// as well as many other errors can happen to a filesystem operation
|
|
||||||
// and we really want to abort on those.
|
|
||||||
if err := os.Link(tmplock.Name(), name); err != nil {
|
|
||||||
if !os.IsExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fiTmp, err := os.Lstat(tmplock.Name())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fiLock, err := os.Lstat(name)
|
|
||||||
if err != nil {
|
|
||||||
// tell user that a retry would be a good idea
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return ErrNotExist
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Success
|
|
||||||
if os.SameFile(fiTmp, fiLock) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
proc, err := l.GetOwner()
|
|
||||||
switch err {
|
|
||||||
default:
|
|
||||||
// Other errors -> defensively fail and let caller handle this
|
|
||||||
return err
|
|
||||||
case nil:
|
|
||||||
if proc.Pid != os.Getpid() {
|
|
||||||
return ErrBusy
|
|
||||||
}
|
|
||||||
case ErrDeadOwner, ErrInvalidPid:
|
|
||||||
// cases we can fix below
|
|
||||||
}
|
|
||||||
|
|
||||||
// clean stale/invalid lockfile
|
|
||||||
err = os.Remove(name)
|
|
||||||
if err != nil {
|
|
||||||
// If it doesn't exist, then it doesn't matter who removed it.
|
|
||||||
if !os.IsNotExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// now that the stale lockfile is gone, let's recurse
|
|
||||||
return l.TryLock()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unlock a lock again, if we owned it. Returns any error that happend during release of lock.
|
|
||||||
func (l Lockfile) Unlock() error {
|
|
||||||
proc, err := l.GetOwner()
|
|
||||||
switch err {
|
|
||||||
case ErrInvalidPid, ErrDeadOwner:
|
|
||||||
return ErrRogueDeletion
|
|
||||||
case nil:
|
|
||||||
if proc.Pid == os.Getpid() {
|
|
||||||
// we really own it, so let's remove it.
|
|
||||||
return os.Remove(string(l))
|
|
||||||
}
|
|
||||||
// Not owned by me, so don't delete it.
|
|
||||||
return ErrRogueDeletion
|
|
||||||
default:
|
|
||||||
// This is an application error or system error.
|
|
||||||
// So give a better error for logging here.
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return ErrRogueDeletion
|
|
||||||
}
|
|
||||||
// Other errors -> defensively fail and let caller handle this
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func writePidLine(w io.Writer, pid int) error {
|
|
||||||
_, err := io.WriteString(w, fmt.Sprintf("%d\n", pid))
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func scanPidLine(content []byte) (int, error) {
|
|
||||||
if len(content) == 0 {
|
|
||||||
return 0, ErrInvalidPid
|
|
||||||
}
|
|
||||||
|
|
||||||
var pid int
|
|
||||||
if _, err := fmt.Sscanln(string(content), &pid); err != nil {
|
|
||||||
return 0, ErrInvalidPid
|
|
||||||
}
|
|
||||||
|
|
||||||
if pid <= 0 {
|
|
||||||
return 0, ErrInvalidPid
|
|
||||||
}
|
|
||||||
return pid, nil
|
|
||||||
}
|
|
20
vendor/github.com/nightlyone/lockfile/lockfile_unix.go
generated
vendored
20
vendor/github.com/nightlyone/lockfile/lockfile_unix.go
generated
vendored
|
@ -1,20 +0,0 @@
|
||||||
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris aix
|
|
||||||
|
|
||||||
package lockfile
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
func isRunning(pid int) (bool, error) {
|
|
||||||
proc, err := os.FindProcess(pid)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := proc.Signal(syscall.Signal(0)); err != nil {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
return true, nil
|
|
||||||
}
|
|
30
vendor/github.com/nightlyone/lockfile/lockfile_windows.go
generated
vendored
30
vendor/github.com/nightlyone/lockfile/lockfile_windows.go
generated
vendored
|
@ -1,30 +0,0 @@
|
||||||
package lockfile
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
//For some reason these consts don't exist in syscall.
|
|
||||||
const (
|
|
||||||
error_invalid_parameter = 87
|
|
||||||
code_still_active = 259
|
|
||||||
)
|
|
||||||
|
|
||||||
func isRunning(pid int) (bool, error) {
|
|
||||||
procHnd, err := syscall.OpenProcess(syscall.PROCESS_QUERY_INFORMATION, true, uint32(pid))
|
|
||||||
if err != nil {
|
|
||||||
if scerr, ok := err.(syscall.Errno); ok {
|
|
||||||
if uintptr(scerr) == error_invalid_parameter {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var code uint32
|
|
||||||
err = syscall.GetExitCodeProcess(procHnd, &code)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return code == code_still_active, nil
|
|
||||||
}
|
|
20
vendor/github.com/onsi/ginkgo/LICENSE
generated
vendored
20
vendor/github.com/onsi/ginkgo/LICENSE
generated
vendored
|
@ -1,20 +0,0 @@
|
||||||
Copyright (c) 2013-2014 Onsi Fakhouri
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
a copy of this software and associated documentation files (the
|
|
||||||
"Software"), to deal in the Software without restriction, including
|
|
||||||
without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be
|
|
||||||
included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
200
vendor/github.com/onsi/ginkgo/config/config.go
generated
vendored
200
vendor/github.com/onsi/ginkgo/config/config.go
generated
vendored
|
@ -1,200 +0,0 @@
|
||||||
/*
|
|
||||||
Ginkgo accepts a number of configuration options.
|
|
||||||
|
|
||||||
These are documented [here](http://onsi.github.io/ginkgo/#the_ginkgo_cli)
|
|
||||||
|
|
||||||
You can also learn more via
|
|
||||||
|
|
||||||
ginkgo help
|
|
||||||
|
|
||||||
or (I kid you not):
|
|
||||||
|
|
||||||
go test -asdf
|
|
||||||
*/
|
|
||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
const VERSION = "1.6.0"
|
|
||||||
|
|
||||||
type GinkgoConfigType struct {
|
|
||||||
RandomSeed int64
|
|
||||||
RandomizeAllSpecs bool
|
|
||||||
RegexScansFilePath bool
|
|
||||||
FocusString string
|
|
||||||
SkipString string
|
|
||||||
SkipMeasurements bool
|
|
||||||
FailOnPending bool
|
|
||||||
FailFast bool
|
|
||||||
FlakeAttempts int
|
|
||||||
EmitSpecProgress bool
|
|
||||||
DryRun bool
|
|
||||||
DebugParallel bool
|
|
||||||
|
|
||||||
ParallelNode int
|
|
||||||
ParallelTotal int
|
|
||||||
SyncHost string
|
|
||||||
StreamHost string
|
|
||||||
}
|
|
||||||
|
|
||||||
var GinkgoConfig = GinkgoConfigType{}
|
|
||||||
|
|
||||||
type DefaultReporterConfigType struct {
|
|
||||||
NoColor bool
|
|
||||||
SlowSpecThreshold float64
|
|
||||||
NoisyPendings bool
|
|
||||||
NoisySkippings bool
|
|
||||||
Succinct bool
|
|
||||||
Verbose bool
|
|
||||||
FullTrace bool
|
|
||||||
}
|
|
||||||
|
|
||||||
var DefaultReporterConfig = DefaultReporterConfigType{}
|
|
||||||
|
|
||||||
func processPrefix(prefix string) string {
|
|
||||||
if prefix != "" {
|
|
||||||
prefix = prefix + "."
|
|
||||||
}
|
|
||||||
return prefix
|
|
||||||
}
|
|
||||||
|
|
||||||
func Flags(flagSet *flag.FlagSet, prefix string, includeParallelFlags bool) {
|
|
||||||
prefix = processPrefix(prefix)
|
|
||||||
flagSet.Int64Var(&(GinkgoConfig.RandomSeed), prefix+"seed", time.Now().Unix(), "The seed used to randomize the spec suite.")
|
|
||||||
flagSet.BoolVar(&(GinkgoConfig.RandomizeAllSpecs), prefix+"randomizeAllSpecs", false, "If set, ginkgo will randomize all specs together. By default, ginkgo only randomizes the top level Describe, Context and When groups.")
|
|
||||||
flagSet.BoolVar(&(GinkgoConfig.SkipMeasurements), prefix+"skipMeasurements", false, "If set, ginkgo will skip any measurement specs.")
|
|
||||||
flagSet.BoolVar(&(GinkgoConfig.FailOnPending), prefix+"failOnPending", false, "If set, ginkgo will mark the test suite as failed if any specs are pending.")
|
|
||||||
flagSet.BoolVar(&(GinkgoConfig.FailFast), prefix+"failFast", false, "If set, ginkgo will stop running a test suite after a failure occurs.")
|
|
||||||
|
|
||||||
flagSet.BoolVar(&(GinkgoConfig.DryRun), prefix+"dryRun", false, "If set, ginkgo will walk the test hierarchy without actually running anything. Best paired with -v.")
|
|
||||||
|
|
||||||
flagSet.StringVar(&(GinkgoConfig.FocusString), prefix+"focus", "", "If set, ginkgo will only run specs that match this regular expression.")
|
|
||||||
flagSet.StringVar(&(GinkgoConfig.SkipString), prefix+"skip", "", "If set, ginkgo will only run specs that do not match this regular expression.")
|
|
||||||
|
|
||||||
flagSet.BoolVar(&(GinkgoConfig.RegexScansFilePath), prefix+"regexScansFilePath", false, "If set, ginkgo regex matching also will look at the file path (code location).")
|
|
||||||
|
|
||||||
flagSet.IntVar(&(GinkgoConfig.FlakeAttempts), prefix+"flakeAttempts", 1, "Make up to this many attempts to run each spec. Please note that if any of the attempts succeed, the suite will not be failed. But any failures will still be recorded.")
|
|
||||||
|
|
||||||
flagSet.BoolVar(&(GinkgoConfig.EmitSpecProgress), prefix+"progress", false, "If set, ginkgo will emit progress information as each spec runs to the GinkgoWriter.")
|
|
||||||
|
|
||||||
flagSet.BoolVar(&(GinkgoConfig.DebugParallel), prefix+"debug", false, "If set, ginkgo will emit node output to files when running in parallel.")
|
|
||||||
|
|
||||||
if includeParallelFlags {
|
|
||||||
flagSet.IntVar(&(GinkgoConfig.ParallelNode), prefix+"parallel.node", 1, "This worker node's (one-indexed) node number. For running specs in parallel.")
|
|
||||||
flagSet.IntVar(&(GinkgoConfig.ParallelTotal), prefix+"parallel.total", 1, "The total number of worker nodes. For running specs in parallel.")
|
|
||||||
flagSet.StringVar(&(GinkgoConfig.SyncHost), prefix+"parallel.synchost", "", "The address for the server that will synchronize the running nodes.")
|
|
||||||
flagSet.StringVar(&(GinkgoConfig.StreamHost), prefix+"parallel.streamhost", "", "The address for the server that the running nodes should stream data to.")
|
|
||||||
}
|
|
||||||
|
|
||||||
flagSet.BoolVar(&(DefaultReporterConfig.NoColor), prefix+"noColor", false, "If set, suppress color output in default reporter.")
|
|
||||||
flagSet.Float64Var(&(DefaultReporterConfig.SlowSpecThreshold), prefix+"slowSpecThreshold", 5.0, "(in seconds) Specs that take longer to run than this threshold are flagged as slow by the default reporter.")
|
|
||||||
flagSet.BoolVar(&(DefaultReporterConfig.NoisyPendings), prefix+"noisyPendings", true, "If set, default reporter will shout about pending tests.")
|
|
||||||
flagSet.BoolVar(&(DefaultReporterConfig.NoisySkippings), prefix+"noisySkippings", true, "If set, default reporter will shout about skipping tests.")
|
|
||||||
flagSet.BoolVar(&(DefaultReporterConfig.Verbose), prefix+"v", false, "If set, default reporter print out all specs as they begin.")
|
|
||||||
flagSet.BoolVar(&(DefaultReporterConfig.Succinct), prefix+"succinct", false, "If set, default reporter prints out a very succinct report")
|
|
||||||
flagSet.BoolVar(&(DefaultReporterConfig.FullTrace), prefix+"trace", false, "If set, default reporter prints out the full stack trace when a failure occurs")
|
|
||||||
}
|
|
||||||
|
|
||||||
func BuildFlagArgs(prefix string, ginkgo GinkgoConfigType, reporter DefaultReporterConfigType) []string {
|
|
||||||
prefix = processPrefix(prefix)
|
|
||||||
result := make([]string, 0)
|
|
||||||
|
|
||||||
if ginkgo.RandomSeed > 0 {
|
|
||||||
result = append(result, fmt.Sprintf("--%sseed=%d", prefix, ginkgo.RandomSeed))
|
|
||||||
}
|
|
||||||
|
|
||||||
if ginkgo.RandomizeAllSpecs {
|
|
||||||
result = append(result, fmt.Sprintf("--%srandomizeAllSpecs", prefix))
|
|
||||||
}
|
|
||||||
|
|
||||||
if ginkgo.SkipMeasurements {
|
|
||||||
result = append(result, fmt.Sprintf("--%sskipMeasurements", prefix))
|
|
||||||
}
|
|
||||||
|
|
||||||
if ginkgo.FailOnPending {
|
|
||||||
result = append(result, fmt.Sprintf("--%sfailOnPending", prefix))
|
|
||||||
}
|
|
||||||
|
|
||||||
if ginkgo.FailFast {
|
|
||||||
result = append(result, fmt.Sprintf("--%sfailFast", prefix))
|
|
||||||
}
|
|
||||||
|
|
||||||
if ginkgo.DryRun {
|
|
||||||
result = append(result, fmt.Sprintf("--%sdryRun", prefix))
|
|
||||||
}
|
|
||||||
|
|
||||||
if ginkgo.FocusString != "" {
|
|
||||||
result = append(result, fmt.Sprintf("--%sfocus=%s", prefix, ginkgo.FocusString))
|
|
||||||
}
|
|
||||||
|
|
||||||
if ginkgo.SkipString != "" {
|
|
||||||
result = append(result, fmt.Sprintf("--%sskip=%s", prefix, ginkgo.SkipString))
|
|
||||||
}
|
|
||||||
|
|
||||||
if ginkgo.FlakeAttempts > 1 {
|
|
||||||
result = append(result, fmt.Sprintf("--%sflakeAttempts=%d", prefix, ginkgo.FlakeAttempts))
|
|
||||||
}
|
|
||||||
|
|
||||||
if ginkgo.EmitSpecProgress {
|
|
||||||
result = append(result, fmt.Sprintf("--%sprogress", prefix))
|
|
||||||
}
|
|
||||||
|
|
||||||
if ginkgo.DebugParallel {
|
|
||||||
result = append(result, fmt.Sprintf("--%sdebug", prefix))
|
|
||||||
}
|
|
||||||
|
|
||||||
if ginkgo.ParallelNode != 0 {
|
|
||||||
result = append(result, fmt.Sprintf("--%sparallel.node=%d", prefix, ginkgo.ParallelNode))
|
|
||||||
}
|
|
||||||
|
|
||||||
if ginkgo.ParallelTotal != 0 {
|
|
||||||
result = append(result, fmt.Sprintf("--%sparallel.total=%d", prefix, ginkgo.ParallelTotal))
|
|
||||||
}
|
|
||||||
|
|
||||||
if ginkgo.StreamHost != "" {
|
|
||||||
result = append(result, fmt.Sprintf("--%sparallel.streamhost=%s", prefix, ginkgo.StreamHost))
|
|
||||||
}
|
|
||||||
|
|
||||||
if ginkgo.SyncHost != "" {
|
|
||||||
result = append(result, fmt.Sprintf("--%sparallel.synchost=%s", prefix, ginkgo.SyncHost))
|
|
||||||
}
|
|
||||||
|
|
||||||
if ginkgo.RegexScansFilePath {
|
|
||||||
result = append(result, fmt.Sprintf("--%sregexScansFilePath", prefix))
|
|
||||||
}
|
|
||||||
|
|
||||||
if reporter.NoColor {
|
|
||||||
result = append(result, fmt.Sprintf("--%snoColor", prefix))
|
|
||||||
}
|
|
||||||
|
|
||||||
if reporter.SlowSpecThreshold > 0 {
|
|
||||||
result = append(result, fmt.Sprintf("--%sslowSpecThreshold=%.5f", prefix, reporter.SlowSpecThreshold))
|
|
||||||
}
|
|
||||||
|
|
||||||
if !reporter.NoisyPendings {
|
|
||||||
result = append(result, fmt.Sprintf("--%snoisyPendings=false", prefix))
|
|
||||||
}
|
|
||||||
|
|
||||||
if !reporter.NoisySkippings {
|
|
||||||
result = append(result, fmt.Sprintf("--%snoisySkippings=false", prefix))
|
|
||||||
}
|
|
||||||
|
|
||||||
if reporter.Verbose {
|
|
||||||
result = append(result, fmt.Sprintf("--%sv", prefix))
|
|
||||||
}
|
|
||||||
|
|
||||||
if reporter.Succinct {
|
|
||||||
result = append(result, fmt.Sprintf("--%ssuccinct", prefix))
|
|
||||||
}
|
|
||||||
|
|
||||||
if reporter.FullTrace {
|
|
||||||
result = append(result, fmt.Sprintf("--%strace", prefix))
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
609
vendor/github.com/onsi/ginkgo/ginkgo_dsl.go
generated
vendored
609
vendor/github.com/onsi/ginkgo/ginkgo_dsl.go
generated
vendored
|
@ -1,609 +0,0 @@
|
||||||
/*
|
|
||||||
Ginkgo is a BDD-style testing framework for Golang
|
|
||||||
|
|
||||||
The godoc documentation describes Ginkgo's API. More comprehensive documentation (with examples!) is available at http://onsi.github.io/ginkgo/
|
|
||||||
|
|
||||||
Ginkgo's preferred matcher library is [Gomega](http://github.com/onsi/gomega)
|
|
||||||
|
|
||||||
Ginkgo on Github: http://github.com/onsi/ginkgo
|
|
||||||
|
|
||||||
Ginkgo is MIT-Licensed
|
|
||||||
*/
|
|
||||||
package ginkgo
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/config"
|
|
||||||
"github.com/onsi/ginkgo/internal/codelocation"
|
|
||||||
"github.com/onsi/ginkgo/internal/failer"
|
|
||||||
"github.com/onsi/ginkgo/internal/remote"
|
|
||||||
"github.com/onsi/ginkgo/internal/suite"
|
|
||||||
"github.com/onsi/ginkgo/internal/testingtproxy"
|
|
||||||
"github.com/onsi/ginkgo/internal/writer"
|
|
||||||
"github.com/onsi/ginkgo/reporters"
|
|
||||||
"github.com/onsi/ginkgo/reporters/stenographer"
|
|
||||||
colorable "github.com/onsi/ginkgo/reporters/stenographer/support/go-colorable"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
const GINKGO_VERSION = config.VERSION
|
|
||||||
const GINKGO_PANIC = `
|
|
||||||
Your test failed.
|
|
||||||
Ginkgo panics to prevent subsequent assertions from running.
|
|
||||||
Normally Ginkgo rescues this panic so you shouldn't see it.
|
|
||||||
|
|
||||||
But, if you make an assertion in a goroutine, Ginkgo can't capture the panic.
|
|
||||||
To circumvent this, you should call
|
|
||||||
|
|
||||||
defer GinkgoRecover()
|
|
||||||
|
|
||||||
at the top of the goroutine that caused this panic.
|
|
||||||
`
|
|
||||||
const defaultTimeout = 1
|
|
||||||
|
|
||||||
var globalSuite *suite.Suite
|
|
||||||
var globalFailer *failer.Failer
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
config.Flags(flag.CommandLine, "ginkgo", true)
|
|
||||||
GinkgoWriter = writer.New(os.Stdout)
|
|
||||||
globalFailer = failer.New()
|
|
||||||
globalSuite = suite.New(globalFailer)
|
|
||||||
}
|
|
||||||
|
|
||||||
//GinkgoWriter implements an io.Writer
|
|
||||||
//When running in verbose mode any writes to GinkgoWriter will be immediately printed
|
|
||||||
//to stdout. Otherwise, GinkgoWriter will buffer any writes produced during the current test and flush them to screen
|
|
||||||
//only if the current test fails.
|
|
||||||
var GinkgoWriter io.Writer
|
|
||||||
|
|
||||||
//The interface by which Ginkgo receives *testing.T
|
|
||||||
type GinkgoTestingT interface {
|
|
||||||
Fail()
|
|
||||||
}
|
|
||||||
|
|
||||||
//GinkgoRandomSeed returns the seed used to randomize spec execution order. It is
|
|
||||||
//useful for seeding your own pseudorandom number generators (PRNGs) to ensure
|
|
||||||
//consistent executions from run to run, where your tests contain variability (for
|
|
||||||
//example, when selecting random test data).
|
|
||||||
func GinkgoRandomSeed() int64 {
|
|
||||||
return config.GinkgoConfig.RandomSeed
|
|
||||||
}
|
|
||||||
|
|
||||||
//GinkgoParallelNode returns the parallel node number for the current ginkgo process
|
|
||||||
//The node number is 1-indexed
|
|
||||||
func GinkgoParallelNode() int {
|
|
||||||
return config.GinkgoConfig.ParallelNode
|
|
||||||
}
|
|
||||||
|
|
||||||
//Some matcher libraries or legacy codebases require a *testing.T
|
|
||||||
//GinkgoT implements an interface analogous to *testing.T and can be used if
|
|
||||||
//the library in question accepts *testing.T through an interface
|
|
||||||
//
|
|
||||||
// For example, with testify:
|
|
||||||
// assert.Equal(GinkgoT(), 123, 123, "they should be equal")
|
|
||||||
//
|
|
||||||
// Or with gomock:
|
|
||||||
// gomock.NewController(GinkgoT())
|
|
||||||
//
|
|
||||||
// GinkgoT() takes an optional offset argument that can be used to get the
|
|
||||||
// correct line number associated with the failure.
|
|
||||||
func GinkgoT(optionalOffset ...int) GinkgoTInterface {
|
|
||||||
offset := 3
|
|
||||||
if len(optionalOffset) > 0 {
|
|
||||||
offset = optionalOffset[0]
|
|
||||||
}
|
|
||||||
return testingtproxy.New(GinkgoWriter, Fail, offset)
|
|
||||||
}
|
|
||||||
|
|
||||||
//The interface returned by GinkgoT(). This covers most of the methods
|
|
||||||
//in the testing package's T.
|
|
||||||
type GinkgoTInterface interface {
|
|
||||||
Fail()
|
|
||||||
Error(args ...interface{})
|
|
||||||
Errorf(format string, args ...interface{})
|
|
||||||
FailNow()
|
|
||||||
Fatal(args ...interface{})
|
|
||||||
Fatalf(format string, args ...interface{})
|
|
||||||
Log(args ...interface{})
|
|
||||||
Logf(format string, args ...interface{})
|
|
||||||
Failed() bool
|
|
||||||
Parallel()
|
|
||||||
Skip(args ...interface{})
|
|
||||||
Skipf(format string, args ...interface{})
|
|
||||||
SkipNow()
|
|
||||||
Skipped() bool
|
|
||||||
}
|
|
||||||
|
|
||||||
//Custom Ginkgo test reporters must implement the Reporter interface.
|
|
||||||
//
|
|
||||||
//The custom reporter is passed in a SuiteSummary when the suite begins and ends,
|
|
||||||
//and a SpecSummary just before a spec begins and just after a spec ends
|
|
||||||
type Reporter reporters.Reporter
|
|
||||||
|
|
||||||
//Asynchronous specs are given a channel of the Done type. You must close or write to the channel
|
|
||||||
//to tell Ginkgo that your async test is done.
|
|
||||||
type Done chan<- interface{}
|
|
||||||
|
|
||||||
//GinkgoTestDescription represents the information about the current running test returned by CurrentGinkgoTestDescription
|
|
||||||
// FullTestText: a concatenation of ComponentTexts and the TestText
|
|
||||||
// ComponentTexts: a list of all texts for the Describes & Contexts leading up to the current test
|
|
||||||
// TestText: the text in the actual It or Measure node
|
|
||||||
// IsMeasurement: true if the current test is a measurement
|
|
||||||
// FileName: the name of the file containing the current test
|
|
||||||
// LineNumber: the line number for the current test
|
|
||||||
// Failed: if the current test has failed, this will be true (useful in an AfterEach)
|
|
||||||
type GinkgoTestDescription struct {
|
|
||||||
FullTestText string
|
|
||||||
ComponentTexts []string
|
|
||||||
TestText string
|
|
||||||
|
|
||||||
IsMeasurement bool
|
|
||||||
|
|
||||||
FileName string
|
|
||||||
LineNumber int
|
|
||||||
|
|
||||||
Failed bool
|
|
||||||
Duration time.Duration
|
|
||||||
}
|
|
||||||
|
|
||||||
//CurrentGinkgoTestDescripton returns information about the current running test.
|
|
||||||
func CurrentGinkgoTestDescription() GinkgoTestDescription {
|
|
||||||
summary, ok := globalSuite.CurrentRunningSpecSummary()
|
|
||||||
if !ok {
|
|
||||||
return GinkgoTestDescription{}
|
|
||||||
}
|
|
||||||
|
|
||||||
subjectCodeLocation := summary.ComponentCodeLocations[len(summary.ComponentCodeLocations)-1]
|
|
||||||
|
|
||||||
return GinkgoTestDescription{
|
|
||||||
ComponentTexts: summary.ComponentTexts[1:],
|
|
||||||
FullTestText: strings.Join(summary.ComponentTexts[1:], " "),
|
|
||||||
TestText: summary.ComponentTexts[len(summary.ComponentTexts)-1],
|
|
||||||
IsMeasurement: summary.IsMeasurement,
|
|
||||||
FileName: subjectCodeLocation.FileName,
|
|
||||||
LineNumber: subjectCodeLocation.LineNumber,
|
|
||||||
Failed: summary.HasFailureState(),
|
|
||||||
Duration: summary.RunTime,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Measurement tests receive a Benchmarker.
|
|
||||||
//
|
|
||||||
//You use the Time() function to time how long the passed in body function takes to run
|
|
||||||
//You use the RecordValue() function to track arbitrary numerical measurements.
|
|
||||||
//The RecordValueWithPrecision() function can be used alternatively to provide the unit
|
|
||||||
//and resolution of the numeric measurement.
|
|
||||||
//The optional info argument is passed to the test reporter and can be used to
|
|
||||||
// provide the measurement data to a custom reporter with context.
|
|
||||||
//
|
|
||||||
//See http://onsi.github.io/ginkgo/#benchmark_tests for more details
|
|
||||||
type Benchmarker interface {
|
|
||||||
Time(name string, body func(), info ...interface{}) (elapsedTime time.Duration)
|
|
||||||
RecordValue(name string, value float64, info ...interface{})
|
|
||||||
RecordValueWithPrecision(name string, value float64, units string, precision int, info ...interface{})
|
|
||||||
}
|
|
||||||
|
|
||||||
//RunSpecs is the entry point for the Ginkgo test runner.
|
|
||||||
//You must call this within a Golang testing TestX(t *testing.T) function.
|
|
||||||
//
|
|
||||||
//To bootstrap a test suite you can use the Ginkgo CLI:
|
|
||||||
//
|
|
||||||
// ginkgo bootstrap
|
|
||||||
func RunSpecs(t GinkgoTestingT, description string) bool {
|
|
||||||
specReporters := []Reporter{buildDefaultReporter()}
|
|
||||||
return RunSpecsWithCustomReporters(t, description, specReporters)
|
|
||||||
}
|
|
||||||
|
|
||||||
//To run your tests with Ginkgo's default reporter and your custom reporter(s), replace
|
|
||||||
//RunSpecs() with this method.
|
|
||||||
func RunSpecsWithDefaultAndCustomReporters(t GinkgoTestingT, description string, specReporters []Reporter) bool {
|
|
||||||
specReporters = append(specReporters, buildDefaultReporter())
|
|
||||||
return RunSpecsWithCustomReporters(t, description, specReporters)
|
|
||||||
}
|
|
||||||
|
|
||||||
//To run your tests with your custom reporter(s) (and *not* Ginkgo's default reporter), replace
|
|
||||||
//RunSpecs() with this method. Note that parallel tests will not work correctly without the default reporter
|
|
||||||
func RunSpecsWithCustomReporters(t GinkgoTestingT, description string, specReporters []Reporter) bool {
|
|
||||||
writer := GinkgoWriter.(*writer.Writer)
|
|
||||||
writer.SetStream(config.DefaultReporterConfig.Verbose)
|
|
||||||
reporters := make([]reporters.Reporter, len(specReporters))
|
|
||||||
for i, reporter := range specReporters {
|
|
||||||
reporters[i] = reporter
|
|
||||||
}
|
|
||||||
passed, hasFocusedTests := globalSuite.Run(t, description, reporters, writer, config.GinkgoConfig)
|
|
||||||
if passed && hasFocusedTests && strings.TrimSpace(os.Getenv("GINKGO_EDITOR_INTEGRATION")) == "" {
|
|
||||||
fmt.Println("PASS | FOCUSED")
|
|
||||||
os.Exit(types.GINKGO_FOCUS_EXIT_CODE)
|
|
||||||
}
|
|
||||||
return passed
|
|
||||||
}
|
|
||||||
|
|
||||||
func buildDefaultReporter() Reporter {
|
|
||||||
remoteReportingServer := config.GinkgoConfig.StreamHost
|
|
||||||
if remoteReportingServer == "" {
|
|
||||||
stenographer := stenographer.New(!config.DefaultReporterConfig.NoColor, config.GinkgoConfig.FlakeAttempts > 1, colorable.NewColorableStdout())
|
|
||||||
return reporters.NewDefaultReporter(config.DefaultReporterConfig, stenographer)
|
|
||||||
} else {
|
|
||||||
debugFile := ""
|
|
||||||
if config.GinkgoConfig.DebugParallel {
|
|
||||||
debugFile = fmt.Sprintf("ginkgo-node-%d.log", config.GinkgoConfig.ParallelNode)
|
|
||||||
}
|
|
||||||
return remote.NewForwardingReporter(config.DefaultReporterConfig, remoteReportingServer, &http.Client{}, remote.NewOutputInterceptor(), GinkgoWriter.(*writer.Writer), debugFile)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Skip notifies Ginkgo that the current spec was skipped.
|
|
||||||
func Skip(message string, callerSkip ...int) {
|
|
||||||
skip := 0
|
|
||||||
if len(callerSkip) > 0 {
|
|
||||||
skip = callerSkip[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
globalFailer.Skip(message, codelocation.New(skip+1))
|
|
||||||
panic(GINKGO_PANIC)
|
|
||||||
}
|
|
||||||
|
|
||||||
//Fail notifies Ginkgo that the current spec has failed. (Gomega will call Fail for you automatically when an assertion fails.)
|
|
||||||
func Fail(message string, callerSkip ...int) {
|
|
||||||
skip := 0
|
|
||||||
if len(callerSkip) > 0 {
|
|
||||||
skip = callerSkip[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
globalFailer.Fail(message, codelocation.New(skip+1))
|
|
||||||
panic(GINKGO_PANIC)
|
|
||||||
}
|
|
||||||
|
|
||||||
//GinkgoRecover should be deferred at the top of any spawned goroutine that (may) call `Fail`
|
|
||||||
//Since Gomega assertions call fail, you should throw a `defer GinkgoRecover()` at the top of any goroutine that
|
|
||||||
//calls out to Gomega
|
|
||||||
//
|
|
||||||
//Here's why: Ginkgo's `Fail` method records the failure and then panics to prevent
|
|
||||||
//further assertions from running. This panic must be recovered. Ginkgo does this for you
|
|
||||||
//if the panic originates in a Ginkgo node (an It, BeforeEach, etc...)
|
|
||||||
//
|
|
||||||
//Unfortunately, if a panic originates on a goroutine *launched* from one of these nodes there's no
|
|
||||||
//way for Ginkgo to rescue the panic. To do this, you must remember to `defer GinkgoRecover()` at the top of such a goroutine.
|
|
||||||
func GinkgoRecover() {
|
|
||||||
e := recover()
|
|
||||||
if e != nil {
|
|
||||||
globalFailer.Panic(codelocation.New(1), e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Describe blocks allow you to organize your specs. A Describe block can contain any number of
|
|
||||||
//BeforeEach, AfterEach, JustBeforeEach, It, and Measurement blocks.
|
|
||||||
//
|
|
||||||
//In addition you can nest Describe, Context and When blocks. Describe, Context and When blocks are functionally
|
|
||||||
//equivalent. The difference is purely semantic -- you typical Describe the behavior of an object
|
|
||||||
//or method and, within that Describe, outline a number of Contexts and Whens.
|
|
||||||
func Describe(text string, body func()) bool {
|
|
||||||
globalSuite.PushContainerNode(text, body, types.FlagTypeNone, codelocation.New(1))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//You can focus the tests within a describe block using FDescribe
|
|
||||||
func FDescribe(text string, body func()) bool {
|
|
||||||
globalSuite.PushContainerNode(text, body, types.FlagTypeFocused, codelocation.New(1))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//You can mark the tests within a describe block as pending using PDescribe
|
|
||||||
func PDescribe(text string, body func()) bool {
|
|
||||||
globalSuite.PushContainerNode(text, body, types.FlagTypePending, codelocation.New(1))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//You can mark the tests within a describe block as pending using XDescribe
|
|
||||||
func XDescribe(text string, body func()) bool {
|
|
||||||
globalSuite.PushContainerNode(text, body, types.FlagTypePending, codelocation.New(1))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//Context blocks allow you to organize your specs. A Context block can contain any number of
|
|
||||||
//BeforeEach, AfterEach, JustBeforeEach, It, and Measurement blocks.
|
|
||||||
//
|
|
||||||
//In addition you can nest Describe, Context and When blocks. Describe, Context and When blocks are functionally
|
|
||||||
//equivalent. The difference is purely semantic -- you typical Describe the behavior of an object
|
|
||||||
//or method and, within that Describe, outline a number of Contexts and Whens.
|
|
||||||
func Context(text string, body func()) bool {
|
|
||||||
globalSuite.PushContainerNode(text, body, types.FlagTypeNone, codelocation.New(1))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//You can focus the tests within a describe block using FContext
|
|
||||||
func FContext(text string, body func()) bool {
|
|
||||||
globalSuite.PushContainerNode(text, body, types.FlagTypeFocused, codelocation.New(1))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//You can mark the tests within a describe block as pending using PContext
|
|
||||||
func PContext(text string, body func()) bool {
|
|
||||||
globalSuite.PushContainerNode(text, body, types.FlagTypePending, codelocation.New(1))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//You can mark the tests within a describe block as pending using XContext
|
|
||||||
func XContext(text string, body func()) bool {
|
|
||||||
globalSuite.PushContainerNode(text, body, types.FlagTypePending, codelocation.New(1))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//When blocks allow you to organize your specs. A When block can contain any number of
|
|
||||||
//BeforeEach, AfterEach, JustBeforeEach, It, and Measurement blocks.
|
|
||||||
//
|
|
||||||
//In addition you can nest Describe, Context and When blocks. Describe, Context and When blocks are functionally
|
|
||||||
//equivalent. The difference is purely semantic -- you typical Describe the behavior of an object
|
|
||||||
//or method and, within that Describe, outline a number of Contexts and Whens.
|
|
||||||
func When(text string, body func()) bool {
|
|
||||||
globalSuite.PushContainerNode("when "+text, body, types.FlagTypeNone, codelocation.New(1))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//You can focus the tests within a describe block using FWhen
|
|
||||||
func FWhen(text string, body func()) bool {
|
|
||||||
globalSuite.PushContainerNode("when "+text, body, types.FlagTypeFocused, codelocation.New(1))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//You can mark the tests within a describe block as pending using PWhen
|
|
||||||
func PWhen(text string, body func()) bool {
|
|
||||||
globalSuite.PushContainerNode("when "+text, body, types.FlagTypePending, codelocation.New(1))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//You can mark the tests within a describe block as pending using XWhen
|
|
||||||
func XWhen(text string, body func()) bool {
|
|
||||||
globalSuite.PushContainerNode("when "+text, body, types.FlagTypePending, codelocation.New(1))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//It blocks contain your test code and assertions. You cannot nest any other Ginkgo blocks
|
|
||||||
//within an It block.
|
|
||||||
//
|
|
||||||
//Ginkgo will normally run It blocks synchronously. To perform asynchronous tests, pass a
|
|
||||||
//function that accepts a Done channel. When you do this, you can also provide an optional timeout.
|
|
||||||
func It(text string, body interface{}, timeout ...float64) bool {
|
|
||||||
globalSuite.PushItNode(text, body, types.FlagTypeNone, codelocation.New(1), parseTimeout(timeout...))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//You can focus individual Its using FIt
|
|
||||||
func FIt(text string, body interface{}, timeout ...float64) bool {
|
|
||||||
globalSuite.PushItNode(text, body, types.FlagTypeFocused, codelocation.New(1), parseTimeout(timeout...))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//You can mark Its as pending using PIt
|
|
||||||
func PIt(text string, _ ...interface{}) bool {
|
|
||||||
globalSuite.PushItNode(text, func() {}, types.FlagTypePending, codelocation.New(1), 0)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//You can mark Its as pending using XIt
|
|
||||||
func XIt(text string, _ ...interface{}) bool {
|
|
||||||
globalSuite.PushItNode(text, func() {}, types.FlagTypePending, codelocation.New(1), 0)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//Specify blocks are aliases for It blocks and allow for more natural wording in situations
|
|
||||||
//which "It" does not fit into a natural sentence flow. All the same protocols apply for Specify blocks
|
|
||||||
//which apply to It blocks.
|
|
||||||
func Specify(text string, body interface{}, timeout ...float64) bool {
|
|
||||||
globalSuite.PushItNode(text, body, types.FlagTypeNone, codelocation.New(1), parseTimeout(timeout...))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//You can focus individual Specifys using FSpecify
|
|
||||||
func FSpecify(text string, body interface{}, timeout ...float64) bool {
|
|
||||||
globalSuite.PushItNode(text, body, types.FlagTypeFocused, codelocation.New(1), parseTimeout(timeout...))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//You can mark Specifys as pending using PSpecify
|
|
||||||
func PSpecify(text string, is ...interface{}) bool {
|
|
||||||
globalSuite.PushItNode(text, func() {}, types.FlagTypePending, codelocation.New(1), 0)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//You can mark Specifys as pending using XSpecify
|
|
||||||
func XSpecify(text string, is ...interface{}) bool {
|
|
||||||
globalSuite.PushItNode(text, func() {}, types.FlagTypePending, codelocation.New(1), 0)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//By allows you to better document large Its.
|
|
||||||
//
|
|
||||||
//Generally you should try to keep your Its short and to the point. This is not always possible, however,
|
|
||||||
//especially in the context of integration tests that capture a particular workflow.
|
|
||||||
//
|
|
||||||
//By allows you to document such flows. By must be called within a runnable node (It, BeforeEach, Measure, etc...)
|
|
||||||
//By will simply log the passed in text to the GinkgoWriter. If By is handed a function it will immediately run the function.
|
|
||||||
func By(text string, callbacks ...func()) {
|
|
||||||
preamble := "\x1b[1mSTEP\x1b[0m"
|
|
||||||
if config.DefaultReporterConfig.NoColor {
|
|
||||||
preamble = "STEP"
|
|
||||||
}
|
|
||||||
fmt.Fprintln(GinkgoWriter, preamble+": "+text)
|
|
||||||
if len(callbacks) == 1 {
|
|
||||||
callbacks[0]()
|
|
||||||
}
|
|
||||||
if len(callbacks) > 1 {
|
|
||||||
panic("just one callback per By, please")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Measure blocks run the passed in body function repeatedly (determined by the samples argument)
|
|
||||||
//and accumulate metrics provided to the Benchmarker by the body function.
|
|
||||||
//
|
|
||||||
//The body function must have the signature:
|
|
||||||
// func(b Benchmarker)
|
|
||||||
func Measure(text string, body interface{}, samples int) bool {
|
|
||||||
globalSuite.PushMeasureNode(text, body, types.FlagTypeNone, codelocation.New(1), samples)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//You can focus individual Measures using FMeasure
|
|
||||||
func FMeasure(text string, body interface{}, samples int) bool {
|
|
||||||
globalSuite.PushMeasureNode(text, body, types.FlagTypeFocused, codelocation.New(1), samples)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//You can mark Maeasurements as pending using PMeasure
|
|
||||||
func PMeasure(text string, _ ...interface{}) bool {
|
|
||||||
globalSuite.PushMeasureNode(text, func(b Benchmarker) {}, types.FlagTypePending, codelocation.New(1), 0)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//You can mark Maeasurements as pending using XMeasure
|
|
||||||
func XMeasure(text string, _ ...interface{}) bool {
|
|
||||||
globalSuite.PushMeasureNode(text, func(b Benchmarker) {}, types.FlagTypePending, codelocation.New(1), 0)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//BeforeSuite blocks are run just once before any specs are run. When running in parallel, each
|
|
||||||
//parallel node process will call BeforeSuite.
|
|
||||||
//
|
|
||||||
//BeforeSuite blocks can be made asynchronous by providing a body function that accepts a Done channel
|
|
||||||
//
|
|
||||||
//You may only register *one* BeforeSuite handler per test suite. You typically do so in your bootstrap file at the top level.
|
|
||||||
func BeforeSuite(body interface{}, timeout ...float64) bool {
|
|
||||||
globalSuite.SetBeforeSuiteNode(body, codelocation.New(1), parseTimeout(timeout...))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//AfterSuite blocks are *always* run after all the specs regardless of whether specs have passed or failed.
|
|
||||||
//Moreover, if Ginkgo receives an interrupt signal (^C) it will attempt to run the AfterSuite before exiting.
|
|
||||||
//
|
|
||||||
//When running in parallel, each parallel node process will call AfterSuite.
|
|
||||||
//
|
|
||||||
//AfterSuite blocks can be made asynchronous by providing a body function that accepts a Done channel
|
|
||||||
//
|
|
||||||
//You may only register *one* AfterSuite handler per test suite. You typically do so in your bootstrap file at the top level.
|
|
||||||
func AfterSuite(body interface{}, timeout ...float64) bool {
|
|
||||||
globalSuite.SetAfterSuiteNode(body, codelocation.New(1), parseTimeout(timeout...))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//SynchronizedBeforeSuite blocks are primarily meant to solve the problem of setting up singleton external resources shared across
|
|
||||||
//nodes when running tests in parallel. For example, say you have a shared database that you can only start one instance of that
|
|
||||||
//must be used in your tests. When running in parallel, only one node should set up the database and all other nodes should wait
|
|
||||||
//until that node is done before running.
|
|
||||||
//
|
|
||||||
//SynchronizedBeforeSuite accomplishes this by taking *two* function arguments. The first is only run on parallel node #1. The second is
|
|
||||||
//run on all nodes, but *only* after the first function completes succesfully. Ginkgo also makes it possible to send data from the first function (on Node 1)
|
|
||||||
//to the second function (on all the other nodes).
|
|
||||||
//
|
|
||||||
//The functions have the following signatures. The first function (which only runs on node 1) has the signature:
|
|
||||||
//
|
|
||||||
// func() []byte
|
|
||||||
//
|
|
||||||
//or, to run asynchronously:
|
|
||||||
//
|
|
||||||
// func(done Done) []byte
|
|
||||||
//
|
|
||||||
//The byte array returned by the first function is then passed to the second function, which has the signature:
|
|
||||||
//
|
|
||||||
// func(data []byte)
|
|
||||||
//
|
|
||||||
//or, to run asynchronously:
|
|
||||||
//
|
|
||||||
// func(data []byte, done Done)
|
|
||||||
//
|
|
||||||
//Here's a simple pseudo-code example that starts a shared database on Node 1 and shares the database's address with the other nodes:
|
|
||||||
//
|
|
||||||
// var dbClient db.Client
|
|
||||||
// var dbRunner db.Runner
|
|
||||||
//
|
|
||||||
// var _ = SynchronizedBeforeSuite(func() []byte {
|
|
||||||
// dbRunner = db.NewRunner()
|
|
||||||
// err := dbRunner.Start()
|
|
||||||
// Ω(err).ShouldNot(HaveOccurred())
|
|
||||||
// return []byte(dbRunner.URL)
|
|
||||||
// }, func(data []byte) {
|
|
||||||
// dbClient = db.NewClient()
|
|
||||||
// err := dbClient.Connect(string(data))
|
|
||||||
// Ω(err).ShouldNot(HaveOccurred())
|
|
||||||
// })
|
|
||||||
func SynchronizedBeforeSuite(node1Body interface{}, allNodesBody interface{}, timeout ...float64) bool {
|
|
||||||
globalSuite.SetSynchronizedBeforeSuiteNode(
|
|
||||||
node1Body,
|
|
||||||
allNodesBody,
|
|
||||||
codelocation.New(1),
|
|
||||||
parseTimeout(timeout...),
|
|
||||||
)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//SynchronizedAfterSuite blocks complement the SynchronizedBeforeSuite blocks in solving the problem of setting up
|
|
||||||
//external singleton resources shared across nodes when running tests in parallel.
|
|
||||||
//
|
|
||||||
//SynchronizedAfterSuite accomplishes this by taking *two* function arguments. The first runs on all nodes. The second runs only on parallel node #1
|
|
||||||
//and *only* after all other nodes have finished and exited. This ensures that node 1, and any resources it is running, remain alive until
|
|
||||||
//all other nodes are finished.
|
|
||||||
//
|
|
||||||
//Both functions have the same signature: either func() or func(done Done) to run asynchronously.
|
|
||||||
//
|
|
||||||
//Here's a pseudo-code example that complements that given in SynchronizedBeforeSuite. Here, SynchronizedAfterSuite is used to tear down the shared database
|
|
||||||
//only after all nodes have finished:
|
|
||||||
//
|
|
||||||
// var _ = SynchronizedAfterSuite(func() {
|
|
||||||
// dbClient.Cleanup()
|
|
||||||
// }, func() {
|
|
||||||
// dbRunner.Stop()
|
|
||||||
// })
|
|
||||||
func SynchronizedAfterSuite(allNodesBody interface{}, node1Body interface{}, timeout ...float64) bool {
|
|
||||||
globalSuite.SetSynchronizedAfterSuiteNode(
|
|
||||||
allNodesBody,
|
|
||||||
node1Body,
|
|
||||||
codelocation.New(1),
|
|
||||||
parseTimeout(timeout...),
|
|
||||||
)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//BeforeEach blocks are run before It blocks. When multiple BeforeEach blocks are defined in nested
|
|
||||||
//Describe and Context blocks the outermost BeforeEach blocks are run first.
|
|
||||||
//
|
|
||||||
//Like It blocks, BeforeEach blocks can be made asynchronous by providing a body function that accepts
|
|
||||||
//a Done channel
|
|
||||||
func BeforeEach(body interface{}, timeout ...float64) bool {
|
|
||||||
globalSuite.PushBeforeEachNode(body, codelocation.New(1), parseTimeout(timeout...))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//JustBeforeEach blocks are run before It blocks but *after* all BeforeEach blocks. For more details,
|
|
||||||
//read the [documentation](http://onsi.github.io/ginkgo/#separating_creation_and_configuration_)
|
|
||||||
//
|
|
||||||
//Like It blocks, BeforeEach blocks can be made asynchronous by providing a body function that accepts
|
|
||||||
//a Done channel
|
|
||||||
func JustBeforeEach(body interface{}, timeout ...float64) bool {
|
|
||||||
globalSuite.PushJustBeforeEachNode(body, codelocation.New(1), parseTimeout(timeout...))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//AfterEach blocks are run after It blocks. When multiple AfterEach blocks are defined in nested
|
|
||||||
//Describe and Context blocks the innermost AfterEach blocks are run first.
|
|
||||||
//
|
|
||||||
//Like It blocks, AfterEach blocks can be made asynchronous by providing a body function that accepts
|
|
||||||
//a Done channel
|
|
||||||
func AfterEach(body interface{}, timeout ...float64) bool {
|
|
||||||
globalSuite.PushAfterEachNode(body, codelocation.New(1), parseTimeout(timeout...))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseTimeout(timeout ...float64) time.Duration {
|
|
||||||
if len(timeout) == 0 {
|
|
||||||
return time.Duration(defaultTimeout * int64(time.Second))
|
|
||||||
} else {
|
|
||||||
return time.Duration(timeout[0] * float64(time.Second))
|
|
||||||
}
|
|
||||||
}
|
|
32
vendor/github.com/onsi/ginkgo/internal/codelocation/code_location.go
generated
vendored
32
vendor/github.com/onsi/ginkgo/internal/codelocation/code_location.go
generated
vendored
|
@ -1,32 +0,0 @@
|
||||||
package codelocation
|
|
||||||
|
|
||||||
import (
|
|
||||||
"regexp"
|
|
||||||
"runtime"
|
|
||||||
"runtime/debug"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func New(skip int) types.CodeLocation {
|
|
||||||
_, file, line, _ := runtime.Caller(skip + 1)
|
|
||||||
stackTrace := PruneStack(string(debug.Stack()), skip)
|
|
||||||
return types.CodeLocation{FileName: file, LineNumber: line, FullStackTrace: stackTrace}
|
|
||||||
}
|
|
||||||
|
|
||||||
func PruneStack(fullStackTrace string, skip int) string {
|
|
||||||
stack := strings.Split(fullStackTrace, "\n")
|
|
||||||
if len(stack) > 2*(skip+1) {
|
|
||||||
stack = stack[2*(skip+1):]
|
|
||||||
}
|
|
||||||
prunedStack := []string{}
|
|
||||||
re := regexp.MustCompile(`\/ginkgo\/|\/pkg\/testing\/|\/pkg\/runtime\/`)
|
|
||||||
for i := 0; i < len(stack)/2; i++ {
|
|
||||||
if !re.Match([]byte(stack[i*2])) {
|
|
||||||
prunedStack = append(prunedStack, stack[i*2])
|
|
||||||
prunedStack = append(prunedStack, stack[i*2+1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return strings.Join(prunedStack, "\n")
|
|
||||||
}
|
|
151
vendor/github.com/onsi/ginkgo/internal/containernode/container_node.go
generated
vendored
151
vendor/github.com/onsi/ginkgo/internal/containernode/container_node.go
generated
vendored
|
@ -1,151 +0,0 @@
|
||||||
package containernode
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math/rand"
|
|
||||||
"sort"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/internal/leafnodes"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type subjectOrContainerNode struct {
|
|
||||||
containerNode *ContainerNode
|
|
||||||
subjectNode leafnodes.SubjectNode
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n subjectOrContainerNode) text() string {
|
|
||||||
if n.containerNode != nil {
|
|
||||||
return n.containerNode.Text()
|
|
||||||
} else {
|
|
||||||
return n.subjectNode.Text()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type CollatedNodes struct {
|
|
||||||
Containers []*ContainerNode
|
|
||||||
Subject leafnodes.SubjectNode
|
|
||||||
}
|
|
||||||
|
|
||||||
type ContainerNode struct {
|
|
||||||
text string
|
|
||||||
flag types.FlagType
|
|
||||||
codeLocation types.CodeLocation
|
|
||||||
|
|
||||||
setupNodes []leafnodes.BasicNode
|
|
||||||
subjectAndContainerNodes []subjectOrContainerNode
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(text string, flag types.FlagType, codeLocation types.CodeLocation) *ContainerNode {
|
|
||||||
return &ContainerNode{
|
|
||||||
text: text,
|
|
||||||
flag: flag,
|
|
||||||
codeLocation: codeLocation,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (container *ContainerNode) Shuffle(r *rand.Rand) {
|
|
||||||
sort.Sort(container)
|
|
||||||
permutation := r.Perm(len(container.subjectAndContainerNodes))
|
|
||||||
shuffledNodes := make([]subjectOrContainerNode, len(container.subjectAndContainerNodes))
|
|
||||||
for i, j := range permutation {
|
|
||||||
shuffledNodes[i] = container.subjectAndContainerNodes[j]
|
|
||||||
}
|
|
||||||
container.subjectAndContainerNodes = shuffledNodes
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *ContainerNode) BackPropagateProgrammaticFocus() bool {
|
|
||||||
if node.flag == types.FlagTypePending {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldUnfocus := false
|
|
||||||
for _, subjectOrContainerNode := range node.subjectAndContainerNodes {
|
|
||||||
if subjectOrContainerNode.containerNode != nil {
|
|
||||||
shouldUnfocus = subjectOrContainerNode.containerNode.BackPropagateProgrammaticFocus() || shouldUnfocus
|
|
||||||
} else {
|
|
||||||
shouldUnfocus = (subjectOrContainerNode.subjectNode.Flag() == types.FlagTypeFocused) || shouldUnfocus
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if shouldUnfocus {
|
|
||||||
if node.flag == types.FlagTypeFocused {
|
|
||||||
node.flag = types.FlagTypeNone
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return node.flag == types.FlagTypeFocused
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *ContainerNode) Collate() []CollatedNodes {
|
|
||||||
return node.collate([]*ContainerNode{})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *ContainerNode) collate(enclosingContainers []*ContainerNode) []CollatedNodes {
|
|
||||||
collated := make([]CollatedNodes, 0)
|
|
||||||
|
|
||||||
containers := make([]*ContainerNode, len(enclosingContainers))
|
|
||||||
copy(containers, enclosingContainers)
|
|
||||||
containers = append(containers, node)
|
|
||||||
|
|
||||||
for _, subjectOrContainer := range node.subjectAndContainerNodes {
|
|
||||||
if subjectOrContainer.containerNode != nil {
|
|
||||||
collated = append(collated, subjectOrContainer.containerNode.collate(containers)...)
|
|
||||||
} else {
|
|
||||||
collated = append(collated, CollatedNodes{
|
|
||||||
Containers: containers,
|
|
||||||
Subject: subjectOrContainer.subjectNode,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return collated
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *ContainerNode) PushContainerNode(container *ContainerNode) {
|
|
||||||
node.subjectAndContainerNodes = append(node.subjectAndContainerNodes, subjectOrContainerNode{containerNode: container})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *ContainerNode) PushSubjectNode(subject leafnodes.SubjectNode) {
|
|
||||||
node.subjectAndContainerNodes = append(node.subjectAndContainerNodes, subjectOrContainerNode{subjectNode: subject})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *ContainerNode) PushSetupNode(setupNode leafnodes.BasicNode) {
|
|
||||||
node.setupNodes = append(node.setupNodes, setupNode)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *ContainerNode) SetupNodesOfType(nodeType types.SpecComponentType) []leafnodes.BasicNode {
|
|
||||||
nodes := []leafnodes.BasicNode{}
|
|
||||||
for _, setupNode := range node.setupNodes {
|
|
||||||
if setupNode.Type() == nodeType {
|
|
||||||
nodes = append(nodes, setupNode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nodes
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *ContainerNode) Text() string {
|
|
||||||
return node.text
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *ContainerNode) CodeLocation() types.CodeLocation {
|
|
||||||
return node.codeLocation
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *ContainerNode) Flag() types.FlagType {
|
|
||||||
return node.flag
|
|
||||||
}
|
|
||||||
|
|
||||||
//sort.Interface
|
|
||||||
|
|
||||||
func (node *ContainerNode) Len() int {
|
|
||||||
return len(node.subjectAndContainerNodes)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *ContainerNode) Less(i, j int) bool {
|
|
||||||
return node.subjectAndContainerNodes[i].text() < node.subjectAndContainerNodes[j].text()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *ContainerNode) Swap(i, j int) {
|
|
||||||
node.subjectAndContainerNodes[i], node.subjectAndContainerNodes[j] = node.subjectAndContainerNodes[j], node.subjectAndContainerNodes[i]
|
|
||||||
}
|
|
92
vendor/github.com/onsi/ginkgo/internal/failer/failer.go
generated
vendored
92
vendor/github.com/onsi/ginkgo/internal/failer/failer.go
generated
vendored
|
@ -1,92 +0,0 @@
|
||||||
package failer
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Failer struct {
|
|
||||||
lock *sync.Mutex
|
|
||||||
failure types.SpecFailure
|
|
||||||
state types.SpecState
|
|
||||||
}
|
|
||||||
|
|
||||||
func New() *Failer {
|
|
||||||
return &Failer{
|
|
||||||
lock: &sync.Mutex{},
|
|
||||||
state: types.SpecStatePassed,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Failer) Panic(location types.CodeLocation, forwardedPanic interface{}) {
|
|
||||||
f.lock.Lock()
|
|
||||||
defer f.lock.Unlock()
|
|
||||||
|
|
||||||
if f.state == types.SpecStatePassed {
|
|
||||||
f.state = types.SpecStatePanicked
|
|
||||||
f.failure = types.SpecFailure{
|
|
||||||
Message: "Test Panicked",
|
|
||||||
Location: location,
|
|
||||||
ForwardedPanic: fmt.Sprintf("%v", forwardedPanic),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Failer) Timeout(location types.CodeLocation) {
|
|
||||||
f.lock.Lock()
|
|
||||||
defer f.lock.Unlock()
|
|
||||||
|
|
||||||
if f.state == types.SpecStatePassed {
|
|
||||||
f.state = types.SpecStateTimedOut
|
|
||||||
f.failure = types.SpecFailure{
|
|
||||||
Message: "Timed out",
|
|
||||||
Location: location,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Failer) Fail(message string, location types.CodeLocation) {
|
|
||||||
f.lock.Lock()
|
|
||||||
defer f.lock.Unlock()
|
|
||||||
|
|
||||||
if f.state == types.SpecStatePassed {
|
|
||||||
f.state = types.SpecStateFailed
|
|
||||||
f.failure = types.SpecFailure{
|
|
||||||
Message: message,
|
|
||||||
Location: location,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Failer) Drain(componentType types.SpecComponentType, componentIndex int, componentCodeLocation types.CodeLocation) (types.SpecFailure, types.SpecState) {
|
|
||||||
f.lock.Lock()
|
|
||||||
defer f.lock.Unlock()
|
|
||||||
|
|
||||||
failure := f.failure
|
|
||||||
outcome := f.state
|
|
||||||
if outcome != types.SpecStatePassed {
|
|
||||||
failure.ComponentType = componentType
|
|
||||||
failure.ComponentIndex = componentIndex
|
|
||||||
failure.ComponentCodeLocation = componentCodeLocation
|
|
||||||
}
|
|
||||||
|
|
||||||
f.state = types.SpecStatePassed
|
|
||||||
f.failure = types.SpecFailure{}
|
|
||||||
|
|
||||||
return failure, outcome
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Failer) Skip(message string, location types.CodeLocation) {
|
|
||||||
f.lock.Lock()
|
|
||||||
defer f.lock.Unlock()
|
|
||||||
|
|
||||||
if f.state == types.SpecStatePassed {
|
|
||||||
f.state = types.SpecStateSkipped
|
|
||||||
f.failure = types.SpecFailure{
|
|
||||||
Message: message,
|
|
||||||
Location: location,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
103
vendor/github.com/onsi/ginkgo/internal/leafnodes/benchmarker.go
generated
vendored
103
vendor/github.com/onsi/ginkgo/internal/leafnodes/benchmarker.go
generated
vendored
|
@ -1,103 +0,0 @@
|
||||||
package leafnodes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type benchmarker struct {
|
|
||||||
mu sync.Mutex
|
|
||||||
measurements map[string]*types.SpecMeasurement
|
|
||||||
orderCounter int
|
|
||||||
}
|
|
||||||
|
|
||||||
func newBenchmarker() *benchmarker {
|
|
||||||
return &benchmarker{
|
|
||||||
measurements: make(map[string]*types.SpecMeasurement, 0),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *benchmarker) Time(name string, body func(), info ...interface{}) (elapsedTime time.Duration) {
|
|
||||||
t := time.Now()
|
|
||||||
body()
|
|
||||||
elapsedTime = time.Since(t)
|
|
||||||
|
|
||||||
b.mu.Lock()
|
|
||||||
defer b.mu.Unlock()
|
|
||||||
measurement := b.getMeasurement(name, "Fastest Time", "Slowest Time", "Average Time", "s", 3, info...)
|
|
||||||
measurement.Results = append(measurement.Results, elapsedTime.Seconds())
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *benchmarker) RecordValue(name string, value float64, info ...interface{}) {
|
|
||||||
b.mu.Lock()
|
|
||||||
measurement := b.getMeasurement(name, "Smallest", " Largest", " Average", "", 3, info...)
|
|
||||||
defer b.mu.Unlock()
|
|
||||||
measurement.Results = append(measurement.Results, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *benchmarker) RecordValueWithPrecision(name string, value float64, units string, precision int, info ...interface{}) {
|
|
||||||
b.mu.Lock()
|
|
||||||
measurement := b.getMeasurement(name, "Smallest", " Largest", " Average", units, precision, info...)
|
|
||||||
defer b.mu.Unlock()
|
|
||||||
measurement.Results = append(measurement.Results, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *benchmarker) getMeasurement(name string, smallestLabel string, largestLabel string, averageLabel string, units string, precision int, info ...interface{}) *types.SpecMeasurement {
|
|
||||||
measurement, ok := b.measurements[name]
|
|
||||||
if !ok {
|
|
||||||
var computedInfo interface{}
|
|
||||||
computedInfo = nil
|
|
||||||
if len(info) > 0 {
|
|
||||||
computedInfo = info[0]
|
|
||||||
}
|
|
||||||
measurement = &types.SpecMeasurement{
|
|
||||||
Name: name,
|
|
||||||
Info: computedInfo,
|
|
||||||
Order: b.orderCounter,
|
|
||||||
SmallestLabel: smallestLabel,
|
|
||||||
LargestLabel: largestLabel,
|
|
||||||
AverageLabel: averageLabel,
|
|
||||||
Units: units,
|
|
||||||
Precision: precision,
|
|
||||||
Results: make([]float64, 0),
|
|
||||||
}
|
|
||||||
b.measurements[name] = measurement
|
|
||||||
b.orderCounter++
|
|
||||||
}
|
|
||||||
|
|
||||||
return measurement
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *benchmarker) measurementsReport() map[string]*types.SpecMeasurement {
|
|
||||||
b.mu.Lock()
|
|
||||||
defer b.mu.Unlock()
|
|
||||||
for _, measurement := range b.measurements {
|
|
||||||
measurement.Smallest = math.MaxFloat64
|
|
||||||
measurement.Largest = -math.MaxFloat64
|
|
||||||
sum := float64(0)
|
|
||||||
sumOfSquares := float64(0)
|
|
||||||
|
|
||||||
for _, result := range measurement.Results {
|
|
||||||
if result > measurement.Largest {
|
|
||||||
measurement.Largest = result
|
|
||||||
}
|
|
||||||
if result < measurement.Smallest {
|
|
||||||
measurement.Smallest = result
|
|
||||||
}
|
|
||||||
sum += result
|
|
||||||
sumOfSquares += result * result
|
|
||||||
}
|
|
||||||
|
|
||||||
n := float64(len(measurement.Results))
|
|
||||||
measurement.Average = sum / n
|
|
||||||
measurement.StdDeviation = math.Sqrt(sumOfSquares/n - (sum/n)*(sum/n))
|
|
||||||
}
|
|
||||||
|
|
||||||
return b.measurements
|
|
||||||
}
|
|
19
vendor/github.com/onsi/ginkgo/internal/leafnodes/interfaces.go
generated
vendored
19
vendor/github.com/onsi/ginkgo/internal/leafnodes/interfaces.go
generated
vendored
|
@ -1,19 +0,0 @@
|
||||||
package leafnodes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type BasicNode interface {
|
|
||||||
Type() types.SpecComponentType
|
|
||||||
Run() (types.SpecState, types.SpecFailure)
|
|
||||||
CodeLocation() types.CodeLocation
|
|
||||||
}
|
|
||||||
|
|
||||||
type SubjectNode interface {
|
|
||||||
BasicNode
|
|
||||||
|
|
||||||
Text() string
|
|
||||||
Flag() types.FlagType
|
|
||||||
Samples() int
|
|
||||||
}
|
|
47
vendor/github.com/onsi/ginkgo/internal/leafnodes/it_node.go
generated
vendored
47
vendor/github.com/onsi/ginkgo/internal/leafnodes/it_node.go
generated
vendored
|
@ -1,47 +0,0 @@
|
||||||
package leafnodes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/internal/failer"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ItNode struct {
|
|
||||||
runner *runner
|
|
||||||
|
|
||||||
flag types.FlagType
|
|
||||||
text string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewItNode(text string, body interface{}, flag types.FlagType, codeLocation types.CodeLocation, timeout time.Duration, failer *failer.Failer, componentIndex int) *ItNode {
|
|
||||||
return &ItNode{
|
|
||||||
runner: newRunner(body, codeLocation, timeout, failer, types.SpecComponentTypeIt, componentIndex),
|
|
||||||
flag: flag,
|
|
||||||
text: text,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *ItNode) Run() (outcome types.SpecState, failure types.SpecFailure) {
|
|
||||||
return node.runner.run()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *ItNode) Type() types.SpecComponentType {
|
|
||||||
return types.SpecComponentTypeIt
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *ItNode) Text() string {
|
|
||||||
return node.text
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *ItNode) Flag() types.FlagType {
|
|
||||||
return node.flag
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *ItNode) CodeLocation() types.CodeLocation {
|
|
||||||
return node.runner.codeLocation
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *ItNode) Samples() int {
|
|
||||||
return 1
|
|
||||||
}
|
|
62
vendor/github.com/onsi/ginkgo/internal/leafnodes/measure_node.go
generated
vendored
62
vendor/github.com/onsi/ginkgo/internal/leafnodes/measure_node.go
generated
vendored
|
@ -1,62 +0,0 @@
|
||||||
package leafnodes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/internal/failer"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type MeasureNode struct {
|
|
||||||
runner *runner
|
|
||||||
|
|
||||||
text string
|
|
||||||
flag types.FlagType
|
|
||||||
samples int
|
|
||||||
benchmarker *benchmarker
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewMeasureNode(text string, body interface{}, flag types.FlagType, codeLocation types.CodeLocation, samples int, failer *failer.Failer, componentIndex int) *MeasureNode {
|
|
||||||
benchmarker := newBenchmarker()
|
|
||||||
|
|
||||||
wrappedBody := func() {
|
|
||||||
reflect.ValueOf(body).Call([]reflect.Value{reflect.ValueOf(benchmarker)})
|
|
||||||
}
|
|
||||||
|
|
||||||
return &MeasureNode{
|
|
||||||
runner: newRunner(wrappedBody, codeLocation, 0, failer, types.SpecComponentTypeMeasure, componentIndex),
|
|
||||||
|
|
||||||
text: text,
|
|
||||||
flag: flag,
|
|
||||||
samples: samples,
|
|
||||||
benchmarker: benchmarker,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *MeasureNode) Run() (outcome types.SpecState, failure types.SpecFailure) {
|
|
||||||
return node.runner.run()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *MeasureNode) MeasurementsReport() map[string]*types.SpecMeasurement {
|
|
||||||
return node.benchmarker.measurementsReport()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *MeasureNode) Type() types.SpecComponentType {
|
|
||||||
return types.SpecComponentTypeMeasure
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *MeasureNode) Text() string {
|
|
||||||
return node.text
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *MeasureNode) Flag() types.FlagType {
|
|
||||||
return node.flag
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *MeasureNode) CodeLocation() types.CodeLocation {
|
|
||||||
return node.runner.codeLocation
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *MeasureNode) Samples() int {
|
|
||||||
return node.samples
|
|
||||||
}
|
|
117
vendor/github.com/onsi/ginkgo/internal/leafnodes/runner.go
generated
vendored
117
vendor/github.com/onsi/ginkgo/internal/leafnodes/runner.go
generated
vendored
|
@ -1,117 +0,0 @@
|
||||||
package leafnodes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/internal/codelocation"
|
|
||||||
"github.com/onsi/ginkgo/internal/failer"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type runner struct {
|
|
||||||
isAsync bool
|
|
||||||
asyncFunc func(chan<- interface{})
|
|
||||||
syncFunc func()
|
|
||||||
codeLocation types.CodeLocation
|
|
||||||
timeoutThreshold time.Duration
|
|
||||||
nodeType types.SpecComponentType
|
|
||||||
componentIndex int
|
|
||||||
failer *failer.Failer
|
|
||||||
}
|
|
||||||
|
|
||||||
func newRunner(body interface{}, codeLocation types.CodeLocation, timeout time.Duration, failer *failer.Failer, nodeType types.SpecComponentType, componentIndex int) *runner {
|
|
||||||
bodyType := reflect.TypeOf(body)
|
|
||||||
if bodyType.Kind() != reflect.Func {
|
|
||||||
panic(fmt.Sprintf("Expected a function but got something else at %v", codeLocation))
|
|
||||||
}
|
|
||||||
|
|
||||||
runner := &runner{
|
|
||||||
codeLocation: codeLocation,
|
|
||||||
timeoutThreshold: timeout,
|
|
||||||
failer: failer,
|
|
||||||
nodeType: nodeType,
|
|
||||||
componentIndex: componentIndex,
|
|
||||||
}
|
|
||||||
|
|
||||||
switch bodyType.NumIn() {
|
|
||||||
case 0:
|
|
||||||
runner.syncFunc = body.(func())
|
|
||||||
return runner
|
|
||||||
case 1:
|
|
||||||
if !(bodyType.In(0).Kind() == reflect.Chan && bodyType.In(0).Elem().Kind() == reflect.Interface) {
|
|
||||||
panic(fmt.Sprintf("Must pass a Done channel to function at %v", codeLocation))
|
|
||||||
}
|
|
||||||
|
|
||||||
wrappedBody := func(done chan<- interface{}) {
|
|
||||||
bodyValue := reflect.ValueOf(body)
|
|
||||||
bodyValue.Call([]reflect.Value{reflect.ValueOf(done)})
|
|
||||||
}
|
|
||||||
|
|
||||||
runner.isAsync = true
|
|
||||||
runner.asyncFunc = wrappedBody
|
|
||||||
return runner
|
|
||||||
}
|
|
||||||
|
|
||||||
panic(fmt.Sprintf("Too many arguments to function at %v", codeLocation))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *runner) run() (outcome types.SpecState, failure types.SpecFailure) {
|
|
||||||
if r.isAsync {
|
|
||||||
return r.runAsync()
|
|
||||||
} else {
|
|
||||||
return r.runSync()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *runner) runAsync() (outcome types.SpecState, failure types.SpecFailure) {
|
|
||||||
done := make(chan interface{}, 1)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
finished := false
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
if e := recover(); e != nil || !finished {
|
|
||||||
r.failer.Panic(codelocation.New(2), e)
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
close(done)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
r.asyncFunc(done)
|
|
||||||
finished = true
|
|
||||||
}()
|
|
||||||
|
|
||||||
// If this goroutine gets no CPU time before the select block,
|
|
||||||
// the <-done case may complete even if the test took longer than the timeoutThreshold.
|
|
||||||
// This can cause flaky behaviour, but we haven't seen it in the wild.
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-time.After(r.timeoutThreshold):
|
|
||||||
r.failer.Timeout(r.codeLocation)
|
|
||||||
}
|
|
||||||
|
|
||||||
failure, outcome = r.failer.Drain(r.nodeType, r.componentIndex, r.codeLocation)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
func (r *runner) runSync() (outcome types.SpecState, failure types.SpecFailure) {
|
|
||||||
finished := false
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
if e := recover(); e != nil || !finished {
|
|
||||||
r.failer.Panic(codelocation.New(2), e)
|
|
||||||
}
|
|
||||||
|
|
||||||
failure, outcome = r.failer.Drain(r.nodeType, r.componentIndex, r.codeLocation)
|
|
||||||
}()
|
|
||||||
|
|
||||||
r.syncFunc()
|
|
||||||
finished = true
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
42
vendor/github.com/onsi/ginkgo/internal/leafnodes/setup_nodes.go
generated
vendored
42
vendor/github.com/onsi/ginkgo/internal/leafnodes/setup_nodes.go
generated
vendored
|
@ -1,42 +0,0 @@
|
||||||
package leafnodes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/internal/failer"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type SetupNode struct {
|
|
||||||
runner *runner
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *SetupNode) Run() (outcome types.SpecState, failure types.SpecFailure) {
|
|
||||||
return node.runner.run()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *SetupNode) Type() types.SpecComponentType {
|
|
||||||
return node.runner.nodeType
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *SetupNode) CodeLocation() types.CodeLocation {
|
|
||||||
return node.runner.codeLocation
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewBeforeEachNode(body interface{}, codeLocation types.CodeLocation, timeout time.Duration, failer *failer.Failer, componentIndex int) *SetupNode {
|
|
||||||
return &SetupNode{
|
|
||||||
runner: newRunner(body, codeLocation, timeout, failer, types.SpecComponentTypeBeforeEach, componentIndex),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewAfterEachNode(body interface{}, codeLocation types.CodeLocation, timeout time.Duration, failer *failer.Failer, componentIndex int) *SetupNode {
|
|
||||||
return &SetupNode{
|
|
||||||
runner: newRunner(body, codeLocation, timeout, failer, types.SpecComponentTypeAfterEach, componentIndex),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewJustBeforeEachNode(body interface{}, codeLocation types.CodeLocation, timeout time.Duration, failer *failer.Failer, componentIndex int) *SetupNode {
|
|
||||||
return &SetupNode{
|
|
||||||
runner: newRunner(body, codeLocation, timeout, failer, types.SpecComponentTypeJustBeforeEach, componentIndex),
|
|
||||||
}
|
|
||||||
}
|
|
55
vendor/github.com/onsi/ginkgo/internal/leafnodes/suite_nodes.go
generated
vendored
55
vendor/github.com/onsi/ginkgo/internal/leafnodes/suite_nodes.go
generated
vendored
|
@ -1,55 +0,0 @@
|
||||||
package leafnodes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/internal/failer"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type SuiteNode interface {
|
|
||||||
Run(parallelNode int, parallelTotal int, syncHost string) bool
|
|
||||||
Passed() bool
|
|
||||||
Summary() *types.SetupSummary
|
|
||||||
}
|
|
||||||
|
|
||||||
type simpleSuiteNode struct {
|
|
||||||
runner *runner
|
|
||||||
outcome types.SpecState
|
|
||||||
failure types.SpecFailure
|
|
||||||
runTime time.Duration
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *simpleSuiteNode) Run(parallelNode int, parallelTotal int, syncHost string) bool {
|
|
||||||
t := time.Now()
|
|
||||||
node.outcome, node.failure = node.runner.run()
|
|
||||||
node.runTime = time.Since(t)
|
|
||||||
|
|
||||||
return node.outcome == types.SpecStatePassed
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *simpleSuiteNode) Passed() bool {
|
|
||||||
return node.outcome == types.SpecStatePassed
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *simpleSuiteNode) Summary() *types.SetupSummary {
|
|
||||||
return &types.SetupSummary{
|
|
||||||
ComponentType: node.runner.nodeType,
|
|
||||||
CodeLocation: node.runner.codeLocation,
|
|
||||||
State: node.outcome,
|
|
||||||
RunTime: node.runTime,
|
|
||||||
Failure: node.failure,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewBeforeSuiteNode(body interface{}, codeLocation types.CodeLocation, timeout time.Duration, failer *failer.Failer) SuiteNode {
|
|
||||||
return &simpleSuiteNode{
|
|
||||||
runner: newRunner(body, codeLocation, timeout, failer, types.SpecComponentTypeBeforeSuite, 0),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewAfterSuiteNode(body interface{}, codeLocation types.CodeLocation, timeout time.Duration, failer *failer.Failer) SuiteNode {
|
|
||||||
return &simpleSuiteNode{
|
|
||||||
runner: newRunner(body, codeLocation, timeout, failer, types.SpecComponentTypeAfterSuite, 0),
|
|
||||||
}
|
|
||||||
}
|
|
90
vendor/github.com/onsi/ginkgo/internal/leafnodes/synchronized_after_suite_node.go
generated
vendored
90
vendor/github.com/onsi/ginkgo/internal/leafnodes/synchronized_after_suite_node.go
generated
vendored
|
@ -1,90 +0,0 @@
|
||||||
package leafnodes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/internal/failer"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type synchronizedAfterSuiteNode struct {
|
|
||||||
runnerA *runner
|
|
||||||
runnerB *runner
|
|
||||||
|
|
||||||
outcome types.SpecState
|
|
||||||
failure types.SpecFailure
|
|
||||||
runTime time.Duration
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSynchronizedAfterSuiteNode(bodyA interface{}, bodyB interface{}, codeLocation types.CodeLocation, timeout time.Duration, failer *failer.Failer) SuiteNode {
|
|
||||||
return &synchronizedAfterSuiteNode{
|
|
||||||
runnerA: newRunner(bodyA, codeLocation, timeout, failer, types.SpecComponentTypeAfterSuite, 0),
|
|
||||||
runnerB: newRunner(bodyB, codeLocation, timeout, failer, types.SpecComponentTypeAfterSuite, 0),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *synchronizedAfterSuiteNode) Run(parallelNode int, parallelTotal int, syncHost string) bool {
|
|
||||||
node.outcome, node.failure = node.runnerA.run()
|
|
||||||
|
|
||||||
if parallelNode == 1 {
|
|
||||||
if parallelTotal > 1 {
|
|
||||||
node.waitUntilOtherNodesAreDone(syncHost)
|
|
||||||
}
|
|
||||||
|
|
||||||
outcome, failure := node.runnerB.run()
|
|
||||||
|
|
||||||
if node.outcome == types.SpecStatePassed {
|
|
||||||
node.outcome, node.failure = outcome, failure
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return node.outcome == types.SpecStatePassed
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *synchronizedAfterSuiteNode) Passed() bool {
|
|
||||||
return node.outcome == types.SpecStatePassed
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *synchronizedAfterSuiteNode) Summary() *types.SetupSummary {
|
|
||||||
return &types.SetupSummary{
|
|
||||||
ComponentType: node.runnerA.nodeType,
|
|
||||||
CodeLocation: node.runnerA.codeLocation,
|
|
||||||
State: node.outcome,
|
|
||||||
RunTime: node.runTime,
|
|
||||||
Failure: node.failure,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *synchronizedAfterSuiteNode) waitUntilOtherNodesAreDone(syncHost string) {
|
|
||||||
for {
|
|
||||||
if node.canRun(syncHost) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(50 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *synchronizedAfterSuiteNode) canRun(syncHost string) bool {
|
|
||||||
resp, err := http.Get(syncHost + "/RemoteAfterSuiteData")
|
|
||||||
if err != nil || resp.StatusCode != http.StatusOK {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
resp.Body.Close()
|
|
||||||
|
|
||||||
afterSuiteData := types.RemoteAfterSuiteData{}
|
|
||||||
err = json.Unmarshal(body, &afterSuiteData)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return afterSuiteData.CanRun
|
|
||||||
}
|
|
181
vendor/github.com/onsi/ginkgo/internal/leafnodes/synchronized_before_suite_node.go
generated
vendored
181
vendor/github.com/onsi/ginkgo/internal/leafnodes/synchronized_before_suite_node.go
generated
vendored
|
@ -1,181 +0,0 @@
|
||||||
package leafnodes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"reflect"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/internal/failer"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type synchronizedBeforeSuiteNode struct {
|
|
||||||
runnerA *runner
|
|
||||||
runnerB *runner
|
|
||||||
|
|
||||||
data []byte
|
|
||||||
|
|
||||||
outcome types.SpecState
|
|
||||||
failure types.SpecFailure
|
|
||||||
runTime time.Duration
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSynchronizedBeforeSuiteNode(bodyA interface{}, bodyB interface{}, codeLocation types.CodeLocation, timeout time.Duration, failer *failer.Failer) SuiteNode {
|
|
||||||
node := &synchronizedBeforeSuiteNode{}
|
|
||||||
|
|
||||||
node.runnerA = newRunner(node.wrapA(bodyA), codeLocation, timeout, failer, types.SpecComponentTypeBeforeSuite, 0)
|
|
||||||
node.runnerB = newRunner(node.wrapB(bodyB), codeLocation, timeout, failer, types.SpecComponentTypeBeforeSuite, 0)
|
|
||||||
|
|
||||||
return node
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *synchronizedBeforeSuiteNode) Run(parallelNode int, parallelTotal int, syncHost string) bool {
|
|
||||||
t := time.Now()
|
|
||||||
defer func() {
|
|
||||||
node.runTime = time.Since(t)
|
|
||||||
}()
|
|
||||||
|
|
||||||
if parallelNode == 1 {
|
|
||||||
node.outcome, node.failure = node.runA(parallelTotal, syncHost)
|
|
||||||
} else {
|
|
||||||
node.outcome, node.failure = node.waitForA(syncHost)
|
|
||||||
}
|
|
||||||
|
|
||||||
if node.outcome != types.SpecStatePassed {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
node.outcome, node.failure = node.runnerB.run()
|
|
||||||
|
|
||||||
return node.outcome == types.SpecStatePassed
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *synchronizedBeforeSuiteNode) runA(parallelTotal int, syncHost string) (types.SpecState, types.SpecFailure) {
|
|
||||||
outcome, failure := node.runnerA.run()
|
|
||||||
|
|
||||||
if parallelTotal > 1 {
|
|
||||||
state := types.RemoteBeforeSuiteStatePassed
|
|
||||||
if outcome != types.SpecStatePassed {
|
|
||||||
state = types.RemoteBeforeSuiteStateFailed
|
|
||||||
}
|
|
||||||
json := (types.RemoteBeforeSuiteData{
|
|
||||||
Data: node.data,
|
|
||||||
State: state,
|
|
||||||
}).ToJSON()
|
|
||||||
http.Post(syncHost+"/BeforeSuiteState", "application/json", bytes.NewBuffer(json))
|
|
||||||
}
|
|
||||||
|
|
||||||
return outcome, failure
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *synchronizedBeforeSuiteNode) waitForA(syncHost string) (types.SpecState, types.SpecFailure) {
|
|
||||||
failure := func(message string) types.SpecFailure {
|
|
||||||
return types.SpecFailure{
|
|
||||||
Message: message,
|
|
||||||
Location: node.runnerA.codeLocation,
|
|
||||||
ComponentType: node.runnerA.nodeType,
|
|
||||||
ComponentIndex: node.runnerA.componentIndex,
|
|
||||||
ComponentCodeLocation: node.runnerA.codeLocation,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for {
|
|
||||||
resp, err := http.Get(syncHost + "/BeforeSuiteState")
|
|
||||||
if err != nil || resp.StatusCode != http.StatusOK {
|
|
||||||
return types.SpecStateFailed, failure("Failed to fetch BeforeSuite state")
|
|
||||||
}
|
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return types.SpecStateFailed, failure("Failed to read BeforeSuite state")
|
|
||||||
}
|
|
||||||
resp.Body.Close()
|
|
||||||
|
|
||||||
beforeSuiteData := types.RemoteBeforeSuiteData{}
|
|
||||||
err = json.Unmarshal(body, &beforeSuiteData)
|
|
||||||
if err != nil {
|
|
||||||
return types.SpecStateFailed, failure("Failed to decode BeforeSuite state")
|
|
||||||
}
|
|
||||||
|
|
||||||
switch beforeSuiteData.State {
|
|
||||||
case types.RemoteBeforeSuiteStatePassed:
|
|
||||||
node.data = beforeSuiteData.Data
|
|
||||||
return types.SpecStatePassed, types.SpecFailure{}
|
|
||||||
case types.RemoteBeforeSuiteStateFailed:
|
|
||||||
return types.SpecStateFailed, failure("BeforeSuite on Node 1 failed")
|
|
||||||
case types.RemoteBeforeSuiteStateDisappeared:
|
|
||||||
return types.SpecStateFailed, failure("Node 1 disappeared before completing BeforeSuite")
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(50 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *synchronizedBeforeSuiteNode) Passed() bool {
|
|
||||||
return node.outcome == types.SpecStatePassed
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *synchronizedBeforeSuiteNode) Summary() *types.SetupSummary {
|
|
||||||
return &types.SetupSummary{
|
|
||||||
ComponentType: node.runnerA.nodeType,
|
|
||||||
CodeLocation: node.runnerA.codeLocation,
|
|
||||||
State: node.outcome,
|
|
||||||
RunTime: node.runTime,
|
|
||||||
Failure: node.failure,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *synchronizedBeforeSuiteNode) wrapA(bodyA interface{}) interface{} {
|
|
||||||
typeA := reflect.TypeOf(bodyA)
|
|
||||||
if typeA.Kind() != reflect.Func {
|
|
||||||
panic("SynchronizedBeforeSuite expects a function as its first argument")
|
|
||||||
}
|
|
||||||
|
|
||||||
takesNothing := typeA.NumIn() == 0
|
|
||||||
takesADoneChannel := typeA.NumIn() == 1 && typeA.In(0).Kind() == reflect.Chan && typeA.In(0).Elem().Kind() == reflect.Interface
|
|
||||||
returnsBytes := typeA.NumOut() == 1 && typeA.Out(0).Kind() == reflect.Slice && typeA.Out(0).Elem().Kind() == reflect.Uint8
|
|
||||||
|
|
||||||
if !((takesNothing || takesADoneChannel) && returnsBytes) {
|
|
||||||
panic("SynchronizedBeforeSuite's first argument should be a function that returns []byte and either takes no arguments or takes a Done channel.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if takesADoneChannel {
|
|
||||||
return func(done chan<- interface{}) {
|
|
||||||
out := reflect.ValueOf(bodyA).Call([]reflect.Value{reflect.ValueOf(done)})
|
|
||||||
node.data = out[0].Interface().([]byte)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return func() {
|
|
||||||
out := reflect.ValueOf(bodyA).Call([]reflect.Value{})
|
|
||||||
node.data = out[0].Interface().([]byte)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (node *synchronizedBeforeSuiteNode) wrapB(bodyB interface{}) interface{} {
|
|
||||||
typeB := reflect.TypeOf(bodyB)
|
|
||||||
if typeB.Kind() != reflect.Func {
|
|
||||||
panic("SynchronizedBeforeSuite expects a function as its second argument")
|
|
||||||
}
|
|
||||||
|
|
||||||
returnsNothing := typeB.NumOut() == 0
|
|
||||||
takesBytesOnly := typeB.NumIn() == 1 && typeB.In(0).Kind() == reflect.Slice && typeB.In(0).Elem().Kind() == reflect.Uint8
|
|
||||||
takesBytesAndDone := typeB.NumIn() == 2 &&
|
|
||||||
typeB.In(0).Kind() == reflect.Slice && typeB.In(0).Elem().Kind() == reflect.Uint8 &&
|
|
||||||
typeB.In(1).Kind() == reflect.Chan && typeB.In(1).Elem().Kind() == reflect.Interface
|
|
||||||
|
|
||||||
if !((takesBytesOnly || takesBytesAndDone) && returnsNothing) {
|
|
||||||
panic("SynchronizedBeforeSuite's second argument should be a function that returns nothing and either takes []byte or ([]byte, Done)")
|
|
||||||
}
|
|
||||||
|
|
||||||
if takesBytesAndDone {
|
|
||||||
return func(done chan<- interface{}) {
|
|
||||||
reflect.ValueOf(bodyB).Call([]reflect.Value{reflect.ValueOf(node.data), reflect.ValueOf(done)})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return func() {
|
|
||||||
reflect.ValueOf(bodyB).Call([]reflect.Value{reflect.ValueOf(node.data)})
|
|
||||||
}
|
|
||||||
}
|
|
249
vendor/github.com/onsi/ginkgo/internal/remote/aggregator.go
generated
vendored
249
vendor/github.com/onsi/ginkgo/internal/remote/aggregator.go
generated
vendored
|
@ -1,249 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
Aggregator is a reporter used by the Ginkgo CLI to aggregate and present parallel test output
|
|
||||||
coherently as tests complete. You shouldn't need to use this in your code. To run tests in parallel:
|
|
||||||
|
|
||||||
ginkgo -nodes=N
|
|
||||||
|
|
||||||
where N is the number of nodes you desire.
|
|
||||||
*/
|
|
||||||
package remote
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/config"
|
|
||||||
"github.com/onsi/ginkgo/reporters/stenographer"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type configAndSuite struct {
|
|
||||||
config config.GinkgoConfigType
|
|
||||||
summary *types.SuiteSummary
|
|
||||||
}
|
|
||||||
|
|
||||||
type Aggregator struct {
|
|
||||||
nodeCount int
|
|
||||||
config config.DefaultReporterConfigType
|
|
||||||
stenographer stenographer.Stenographer
|
|
||||||
result chan bool
|
|
||||||
|
|
||||||
suiteBeginnings chan configAndSuite
|
|
||||||
aggregatedSuiteBeginnings []configAndSuite
|
|
||||||
|
|
||||||
beforeSuites chan *types.SetupSummary
|
|
||||||
aggregatedBeforeSuites []*types.SetupSummary
|
|
||||||
|
|
||||||
afterSuites chan *types.SetupSummary
|
|
||||||
aggregatedAfterSuites []*types.SetupSummary
|
|
||||||
|
|
||||||
specCompletions chan *types.SpecSummary
|
|
||||||
completedSpecs []*types.SpecSummary
|
|
||||||
|
|
||||||
suiteEndings chan *types.SuiteSummary
|
|
||||||
aggregatedSuiteEndings []*types.SuiteSummary
|
|
||||||
specs []*types.SpecSummary
|
|
||||||
|
|
||||||
startTime time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewAggregator(nodeCount int, result chan bool, config config.DefaultReporterConfigType, stenographer stenographer.Stenographer) *Aggregator {
|
|
||||||
aggregator := &Aggregator{
|
|
||||||
nodeCount: nodeCount,
|
|
||||||
result: result,
|
|
||||||
config: config,
|
|
||||||
stenographer: stenographer,
|
|
||||||
|
|
||||||
suiteBeginnings: make(chan configAndSuite, 0),
|
|
||||||
beforeSuites: make(chan *types.SetupSummary, 0),
|
|
||||||
afterSuites: make(chan *types.SetupSummary, 0),
|
|
||||||
specCompletions: make(chan *types.SpecSummary, 0),
|
|
||||||
suiteEndings: make(chan *types.SuiteSummary, 0),
|
|
||||||
}
|
|
||||||
|
|
||||||
go aggregator.mux()
|
|
||||||
|
|
||||||
return aggregator
|
|
||||||
}
|
|
||||||
|
|
||||||
func (aggregator *Aggregator) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) {
|
|
||||||
aggregator.suiteBeginnings <- configAndSuite{config, summary}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (aggregator *Aggregator) BeforeSuiteDidRun(setupSummary *types.SetupSummary) {
|
|
||||||
aggregator.beforeSuites <- setupSummary
|
|
||||||
}
|
|
||||||
|
|
||||||
func (aggregator *Aggregator) AfterSuiteDidRun(setupSummary *types.SetupSummary) {
|
|
||||||
aggregator.afterSuites <- setupSummary
|
|
||||||
}
|
|
||||||
|
|
||||||
func (aggregator *Aggregator) SpecWillRun(specSummary *types.SpecSummary) {
|
|
||||||
//noop
|
|
||||||
}
|
|
||||||
|
|
||||||
func (aggregator *Aggregator) SpecDidComplete(specSummary *types.SpecSummary) {
|
|
||||||
aggregator.specCompletions <- specSummary
|
|
||||||
}
|
|
||||||
|
|
||||||
func (aggregator *Aggregator) SpecSuiteDidEnd(summary *types.SuiteSummary) {
|
|
||||||
aggregator.suiteEndings <- summary
|
|
||||||
}
|
|
||||||
|
|
||||||
func (aggregator *Aggregator) mux() {
|
|
||||||
loop:
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case configAndSuite := <-aggregator.suiteBeginnings:
|
|
||||||
aggregator.registerSuiteBeginning(configAndSuite)
|
|
||||||
case setupSummary := <-aggregator.beforeSuites:
|
|
||||||
aggregator.registerBeforeSuite(setupSummary)
|
|
||||||
case setupSummary := <-aggregator.afterSuites:
|
|
||||||
aggregator.registerAfterSuite(setupSummary)
|
|
||||||
case specSummary := <-aggregator.specCompletions:
|
|
||||||
aggregator.registerSpecCompletion(specSummary)
|
|
||||||
case suite := <-aggregator.suiteEndings:
|
|
||||||
finished, passed := aggregator.registerSuiteEnding(suite)
|
|
||||||
if finished {
|
|
||||||
aggregator.result <- passed
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (aggregator *Aggregator) registerSuiteBeginning(configAndSuite configAndSuite) {
|
|
||||||
aggregator.aggregatedSuiteBeginnings = append(aggregator.aggregatedSuiteBeginnings, configAndSuite)
|
|
||||||
|
|
||||||
if len(aggregator.aggregatedSuiteBeginnings) == 1 {
|
|
||||||
aggregator.startTime = time.Now()
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(aggregator.aggregatedSuiteBeginnings) != aggregator.nodeCount {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
aggregator.stenographer.AnnounceSuite(configAndSuite.summary.SuiteDescription, configAndSuite.config.RandomSeed, configAndSuite.config.RandomizeAllSpecs, aggregator.config.Succinct)
|
|
||||||
|
|
||||||
totalNumberOfSpecs := 0
|
|
||||||
if len(aggregator.aggregatedSuiteBeginnings) > 0 {
|
|
||||||
totalNumberOfSpecs = configAndSuite.summary.NumberOfSpecsBeforeParallelization
|
|
||||||
}
|
|
||||||
|
|
||||||
aggregator.stenographer.AnnounceTotalNumberOfSpecs(totalNumberOfSpecs, aggregator.config.Succinct)
|
|
||||||
aggregator.stenographer.AnnounceAggregatedParallelRun(aggregator.nodeCount, aggregator.config.Succinct)
|
|
||||||
aggregator.flushCompletedSpecs()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (aggregator *Aggregator) registerBeforeSuite(setupSummary *types.SetupSummary) {
|
|
||||||
aggregator.aggregatedBeforeSuites = append(aggregator.aggregatedBeforeSuites, setupSummary)
|
|
||||||
aggregator.flushCompletedSpecs()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (aggregator *Aggregator) registerAfterSuite(setupSummary *types.SetupSummary) {
|
|
||||||
aggregator.aggregatedAfterSuites = append(aggregator.aggregatedAfterSuites, setupSummary)
|
|
||||||
aggregator.flushCompletedSpecs()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (aggregator *Aggregator) registerSpecCompletion(specSummary *types.SpecSummary) {
|
|
||||||
aggregator.completedSpecs = append(aggregator.completedSpecs, specSummary)
|
|
||||||
aggregator.specs = append(aggregator.specs, specSummary)
|
|
||||||
aggregator.flushCompletedSpecs()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (aggregator *Aggregator) flushCompletedSpecs() {
|
|
||||||
if len(aggregator.aggregatedSuiteBeginnings) != aggregator.nodeCount {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, setupSummary := range aggregator.aggregatedBeforeSuites {
|
|
||||||
aggregator.announceBeforeSuite(setupSummary)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, specSummary := range aggregator.completedSpecs {
|
|
||||||
aggregator.announceSpec(specSummary)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, setupSummary := range aggregator.aggregatedAfterSuites {
|
|
||||||
aggregator.announceAfterSuite(setupSummary)
|
|
||||||
}
|
|
||||||
|
|
||||||
aggregator.aggregatedBeforeSuites = []*types.SetupSummary{}
|
|
||||||
aggregator.completedSpecs = []*types.SpecSummary{}
|
|
||||||
aggregator.aggregatedAfterSuites = []*types.SetupSummary{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (aggregator *Aggregator) announceBeforeSuite(setupSummary *types.SetupSummary) {
|
|
||||||
aggregator.stenographer.AnnounceCapturedOutput(setupSummary.CapturedOutput)
|
|
||||||
if setupSummary.State != types.SpecStatePassed {
|
|
||||||
aggregator.stenographer.AnnounceBeforeSuiteFailure(setupSummary, aggregator.config.Succinct, aggregator.config.FullTrace)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (aggregator *Aggregator) announceAfterSuite(setupSummary *types.SetupSummary) {
|
|
||||||
aggregator.stenographer.AnnounceCapturedOutput(setupSummary.CapturedOutput)
|
|
||||||
if setupSummary.State != types.SpecStatePassed {
|
|
||||||
aggregator.stenographer.AnnounceAfterSuiteFailure(setupSummary, aggregator.config.Succinct, aggregator.config.FullTrace)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (aggregator *Aggregator) announceSpec(specSummary *types.SpecSummary) {
|
|
||||||
if aggregator.config.Verbose && specSummary.State != types.SpecStatePending && specSummary.State != types.SpecStateSkipped {
|
|
||||||
aggregator.stenographer.AnnounceSpecWillRun(specSummary)
|
|
||||||
}
|
|
||||||
|
|
||||||
aggregator.stenographer.AnnounceCapturedOutput(specSummary.CapturedOutput)
|
|
||||||
|
|
||||||
switch specSummary.State {
|
|
||||||
case types.SpecStatePassed:
|
|
||||||
if specSummary.IsMeasurement {
|
|
||||||
aggregator.stenographer.AnnounceSuccesfulMeasurement(specSummary, aggregator.config.Succinct)
|
|
||||||
} else if specSummary.RunTime.Seconds() >= aggregator.config.SlowSpecThreshold {
|
|
||||||
aggregator.stenographer.AnnounceSuccesfulSlowSpec(specSummary, aggregator.config.Succinct)
|
|
||||||
} else {
|
|
||||||
aggregator.stenographer.AnnounceSuccesfulSpec(specSummary)
|
|
||||||
}
|
|
||||||
|
|
||||||
case types.SpecStatePending:
|
|
||||||
aggregator.stenographer.AnnouncePendingSpec(specSummary, aggregator.config.NoisyPendings && !aggregator.config.Succinct)
|
|
||||||
case types.SpecStateSkipped:
|
|
||||||
aggregator.stenographer.AnnounceSkippedSpec(specSummary, aggregator.config.Succinct || !aggregator.config.NoisySkippings, aggregator.config.FullTrace)
|
|
||||||
case types.SpecStateTimedOut:
|
|
||||||
aggregator.stenographer.AnnounceSpecTimedOut(specSummary, aggregator.config.Succinct, aggregator.config.FullTrace)
|
|
||||||
case types.SpecStatePanicked:
|
|
||||||
aggregator.stenographer.AnnounceSpecPanicked(specSummary, aggregator.config.Succinct, aggregator.config.FullTrace)
|
|
||||||
case types.SpecStateFailed:
|
|
||||||
aggregator.stenographer.AnnounceSpecFailed(specSummary, aggregator.config.Succinct, aggregator.config.FullTrace)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (aggregator *Aggregator) registerSuiteEnding(suite *types.SuiteSummary) (finished bool, passed bool) {
|
|
||||||
aggregator.aggregatedSuiteEndings = append(aggregator.aggregatedSuiteEndings, suite)
|
|
||||||
if len(aggregator.aggregatedSuiteEndings) < aggregator.nodeCount {
|
|
||||||
return false, false
|
|
||||||
}
|
|
||||||
|
|
||||||
aggregatedSuiteSummary := &types.SuiteSummary{}
|
|
||||||
aggregatedSuiteSummary.SuiteSucceeded = true
|
|
||||||
|
|
||||||
for _, suiteSummary := range aggregator.aggregatedSuiteEndings {
|
|
||||||
if suiteSummary.SuiteSucceeded == false {
|
|
||||||
aggregatedSuiteSummary.SuiteSucceeded = false
|
|
||||||
}
|
|
||||||
|
|
||||||
aggregatedSuiteSummary.NumberOfSpecsThatWillBeRun += suiteSummary.NumberOfSpecsThatWillBeRun
|
|
||||||
aggregatedSuiteSummary.NumberOfTotalSpecs += suiteSummary.NumberOfTotalSpecs
|
|
||||||
aggregatedSuiteSummary.NumberOfPassedSpecs += suiteSummary.NumberOfPassedSpecs
|
|
||||||
aggregatedSuiteSummary.NumberOfFailedSpecs += suiteSummary.NumberOfFailedSpecs
|
|
||||||
aggregatedSuiteSummary.NumberOfPendingSpecs += suiteSummary.NumberOfPendingSpecs
|
|
||||||
aggregatedSuiteSummary.NumberOfSkippedSpecs += suiteSummary.NumberOfSkippedSpecs
|
|
||||||
aggregatedSuiteSummary.NumberOfFlakedSpecs += suiteSummary.NumberOfFlakedSpecs
|
|
||||||
}
|
|
||||||
|
|
||||||
aggregatedSuiteSummary.RunTime = time.Since(aggregator.startTime)
|
|
||||||
|
|
||||||
aggregator.stenographer.SummarizeFailures(aggregator.specs)
|
|
||||||
aggregator.stenographer.AnnounceSpecRunCompletion(aggregatedSuiteSummary, aggregator.config.Succinct)
|
|
||||||
|
|
||||||
return true, aggregatedSuiteSummary.SuiteSucceeded
|
|
||||||
}
|
|
147
vendor/github.com/onsi/ginkgo/internal/remote/forwarding_reporter.go
generated
vendored
147
vendor/github.com/onsi/ginkgo/internal/remote/forwarding_reporter.go
generated
vendored
|
@ -1,147 +0,0 @@
|
||||||
package remote
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/internal/writer"
|
|
||||||
"github.com/onsi/ginkgo/reporters"
|
|
||||||
"github.com/onsi/ginkgo/reporters/stenographer"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/config"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
//An interface to net/http's client to allow the injection of fakes under test
|
|
||||||
type Poster interface {
|
|
||||||
Post(url string, bodyType string, body io.Reader) (resp *http.Response, err error)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
The ForwardingReporter is a Ginkgo reporter that forwards information to
|
|
||||||
a Ginkgo remote server.
|
|
||||||
|
|
||||||
When streaming parallel test output, this repoter is automatically installed by Ginkgo.
|
|
||||||
|
|
||||||
This is accomplished by passing in the GINKGO_REMOTE_REPORTING_SERVER environment variable to `go test`, the Ginkgo test runner
|
|
||||||
detects this environment variable (which should contain the host of the server) and automatically installs a ForwardingReporter
|
|
||||||
in place of Ginkgo's DefaultReporter.
|
|
||||||
*/
|
|
||||||
|
|
||||||
type ForwardingReporter struct {
|
|
||||||
serverHost string
|
|
||||||
poster Poster
|
|
||||||
outputInterceptor OutputInterceptor
|
|
||||||
debugMode bool
|
|
||||||
debugFile *os.File
|
|
||||||
nestedReporter *reporters.DefaultReporter
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewForwardingReporter(config config.DefaultReporterConfigType, serverHost string, poster Poster, outputInterceptor OutputInterceptor, ginkgoWriter *writer.Writer, debugFile string) *ForwardingReporter {
|
|
||||||
reporter := &ForwardingReporter{
|
|
||||||
serverHost: serverHost,
|
|
||||||
poster: poster,
|
|
||||||
outputInterceptor: outputInterceptor,
|
|
||||||
}
|
|
||||||
|
|
||||||
if debugFile != "" {
|
|
||||||
var err error
|
|
||||||
reporter.debugMode = true
|
|
||||||
reporter.debugFile, err = os.Create(debugFile)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !config.Verbose {
|
|
||||||
//if verbose is true then the GinkgoWriter emits to stdout. Don't _also_ redirect GinkgoWriter output as that will result in duplication.
|
|
||||||
ginkgoWriter.AndRedirectTo(reporter.debugFile)
|
|
||||||
}
|
|
||||||
outputInterceptor.StreamTo(reporter.debugFile) //This is not working
|
|
||||||
|
|
||||||
stenographer := stenographer.New(false, true, reporter.debugFile)
|
|
||||||
config.Succinct = false
|
|
||||||
config.Verbose = true
|
|
||||||
config.FullTrace = true
|
|
||||||
reporter.nestedReporter = reporters.NewDefaultReporter(config, stenographer)
|
|
||||||
}
|
|
||||||
|
|
||||||
return reporter
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *ForwardingReporter) post(path string, data interface{}) {
|
|
||||||
encoded, _ := json.Marshal(data)
|
|
||||||
buffer := bytes.NewBuffer(encoded)
|
|
||||||
reporter.poster.Post(reporter.serverHost+path, "application/json", buffer)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *ForwardingReporter) SpecSuiteWillBegin(conf config.GinkgoConfigType, summary *types.SuiteSummary) {
|
|
||||||
data := struct {
|
|
||||||
Config config.GinkgoConfigType `json:"config"`
|
|
||||||
Summary *types.SuiteSummary `json:"suite-summary"`
|
|
||||||
}{
|
|
||||||
conf,
|
|
||||||
summary,
|
|
||||||
}
|
|
||||||
|
|
||||||
reporter.outputInterceptor.StartInterceptingOutput()
|
|
||||||
if reporter.debugMode {
|
|
||||||
reporter.nestedReporter.SpecSuiteWillBegin(conf, summary)
|
|
||||||
reporter.debugFile.Sync()
|
|
||||||
}
|
|
||||||
reporter.post("/SpecSuiteWillBegin", data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *ForwardingReporter) BeforeSuiteDidRun(setupSummary *types.SetupSummary) {
|
|
||||||
output, _ := reporter.outputInterceptor.StopInterceptingAndReturnOutput()
|
|
||||||
reporter.outputInterceptor.StartInterceptingOutput()
|
|
||||||
setupSummary.CapturedOutput = output
|
|
||||||
if reporter.debugMode {
|
|
||||||
reporter.nestedReporter.BeforeSuiteDidRun(setupSummary)
|
|
||||||
reporter.debugFile.Sync()
|
|
||||||
}
|
|
||||||
reporter.post("/BeforeSuiteDidRun", setupSummary)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *ForwardingReporter) SpecWillRun(specSummary *types.SpecSummary) {
|
|
||||||
if reporter.debugMode {
|
|
||||||
reporter.nestedReporter.SpecWillRun(specSummary)
|
|
||||||
reporter.debugFile.Sync()
|
|
||||||
}
|
|
||||||
reporter.post("/SpecWillRun", specSummary)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *ForwardingReporter) SpecDidComplete(specSummary *types.SpecSummary) {
|
|
||||||
output, _ := reporter.outputInterceptor.StopInterceptingAndReturnOutput()
|
|
||||||
reporter.outputInterceptor.StartInterceptingOutput()
|
|
||||||
specSummary.CapturedOutput = output
|
|
||||||
if reporter.debugMode {
|
|
||||||
reporter.nestedReporter.SpecDidComplete(specSummary)
|
|
||||||
reporter.debugFile.Sync()
|
|
||||||
}
|
|
||||||
reporter.post("/SpecDidComplete", specSummary)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *ForwardingReporter) AfterSuiteDidRun(setupSummary *types.SetupSummary) {
|
|
||||||
output, _ := reporter.outputInterceptor.StopInterceptingAndReturnOutput()
|
|
||||||
reporter.outputInterceptor.StartInterceptingOutput()
|
|
||||||
setupSummary.CapturedOutput = output
|
|
||||||
if reporter.debugMode {
|
|
||||||
reporter.nestedReporter.AfterSuiteDidRun(setupSummary)
|
|
||||||
reporter.debugFile.Sync()
|
|
||||||
}
|
|
||||||
reporter.post("/AfterSuiteDidRun", setupSummary)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *ForwardingReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {
|
|
||||||
reporter.outputInterceptor.StopInterceptingAndReturnOutput()
|
|
||||||
if reporter.debugMode {
|
|
||||||
reporter.nestedReporter.SpecSuiteDidEnd(summary)
|
|
||||||
reporter.debugFile.Sync()
|
|
||||||
}
|
|
||||||
reporter.post("/SpecSuiteDidEnd", summary)
|
|
||||||
}
|
|
13
vendor/github.com/onsi/ginkgo/internal/remote/output_interceptor.go
generated
vendored
13
vendor/github.com/onsi/ginkgo/internal/remote/output_interceptor.go
generated
vendored
|
@ -1,13 +0,0 @@
|
||||||
package remote
|
|
||||||
|
|
||||||
import "os"
|
|
||||||
|
|
||||||
/*
|
|
||||||
The OutputInterceptor is used by the ForwardingReporter to
|
|
||||||
intercept and capture all stdin and stderr output during a test run.
|
|
||||||
*/
|
|
||||||
type OutputInterceptor interface {
|
|
||||||
StartInterceptingOutput() error
|
|
||||||
StopInterceptingAndReturnOutput() (string, error)
|
|
||||||
StreamTo(*os.File)
|
|
||||||
}
|
|
83
vendor/github.com/onsi/ginkgo/internal/remote/output_interceptor_unix.go
generated
vendored
83
vendor/github.com/onsi/ginkgo/internal/remote/output_interceptor_unix.go
generated
vendored
|
@ -1,83 +0,0 @@
|
||||||
// +build freebsd openbsd netbsd dragonfly darwin linux solaris
|
|
||||||
|
|
||||||
package remote
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/hpcloud/tail"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewOutputInterceptor() OutputInterceptor {
|
|
||||||
return &outputInterceptor{}
|
|
||||||
}
|
|
||||||
|
|
||||||
type outputInterceptor struct {
|
|
||||||
redirectFile *os.File
|
|
||||||
streamTarget *os.File
|
|
||||||
intercepting bool
|
|
||||||
tailer *tail.Tail
|
|
||||||
doneTailing chan bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (interceptor *outputInterceptor) StartInterceptingOutput() error {
|
|
||||||
if interceptor.intercepting {
|
|
||||||
return errors.New("Already intercepting output!")
|
|
||||||
}
|
|
||||||
interceptor.intercepting = true
|
|
||||||
|
|
||||||
var err error
|
|
||||||
|
|
||||||
interceptor.redirectFile, err = ioutil.TempFile("", "ginkgo-output")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call a function in ./syscall_dup_*.go
|
|
||||||
// If building for everything other than linux_arm64,
|
|
||||||
// use a "normal" syscall.Dup2(oldfd, newfd) call. If building for linux_arm64 (which doesn't have syscall.Dup2)
|
|
||||||
// call syscall.Dup3(oldfd, newfd, 0). They are nearly identical, see: http://linux.die.net/man/2/dup3
|
|
||||||
syscallDup(int(interceptor.redirectFile.Fd()), 1)
|
|
||||||
syscallDup(int(interceptor.redirectFile.Fd()), 2)
|
|
||||||
|
|
||||||
if interceptor.streamTarget != nil {
|
|
||||||
interceptor.tailer, _ = tail.TailFile(interceptor.redirectFile.Name(), tail.Config{Follow: true})
|
|
||||||
interceptor.doneTailing = make(chan bool)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
for line := range interceptor.tailer.Lines {
|
|
||||||
interceptor.streamTarget.Write([]byte(line.Text + "\n"))
|
|
||||||
}
|
|
||||||
close(interceptor.doneTailing)
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (interceptor *outputInterceptor) StopInterceptingAndReturnOutput() (string, error) {
|
|
||||||
if !interceptor.intercepting {
|
|
||||||
return "", errors.New("Not intercepting output!")
|
|
||||||
}
|
|
||||||
|
|
||||||
interceptor.redirectFile.Close()
|
|
||||||
output, err := ioutil.ReadFile(interceptor.redirectFile.Name())
|
|
||||||
os.Remove(interceptor.redirectFile.Name())
|
|
||||||
|
|
||||||
interceptor.intercepting = false
|
|
||||||
|
|
||||||
if interceptor.streamTarget != nil {
|
|
||||||
interceptor.tailer.Stop()
|
|
||||||
interceptor.tailer.Cleanup()
|
|
||||||
<-interceptor.doneTailing
|
|
||||||
interceptor.streamTarget.Sync()
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(output), err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (interceptor *outputInterceptor) StreamTo(out *os.File) {
|
|
||||||
interceptor.streamTarget = out
|
|
||||||
}
|
|
36
vendor/github.com/onsi/ginkgo/internal/remote/output_interceptor_win.go
generated
vendored
36
vendor/github.com/onsi/ginkgo/internal/remote/output_interceptor_win.go
generated
vendored
|
@ -1,36 +0,0 @@
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package remote
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewOutputInterceptor() OutputInterceptor {
|
|
||||||
return &outputInterceptor{}
|
|
||||||
}
|
|
||||||
|
|
||||||
type outputInterceptor struct {
|
|
||||||
intercepting bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (interceptor *outputInterceptor) StartInterceptingOutput() error {
|
|
||||||
if interceptor.intercepting {
|
|
||||||
return errors.New("Already intercepting output!")
|
|
||||||
}
|
|
||||||
interceptor.intercepting = true
|
|
||||||
|
|
||||||
// not working on windows...
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (interceptor *outputInterceptor) StopInterceptingAndReturnOutput() (string, error) {
|
|
||||||
// not working on windows...
|
|
||||||
interceptor.intercepting = false
|
|
||||||
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (interceptor *outputInterceptor) StreamTo(*os.File) {}
|
|
224
vendor/github.com/onsi/ginkgo/internal/remote/server.go
generated
vendored
224
vendor/github.com/onsi/ginkgo/internal/remote/server.go
generated
vendored
|
@ -1,224 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The remote package provides the pieces to allow Ginkgo test suites to report to remote listeners.
|
|
||||||
This is used, primarily, to enable streaming parallel test output but has, in principal, broader applications (e.g. streaming test output to a browser).
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
package remote
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/internal/spec_iterator"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/config"
|
|
||||||
"github.com/onsi/ginkgo/reporters"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
|
||||||
Server spins up on an automatically selected port and listens for communication from the forwarding reporter.
|
|
||||||
It then forwards that communication to attached reporters.
|
|
||||||
*/
|
|
||||||
type Server struct {
|
|
||||||
listener net.Listener
|
|
||||||
reporters []reporters.Reporter
|
|
||||||
alives []func() bool
|
|
||||||
lock *sync.Mutex
|
|
||||||
beforeSuiteData types.RemoteBeforeSuiteData
|
|
||||||
parallelTotal int
|
|
||||||
counter int
|
|
||||||
}
|
|
||||||
|
|
||||||
//Create a new server, automatically selecting a port
|
|
||||||
func NewServer(parallelTotal int) (*Server, error) {
|
|
||||||
listener, err := net.Listen("tcp", "127.0.0.1:0")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &Server{
|
|
||||||
listener: listener,
|
|
||||||
lock: &sync.Mutex{},
|
|
||||||
alives: make([]func() bool, parallelTotal),
|
|
||||||
beforeSuiteData: types.RemoteBeforeSuiteData{Data: nil, State: types.RemoteBeforeSuiteStatePending},
|
|
||||||
parallelTotal: parallelTotal,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
//Start the server. You don't need to `go s.Start()`, just `s.Start()`
|
|
||||||
func (server *Server) Start() {
|
|
||||||
httpServer := &http.Server{}
|
|
||||||
mux := http.NewServeMux()
|
|
||||||
httpServer.Handler = mux
|
|
||||||
|
|
||||||
//streaming endpoints
|
|
||||||
mux.HandleFunc("/SpecSuiteWillBegin", server.specSuiteWillBegin)
|
|
||||||
mux.HandleFunc("/BeforeSuiteDidRun", server.beforeSuiteDidRun)
|
|
||||||
mux.HandleFunc("/AfterSuiteDidRun", server.afterSuiteDidRun)
|
|
||||||
mux.HandleFunc("/SpecWillRun", server.specWillRun)
|
|
||||||
mux.HandleFunc("/SpecDidComplete", server.specDidComplete)
|
|
||||||
mux.HandleFunc("/SpecSuiteDidEnd", server.specSuiteDidEnd)
|
|
||||||
|
|
||||||
//synchronization endpoints
|
|
||||||
mux.HandleFunc("/BeforeSuiteState", server.handleBeforeSuiteState)
|
|
||||||
mux.HandleFunc("/RemoteAfterSuiteData", server.handleRemoteAfterSuiteData)
|
|
||||||
mux.HandleFunc("/counter", server.handleCounter)
|
|
||||||
mux.HandleFunc("/has-counter", server.handleHasCounter) //for backward compatibility
|
|
||||||
|
|
||||||
go httpServer.Serve(server.listener)
|
|
||||||
}
|
|
||||||
|
|
||||||
//Stop the server
|
|
||||||
func (server *Server) Close() {
|
|
||||||
server.listener.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
//The address the server can be reached it. Pass this into the `ForwardingReporter`.
|
|
||||||
func (server *Server) Address() string {
|
|
||||||
return "http://" + server.listener.Addr().String()
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Streaming Endpoints
|
|
||||||
//
|
|
||||||
|
|
||||||
//The server will forward all received messages to Ginkgo reporters registered with `RegisterReporters`
|
|
||||||
func (server *Server) readAll(request *http.Request) []byte {
|
|
||||||
defer request.Body.Close()
|
|
||||||
body, _ := ioutil.ReadAll(request.Body)
|
|
||||||
return body
|
|
||||||
}
|
|
||||||
|
|
||||||
func (server *Server) RegisterReporters(reporters ...reporters.Reporter) {
|
|
||||||
server.reporters = reporters
|
|
||||||
}
|
|
||||||
|
|
||||||
func (server *Server) specSuiteWillBegin(writer http.ResponseWriter, request *http.Request) {
|
|
||||||
body := server.readAll(request)
|
|
||||||
|
|
||||||
var data struct {
|
|
||||||
Config config.GinkgoConfigType `json:"config"`
|
|
||||||
Summary *types.SuiteSummary `json:"suite-summary"`
|
|
||||||
}
|
|
||||||
|
|
||||||
json.Unmarshal(body, &data)
|
|
||||||
|
|
||||||
for _, reporter := range server.reporters {
|
|
||||||
reporter.SpecSuiteWillBegin(data.Config, data.Summary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (server *Server) beforeSuiteDidRun(writer http.ResponseWriter, request *http.Request) {
|
|
||||||
body := server.readAll(request)
|
|
||||||
var setupSummary *types.SetupSummary
|
|
||||||
json.Unmarshal(body, &setupSummary)
|
|
||||||
|
|
||||||
for _, reporter := range server.reporters {
|
|
||||||
reporter.BeforeSuiteDidRun(setupSummary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (server *Server) afterSuiteDidRun(writer http.ResponseWriter, request *http.Request) {
|
|
||||||
body := server.readAll(request)
|
|
||||||
var setupSummary *types.SetupSummary
|
|
||||||
json.Unmarshal(body, &setupSummary)
|
|
||||||
|
|
||||||
for _, reporter := range server.reporters {
|
|
||||||
reporter.AfterSuiteDidRun(setupSummary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (server *Server) specWillRun(writer http.ResponseWriter, request *http.Request) {
|
|
||||||
body := server.readAll(request)
|
|
||||||
var specSummary *types.SpecSummary
|
|
||||||
json.Unmarshal(body, &specSummary)
|
|
||||||
|
|
||||||
for _, reporter := range server.reporters {
|
|
||||||
reporter.SpecWillRun(specSummary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (server *Server) specDidComplete(writer http.ResponseWriter, request *http.Request) {
|
|
||||||
body := server.readAll(request)
|
|
||||||
var specSummary *types.SpecSummary
|
|
||||||
json.Unmarshal(body, &specSummary)
|
|
||||||
|
|
||||||
for _, reporter := range server.reporters {
|
|
||||||
reporter.SpecDidComplete(specSummary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (server *Server) specSuiteDidEnd(writer http.ResponseWriter, request *http.Request) {
|
|
||||||
body := server.readAll(request)
|
|
||||||
var suiteSummary *types.SuiteSummary
|
|
||||||
json.Unmarshal(body, &suiteSummary)
|
|
||||||
|
|
||||||
for _, reporter := range server.reporters {
|
|
||||||
reporter.SpecSuiteDidEnd(suiteSummary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Synchronization Endpoints
|
|
||||||
//
|
|
||||||
|
|
||||||
func (server *Server) RegisterAlive(node int, alive func() bool) {
|
|
||||||
server.lock.Lock()
|
|
||||||
defer server.lock.Unlock()
|
|
||||||
server.alives[node-1] = alive
|
|
||||||
}
|
|
||||||
|
|
||||||
func (server *Server) nodeIsAlive(node int) bool {
|
|
||||||
server.lock.Lock()
|
|
||||||
defer server.lock.Unlock()
|
|
||||||
alive := server.alives[node-1]
|
|
||||||
if alive == nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return alive()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (server *Server) handleBeforeSuiteState(writer http.ResponseWriter, request *http.Request) {
|
|
||||||
if request.Method == "POST" {
|
|
||||||
dec := json.NewDecoder(request.Body)
|
|
||||||
dec.Decode(&(server.beforeSuiteData))
|
|
||||||
} else {
|
|
||||||
beforeSuiteData := server.beforeSuiteData
|
|
||||||
if beforeSuiteData.State == types.RemoteBeforeSuiteStatePending && !server.nodeIsAlive(1) {
|
|
||||||
beforeSuiteData.State = types.RemoteBeforeSuiteStateDisappeared
|
|
||||||
}
|
|
||||||
enc := json.NewEncoder(writer)
|
|
||||||
enc.Encode(beforeSuiteData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (server *Server) handleRemoteAfterSuiteData(writer http.ResponseWriter, request *http.Request) {
|
|
||||||
afterSuiteData := types.RemoteAfterSuiteData{
|
|
||||||
CanRun: true,
|
|
||||||
}
|
|
||||||
for i := 2; i <= server.parallelTotal; i++ {
|
|
||||||
afterSuiteData.CanRun = afterSuiteData.CanRun && !server.nodeIsAlive(i)
|
|
||||||
}
|
|
||||||
|
|
||||||
enc := json.NewEncoder(writer)
|
|
||||||
enc.Encode(afterSuiteData)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (server *Server) handleCounter(writer http.ResponseWriter, request *http.Request) {
|
|
||||||
c := spec_iterator.Counter{}
|
|
||||||
server.lock.Lock()
|
|
||||||
c.Index = server.counter
|
|
||||||
server.counter = server.counter + 1
|
|
||||||
server.lock.Unlock()
|
|
||||||
|
|
||||||
json.NewEncoder(writer).Encode(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (server *Server) handleHasCounter(writer http.ResponseWriter, request *http.Request) {
|
|
||||||
writer.Write([]byte(""))
|
|
||||||
}
|
|
11
vendor/github.com/onsi/ginkgo/internal/remote/syscall_dup_linux_arm64.go
generated
vendored
11
vendor/github.com/onsi/ginkgo/internal/remote/syscall_dup_linux_arm64.go
generated
vendored
|
@ -1,11 +0,0 @@
|
||||||
// +build linux,arm64
|
|
||||||
|
|
||||||
package remote
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
// linux_arm64 doesn't have syscall.Dup2 which ginkgo uses, so
|
|
||||||
// use the nearly identical syscall.Dup3 instead
|
|
||||||
func syscallDup(oldfd int, newfd int) (err error) {
|
|
||||||
return syscall.Dup3(oldfd, newfd, 0)
|
|
||||||
}
|
|
9
vendor/github.com/onsi/ginkgo/internal/remote/syscall_dup_solaris.go
generated
vendored
9
vendor/github.com/onsi/ginkgo/internal/remote/syscall_dup_solaris.go
generated
vendored
|
@ -1,9 +0,0 @@
|
||||||
// +build solaris
|
|
||||||
|
|
||||||
package remote
|
|
||||||
|
|
||||||
import "golang.org/x/sys/unix"
|
|
||||||
|
|
||||||
func syscallDup(oldfd int, newfd int) (err error) {
|
|
||||||
return unix.Dup2(oldfd, newfd)
|
|
||||||
}
|
|
11
vendor/github.com/onsi/ginkgo/internal/remote/syscall_dup_unix.go
generated
vendored
11
vendor/github.com/onsi/ginkgo/internal/remote/syscall_dup_unix.go
generated
vendored
|
@ -1,11 +0,0 @@
|
||||||
// +build !linux !arm64
|
|
||||||
// +build !windows
|
|
||||||
// +build !solaris
|
|
||||||
|
|
||||||
package remote
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
func syscallDup(oldfd int, newfd int) (err error) {
|
|
||||||
return syscall.Dup2(oldfd, newfd)
|
|
||||||
}
|
|
235
vendor/github.com/onsi/ginkgo/internal/spec/spec.go
generated
vendored
235
vendor/github.com/onsi/ginkgo/internal/spec/spec.go
generated
vendored
|
@ -1,235 +0,0 @@
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/internal/containernode"
|
|
||||||
"github.com/onsi/ginkgo/internal/leafnodes"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Spec struct {
|
|
||||||
subject leafnodes.SubjectNode
|
|
||||||
focused bool
|
|
||||||
announceProgress bool
|
|
||||||
|
|
||||||
containers []*containernode.ContainerNode
|
|
||||||
|
|
||||||
state types.SpecState
|
|
||||||
runTime time.Duration
|
|
||||||
startTime time.Time
|
|
||||||
failure types.SpecFailure
|
|
||||||
previousFailures bool
|
|
||||||
|
|
||||||
stateMutex *sync.Mutex
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(subject leafnodes.SubjectNode, containers []*containernode.ContainerNode, announceProgress bool) *Spec {
|
|
||||||
spec := &Spec{
|
|
||||||
subject: subject,
|
|
||||||
containers: containers,
|
|
||||||
focused: subject.Flag() == types.FlagTypeFocused,
|
|
||||||
announceProgress: announceProgress,
|
|
||||||
stateMutex: &sync.Mutex{},
|
|
||||||
}
|
|
||||||
|
|
||||||
spec.processFlag(subject.Flag())
|
|
||||||
for i := len(containers) - 1; i >= 0; i-- {
|
|
||||||
spec.processFlag(containers[i].Flag())
|
|
||||||
}
|
|
||||||
|
|
||||||
return spec
|
|
||||||
}
|
|
||||||
|
|
||||||
func (spec *Spec) processFlag(flag types.FlagType) {
|
|
||||||
if flag == types.FlagTypeFocused {
|
|
||||||
spec.focused = true
|
|
||||||
} else if flag == types.FlagTypePending {
|
|
||||||
spec.setState(types.SpecStatePending)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (spec *Spec) Skip() {
|
|
||||||
spec.setState(types.SpecStateSkipped)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (spec *Spec) Failed() bool {
|
|
||||||
return spec.getState() == types.SpecStateFailed || spec.getState() == types.SpecStatePanicked || spec.getState() == types.SpecStateTimedOut
|
|
||||||
}
|
|
||||||
|
|
||||||
func (spec *Spec) Passed() bool {
|
|
||||||
return spec.getState() == types.SpecStatePassed
|
|
||||||
}
|
|
||||||
|
|
||||||
func (spec *Spec) Flaked() bool {
|
|
||||||
return spec.getState() == types.SpecStatePassed && spec.previousFailures
|
|
||||||
}
|
|
||||||
|
|
||||||
func (spec *Spec) Pending() bool {
|
|
||||||
return spec.getState() == types.SpecStatePending
|
|
||||||
}
|
|
||||||
|
|
||||||
func (spec *Spec) Skipped() bool {
|
|
||||||
return spec.getState() == types.SpecStateSkipped
|
|
||||||
}
|
|
||||||
|
|
||||||
func (spec *Spec) Focused() bool {
|
|
||||||
return spec.focused
|
|
||||||
}
|
|
||||||
|
|
||||||
func (spec *Spec) IsMeasurement() bool {
|
|
||||||
return spec.subject.Type() == types.SpecComponentTypeMeasure
|
|
||||||
}
|
|
||||||
|
|
||||||
func (spec *Spec) Summary(suiteID string) *types.SpecSummary {
|
|
||||||
componentTexts := make([]string, len(spec.containers)+1)
|
|
||||||
componentCodeLocations := make([]types.CodeLocation, len(spec.containers)+1)
|
|
||||||
|
|
||||||
for i, container := range spec.containers {
|
|
||||||
componentTexts[i] = container.Text()
|
|
||||||
componentCodeLocations[i] = container.CodeLocation()
|
|
||||||
}
|
|
||||||
|
|
||||||
componentTexts[len(spec.containers)] = spec.subject.Text()
|
|
||||||
componentCodeLocations[len(spec.containers)] = spec.subject.CodeLocation()
|
|
||||||
|
|
||||||
runTime := spec.runTime
|
|
||||||
if runTime == 0 && !spec.startTime.IsZero() {
|
|
||||||
runTime = time.Since(spec.startTime)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &types.SpecSummary{
|
|
||||||
IsMeasurement: spec.IsMeasurement(),
|
|
||||||
NumberOfSamples: spec.subject.Samples(),
|
|
||||||
ComponentTexts: componentTexts,
|
|
||||||
ComponentCodeLocations: componentCodeLocations,
|
|
||||||
State: spec.getState(),
|
|
||||||
RunTime: runTime,
|
|
||||||
Failure: spec.failure,
|
|
||||||
Measurements: spec.measurementsReport(),
|
|
||||||
SuiteID: suiteID,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (spec *Spec) ConcatenatedString() string {
|
|
||||||
s := ""
|
|
||||||
for _, container := range spec.containers {
|
|
||||||
s += container.Text() + " "
|
|
||||||
}
|
|
||||||
|
|
||||||
return s + spec.subject.Text()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (spec *Spec) Run(writer io.Writer) {
|
|
||||||
if spec.getState() == types.SpecStateFailed {
|
|
||||||
spec.previousFailures = true
|
|
||||||
}
|
|
||||||
|
|
||||||
spec.startTime = time.Now()
|
|
||||||
defer func() {
|
|
||||||
spec.runTime = time.Since(spec.startTime)
|
|
||||||
}()
|
|
||||||
|
|
||||||
for sample := 0; sample < spec.subject.Samples(); sample++ {
|
|
||||||
spec.runSample(sample, writer)
|
|
||||||
|
|
||||||
if spec.getState() != types.SpecStatePassed {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (spec *Spec) getState() types.SpecState {
|
|
||||||
spec.stateMutex.Lock()
|
|
||||||
defer spec.stateMutex.Unlock()
|
|
||||||
return spec.state
|
|
||||||
}
|
|
||||||
|
|
||||||
func (spec *Spec) setState(state types.SpecState) {
|
|
||||||
spec.stateMutex.Lock()
|
|
||||||
defer spec.stateMutex.Unlock()
|
|
||||||
spec.state = state
|
|
||||||
}
|
|
||||||
|
|
||||||
func (spec *Spec) runSample(sample int, writer io.Writer) {
|
|
||||||
spec.setState(types.SpecStatePassed)
|
|
||||||
spec.failure = types.SpecFailure{}
|
|
||||||
innerMostContainerIndexToUnwind := -1
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
for i := innerMostContainerIndexToUnwind; i >= 0; i-- {
|
|
||||||
container := spec.containers[i]
|
|
||||||
for _, afterEach := range container.SetupNodesOfType(types.SpecComponentTypeAfterEach) {
|
|
||||||
spec.announceSetupNode(writer, "AfterEach", container, afterEach)
|
|
||||||
afterEachState, afterEachFailure := afterEach.Run()
|
|
||||||
if afterEachState != types.SpecStatePassed && spec.getState() == types.SpecStatePassed {
|
|
||||||
spec.setState(afterEachState)
|
|
||||||
spec.failure = afterEachFailure
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
for i, container := range spec.containers {
|
|
||||||
innerMostContainerIndexToUnwind = i
|
|
||||||
for _, beforeEach := range container.SetupNodesOfType(types.SpecComponentTypeBeforeEach) {
|
|
||||||
spec.announceSetupNode(writer, "BeforeEach", container, beforeEach)
|
|
||||||
s, f := beforeEach.Run()
|
|
||||||
spec.failure = f
|
|
||||||
spec.setState(s)
|
|
||||||
if spec.getState() != types.SpecStatePassed {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, container := range spec.containers {
|
|
||||||
for _, justBeforeEach := range container.SetupNodesOfType(types.SpecComponentTypeJustBeforeEach) {
|
|
||||||
spec.announceSetupNode(writer, "JustBeforeEach", container, justBeforeEach)
|
|
||||||
s, f := justBeforeEach.Run()
|
|
||||||
spec.failure = f
|
|
||||||
spec.setState(s)
|
|
||||||
if spec.getState() != types.SpecStatePassed {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
spec.announceSubject(writer, spec.subject)
|
|
||||||
s, f := spec.subject.Run()
|
|
||||||
spec.failure = f
|
|
||||||
spec.setState(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (spec *Spec) announceSetupNode(writer io.Writer, nodeType string, container *containernode.ContainerNode, setupNode leafnodes.BasicNode) {
|
|
||||||
if spec.announceProgress {
|
|
||||||
s := fmt.Sprintf("[%s] %s\n %s\n", nodeType, container.Text(), setupNode.CodeLocation().String())
|
|
||||||
writer.Write([]byte(s))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (spec *Spec) announceSubject(writer io.Writer, subject leafnodes.SubjectNode) {
|
|
||||||
if spec.announceProgress {
|
|
||||||
nodeType := ""
|
|
||||||
switch subject.Type() {
|
|
||||||
case types.SpecComponentTypeIt:
|
|
||||||
nodeType = "It"
|
|
||||||
case types.SpecComponentTypeMeasure:
|
|
||||||
nodeType = "Measure"
|
|
||||||
}
|
|
||||||
s := fmt.Sprintf("[%s] %s\n %s\n", nodeType, subject.Text(), subject.CodeLocation().String())
|
|
||||||
writer.Write([]byte(s))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (spec *Spec) measurementsReport() map[string]*types.SpecMeasurement {
|
|
||||||
if !spec.IsMeasurement() || spec.Failed() {
|
|
||||||
return map[string]*types.SpecMeasurement{}
|
|
||||||
}
|
|
||||||
|
|
||||||
return spec.subject.(*leafnodes.MeasureNode).MeasurementsReport()
|
|
||||||
}
|
|
123
vendor/github.com/onsi/ginkgo/internal/spec/specs.go
generated
vendored
123
vendor/github.com/onsi/ginkgo/internal/spec/specs.go
generated
vendored
|
@ -1,123 +0,0 @@
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math/rand"
|
|
||||||
"regexp"
|
|
||||||
"sort"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Specs struct {
|
|
||||||
specs []*Spec
|
|
||||||
hasProgrammaticFocus bool
|
|
||||||
RegexScansFilePath bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSpecs(specs []*Spec) *Specs {
|
|
||||||
return &Specs{
|
|
||||||
specs: specs,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Specs) Specs() []*Spec {
|
|
||||||
return e.specs
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Specs) HasProgrammaticFocus() bool {
|
|
||||||
return e.hasProgrammaticFocus
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Specs) Shuffle(r *rand.Rand) {
|
|
||||||
sort.Sort(e)
|
|
||||||
permutation := r.Perm(len(e.specs))
|
|
||||||
shuffledSpecs := make([]*Spec, len(e.specs))
|
|
||||||
for i, j := range permutation {
|
|
||||||
shuffledSpecs[i] = e.specs[j]
|
|
||||||
}
|
|
||||||
e.specs = shuffledSpecs
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Specs) ApplyFocus(description string, focusString string, skipString string) {
|
|
||||||
if focusString == "" && skipString == "" {
|
|
||||||
e.applyProgrammaticFocus()
|
|
||||||
} else {
|
|
||||||
e.applyRegExpFocusAndSkip(description, focusString, skipString)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Specs) applyProgrammaticFocus() {
|
|
||||||
e.hasProgrammaticFocus = false
|
|
||||||
for _, spec := range e.specs {
|
|
||||||
if spec.Focused() && !spec.Pending() {
|
|
||||||
e.hasProgrammaticFocus = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if e.hasProgrammaticFocus {
|
|
||||||
for _, spec := range e.specs {
|
|
||||||
if !spec.Focused() {
|
|
||||||
spec.Skip()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// toMatch returns a byte[] to be used by regex matchers. When adding new behaviours to the matching function,
|
|
||||||
// this is the place which we append to.
|
|
||||||
func (e *Specs) toMatch(description string, spec *Spec) []byte {
|
|
||||||
if e.RegexScansFilePath {
|
|
||||||
return []byte(
|
|
||||||
description + " " +
|
|
||||||
spec.ConcatenatedString() + " " +
|
|
||||||
spec.subject.CodeLocation().FileName)
|
|
||||||
} else {
|
|
||||||
return []byte(
|
|
||||||
description + " " +
|
|
||||||
spec.ConcatenatedString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Specs) applyRegExpFocusAndSkip(description string, focusString string, skipString string) {
|
|
||||||
for _, spec := range e.specs {
|
|
||||||
matchesFocus := true
|
|
||||||
matchesSkip := false
|
|
||||||
|
|
||||||
toMatch := e.toMatch(description, spec)
|
|
||||||
|
|
||||||
if focusString != "" {
|
|
||||||
focusFilter := regexp.MustCompile(focusString)
|
|
||||||
matchesFocus = focusFilter.Match([]byte(toMatch))
|
|
||||||
}
|
|
||||||
|
|
||||||
if skipString != "" {
|
|
||||||
skipFilter := regexp.MustCompile(skipString)
|
|
||||||
matchesSkip = skipFilter.Match([]byte(toMatch))
|
|
||||||
}
|
|
||||||
|
|
||||||
if !matchesFocus || matchesSkip {
|
|
||||||
spec.Skip()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Specs) SkipMeasurements() {
|
|
||||||
for _, spec := range e.specs {
|
|
||||||
if spec.IsMeasurement() {
|
|
||||||
spec.Skip()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//sort.Interface
|
|
||||||
|
|
||||||
func (e *Specs) Len() int {
|
|
||||||
return len(e.specs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Specs) Less(i, j int) bool {
|
|
||||||
return e.specs[i].ConcatenatedString() < e.specs[j].ConcatenatedString()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Specs) Swap(i, j int) {
|
|
||||||
e.specs[i], e.specs[j] = e.specs[j], e.specs[i]
|
|
||||||
}
|
|
55
vendor/github.com/onsi/ginkgo/internal/spec_iterator/index_computer.go
generated
vendored
55
vendor/github.com/onsi/ginkgo/internal/spec_iterator/index_computer.go
generated
vendored
|
@ -1,55 +0,0 @@
|
||||||
package spec_iterator
|
|
||||||
|
|
||||||
func ParallelizedIndexRange(length int, parallelTotal int, parallelNode int) (startIndex int, count int) {
|
|
||||||
if length == 0 {
|
|
||||||
return 0, 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// We have more nodes than tests. Trivial case.
|
|
||||||
if parallelTotal >= length {
|
|
||||||
if parallelNode > length {
|
|
||||||
return 0, 0
|
|
||||||
} else {
|
|
||||||
return parallelNode - 1, 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is the minimum amount of tests that a node will be required to run
|
|
||||||
minTestsPerNode := length / parallelTotal
|
|
||||||
|
|
||||||
// This is the maximum amount of tests that a node will be required to run
|
|
||||||
// The algorithm guarantees that this would be equal to at least the minimum amount
|
|
||||||
// and at most one more
|
|
||||||
maxTestsPerNode := minTestsPerNode
|
|
||||||
if length%parallelTotal != 0 {
|
|
||||||
maxTestsPerNode++
|
|
||||||
}
|
|
||||||
|
|
||||||
// Number of nodes that will have to run the maximum amount of tests per node
|
|
||||||
numMaxLoadNodes := length % parallelTotal
|
|
||||||
|
|
||||||
// Number of nodes that precede the current node and will have to run the maximum amount of tests per node
|
|
||||||
var numPrecedingMaxLoadNodes int
|
|
||||||
if parallelNode > numMaxLoadNodes {
|
|
||||||
numPrecedingMaxLoadNodes = numMaxLoadNodes
|
|
||||||
} else {
|
|
||||||
numPrecedingMaxLoadNodes = parallelNode - 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// Number of nodes that precede the current node and will have to run the minimum amount of tests per node
|
|
||||||
var numPrecedingMinLoadNodes int
|
|
||||||
if parallelNode <= numMaxLoadNodes {
|
|
||||||
numPrecedingMinLoadNodes = 0
|
|
||||||
} else {
|
|
||||||
numPrecedingMinLoadNodes = parallelNode - numMaxLoadNodes - 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// Evaluate the test start index and number of tests to run
|
|
||||||
startIndex = numPrecedingMaxLoadNodes*maxTestsPerNode + numPrecedingMinLoadNodes*minTestsPerNode
|
|
||||||
if parallelNode > numMaxLoadNodes {
|
|
||||||
count = minTestsPerNode
|
|
||||||
} else {
|
|
||||||
count = maxTestsPerNode
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
59
vendor/github.com/onsi/ginkgo/internal/spec_iterator/parallel_spec_iterator.go
generated
vendored
59
vendor/github.com/onsi/ginkgo/internal/spec_iterator/parallel_spec_iterator.go
generated
vendored
|
@ -1,59 +0,0 @@
|
||||||
package spec_iterator
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/internal/spec"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ParallelIterator struct {
|
|
||||||
specs []*spec.Spec
|
|
||||||
host string
|
|
||||||
client *http.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewParallelIterator(specs []*spec.Spec, host string) *ParallelIterator {
|
|
||||||
return &ParallelIterator{
|
|
||||||
specs: specs,
|
|
||||||
host: host,
|
|
||||||
client: &http.Client{},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ParallelIterator) Next() (*spec.Spec, error) {
|
|
||||||
resp, err := s.client.Get(s.host + "/counter")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
return nil, fmt.Errorf("unexpected status code %d", resp.StatusCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
var counter Counter
|
|
||||||
err = json.NewDecoder(resp.Body).Decode(&counter)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if counter.Index >= len(s.specs) {
|
|
||||||
return nil, ErrClosed
|
|
||||||
}
|
|
||||||
|
|
||||||
return s.specs[counter.Index], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ParallelIterator) NumberOfSpecsPriorToIteration() int {
|
|
||||||
return len(s.specs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ParallelIterator) NumberOfSpecsToProcessIfKnown() (int, bool) {
|
|
||||||
return -1, false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ParallelIterator) NumberOfSpecsThatWillBeRunIfKnown() (int, bool) {
|
|
||||||
return -1, false
|
|
||||||
}
|
|
45
vendor/github.com/onsi/ginkgo/internal/spec_iterator/serial_spec_iterator.go
generated
vendored
45
vendor/github.com/onsi/ginkgo/internal/spec_iterator/serial_spec_iterator.go
generated
vendored
|
@ -1,45 +0,0 @@
|
||||||
package spec_iterator
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/onsi/ginkgo/internal/spec"
|
|
||||||
)
|
|
||||||
|
|
||||||
type SerialIterator struct {
|
|
||||||
specs []*spec.Spec
|
|
||||||
index int
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSerialIterator(specs []*spec.Spec) *SerialIterator {
|
|
||||||
return &SerialIterator{
|
|
||||||
specs: specs,
|
|
||||||
index: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SerialIterator) Next() (*spec.Spec, error) {
|
|
||||||
if s.index >= len(s.specs) {
|
|
||||||
return nil, ErrClosed
|
|
||||||
}
|
|
||||||
|
|
||||||
spec := s.specs[s.index]
|
|
||||||
s.index += 1
|
|
||||||
return spec, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SerialIterator) NumberOfSpecsPriorToIteration() int {
|
|
||||||
return len(s.specs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SerialIterator) NumberOfSpecsToProcessIfKnown() (int, bool) {
|
|
||||||
return len(s.specs), true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SerialIterator) NumberOfSpecsThatWillBeRunIfKnown() (int, bool) {
|
|
||||||
count := 0
|
|
||||||
for _, s := range s.specs {
|
|
||||||
if !s.Skipped() && !s.Pending() {
|
|
||||||
count += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return count, true
|
|
||||||
}
|
|
47
vendor/github.com/onsi/ginkgo/internal/spec_iterator/sharded_parallel_spec_iterator.go
generated
vendored
47
vendor/github.com/onsi/ginkgo/internal/spec_iterator/sharded_parallel_spec_iterator.go
generated
vendored
|
@ -1,47 +0,0 @@
|
||||||
package spec_iterator
|
|
||||||
|
|
||||||
import "github.com/onsi/ginkgo/internal/spec"
|
|
||||||
|
|
||||||
type ShardedParallelIterator struct {
|
|
||||||
specs []*spec.Spec
|
|
||||||
index int
|
|
||||||
maxIndex int
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewShardedParallelIterator(specs []*spec.Spec, total int, node int) *ShardedParallelIterator {
|
|
||||||
startIndex, count := ParallelizedIndexRange(len(specs), total, node)
|
|
||||||
|
|
||||||
return &ShardedParallelIterator{
|
|
||||||
specs: specs,
|
|
||||||
index: startIndex,
|
|
||||||
maxIndex: startIndex + count,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ShardedParallelIterator) Next() (*spec.Spec, error) {
|
|
||||||
if s.index >= s.maxIndex {
|
|
||||||
return nil, ErrClosed
|
|
||||||
}
|
|
||||||
|
|
||||||
spec := s.specs[s.index]
|
|
||||||
s.index += 1
|
|
||||||
return spec, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ShardedParallelIterator) NumberOfSpecsPriorToIteration() int {
|
|
||||||
return len(s.specs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ShardedParallelIterator) NumberOfSpecsToProcessIfKnown() (int, bool) {
|
|
||||||
return s.maxIndex - s.index, true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ShardedParallelIterator) NumberOfSpecsThatWillBeRunIfKnown() (int, bool) {
|
|
||||||
count := 0
|
|
||||||
for i := s.index; i < s.maxIndex; i += 1 {
|
|
||||||
if !s.specs[i].Skipped() && !s.specs[i].Pending() {
|
|
||||||
count += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return count, true
|
|
||||||
}
|
|
20
vendor/github.com/onsi/ginkgo/internal/spec_iterator/spec_iterator.go
generated
vendored
20
vendor/github.com/onsi/ginkgo/internal/spec_iterator/spec_iterator.go
generated
vendored
|
@ -1,20 +0,0 @@
|
||||||
package spec_iterator
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/internal/spec"
|
|
||||||
)
|
|
||||||
|
|
||||||
var ErrClosed = errors.New("no more specs to run")
|
|
||||||
|
|
||||||
type SpecIterator interface {
|
|
||||||
Next() (*spec.Spec, error)
|
|
||||||
NumberOfSpecsPriorToIteration() int
|
|
||||||
NumberOfSpecsToProcessIfKnown() (int, bool)
|
|
||||||
NumberOfSpecsThatWillBeRunIfKnown() (int, bool)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Counter struct {
|
|
||||||
Index int `json:"index"`
|
|
||||||
}
|
|
15
vendor/github.com/onsi/ginkgo/internal/specrunner/random_id.go
generated
vendored
15
vendor/github.com/onsi/ginkgo/internal/specrunner/random_id.go
generated
vendored
|
@ -1,15 +0,0 @@
|
||||||
package specrunner
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/rand"
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func randomID() string {
|
|
||||||
b := make([]byte, 8)
|
|
||||||
_, err := rand.Read(b)
|
|
||||||
if err != nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%x-%x-%x-%x", b[0:2], b[2:4], b[4:6], b[6:8])
|
|
||||||
}
|
|
411
vendor/github.com/onsi/ginkgo/internal/specrunner/spec_runner.go
generated
vendored
411
vendor/github.com/onsi/ginkgo/internal/specrunner/spec_runner.go
generated
vendored
|
@ -1,411 +0,0 @@
|
||||||
package specrunner
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"sync"
|
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/internal/spec_iterator"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/config"
|
|
||||||
"github.com/onsi/ginkgo/internal/leafnodes"
|
|
||||||
"github.com/onsi/ginkgo/internal/spec"
|
|
||||||
Writer "github.com/onsi/ginkgo/internal/writer"
|
|
||||||
"github.com/onsi/ginkgo/reporters"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type SpecRunner struct {
|
|
||||||
description string
|
|
||||||
beforeSuiteNode leafnodes.SuiteNode
|
|
||||||
iterator spec_iterator.SpecIterator
|
|
||||||
afterSuiteNode leafnodes.SuiteNode
|
|
||||||
reporters []reporters.Reporter
|
|
||||||
startTime time.Time
|
|
||||||
suiteID string
|
|
||||||
runningSpec *spec.Spec
|
|
||||||
writer Writer.WriterInterface
|
|
||||||
config config.GinkgoConfigType
|
|
||||||
interrupted bool
|
|
||||||
processedSpecs []*spec.Spec
|
|
||||||
lock *sync.Mutex
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(description string, beforeSuiteNode leafnodes.SuiteNode, iterator spec_iterator.SpecIterator, afterSuiteNode leafnodes.SuiteNode, reporters []reporters.Reporter, writer Writer.WriterInterface, config config.GinkgoConfigType) *SpecRunner {
|
|
||||||
return &SpecRunner{
|
|
||||||
description: description,
|
|
||||||
beforeSuiteNode: beforeSuiteNode,
|
|
||||||
iterator: iterator,
|
|
||||||
afterSuiteNode: afterSuiteNode,
|
|
||||||
reporters: reporters,
|
|
||||||
writer: writer,
|
|
||||||
config: config,
|
|
||||||
suiteID: randomID(),
|
|
||||||
lock: &sync.Mutex{},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) Run() bool {
|
|
||||||
if runner.config.DryRun {
|
|
||||||
runner.performDryRun()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
runner.reportSuiteWillBegin()
|
|
||||||
signalRegistered := make(chan struct{})
|
|
||||||
go runner.registerForInterrupts(signalRegistered)
|
|
||||||
<-signalRegistered
|
|
||||||
|
|
||||||
suitePassed := runner.runBeforeSuite()
|
|
||||||
|
|
||||||
if suitePassed {
|
|
||||||
suitePassed = runner.runSpecs()
|
|
||||||
}
|
|
||||||
|
|
||||||
runner.blockForeverIfInterrupted()
|
|
||||||
|
|
||||||
suitePassed = runner.runAfterSuite() && suitePassed
|
|
||||||
|
|
||||||
runner.reportSuiteDidEnd(suitePassed)
|
|
||||||
|
|
||||||
return suitePassed
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) performDryRun() {
|
|
||||||
runner.reportSuiteWillBegin()
|
|
||||||
|
|
||||||
if runner.beforeSuiteNode != nil {
|
|
||||||
summary := runner.beforeSuiteNode.Summary()
|
|
||||||
summary.State = types.SpecStatePassed
|
|
||||||
runner.reportBeforeSuite(summary)
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
|
||||||
spec, err := runner.iterator.Next()
|
|
||||||
if err == spec_iterator.ErrClosed {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("failed to iterate over tests:\n" + err.Error())
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
runner.processedSpecs = append(runner.processedSpecs, spec)
|
|
||||||
|
|
||||||
summary := spec.Summary(runner.suiteID)
|
|
||||||
runner.reportSpecWillRun(summary)
|
|
||||||
if summary.State == types.SpecStateInvalid {
|
|
||||||
summary.State = types.SpecStatePassed
|
|
||||||
}
|
|
||||||
runner.reportSpecDidComplete(summary, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
if runner.afterSuiteNode != nil {
|
|
||||||
summary := runner.afterSuiteNode.Summary()
|
|
||||||
summary.State = types.SpecStatePassed
|
|
||||||
runner.reportAfterSuite(summary)
|
|
||||||
}
|
|
||||||
|
|
||||||
runner.reportSuiteDidEnd(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) runBeforeSuite() bool {
|
|
||||||
if runner.beforeSuiteNode == nil || runner.wasInterrupted() {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
runner.writer.Truncate()
|
|
||||||
conf := runner.config
|
|
||||||
passed := runner.beforeSuiteNode.Run(conf.ParallelNode, conf.ParallelTotal, conf.SyncHost)
|
|
||||||
if !passed {
|
|
||||||
runner.writer.DumpOut()
|
|
||||||
}
|
|
||||||
runner.reportBeforeSuite(runner.beforeSuiteNode.Summary())
|
|
||||||
return passed
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) runAfterSuite() bool {
|
|
||||||
if runner.afterSuiteNode == nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
runner.writer.Truncate()
|
|
||||||
conf := runner.config
|
|
||||||
passed := runner.afterSuiteNode.Run(conf.ParallelNode, conf.ParallelTotal, conf.SyncHost)
|
|
||||||
if !passed {
|
|
||||||
runner.writer.DumpOut()
|
|
||||||
}
|
|
||||||
runner.reportAfterSuite(runner.afterSuiteNode.Summary())
|
|
||||||
return passed
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) runSpecs() bool {
|
|
||||||
suiteFailed := false
|
|
||||||
skipRemainingSpecs := false
|
|
||||||
for {
|
|
||||||
spec, err := runner.iterator.Next()
|
|
||||||
if err == spec_iterator.ErrClosed {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("failed to iterate over tests:\n" + err.Error())
|
|
||||||
suiteFailed = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
runner.processedSpecs = append(runner.processedSpecs, spec)
|
|
||||||
|
|
||||||
if runner.wasInterrupted() {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if skipRemainingSpecs {
|
|
||||||
spec.Skip()
|
|
||||||
}
|
|
||||||
|
|
||||||
if !spec.Skipped() && !spec.Pending() {
|
|
||||||
if passed := runner.runSpec(spec); !passed {
|
|
||||||
suiteFailed = true
|
|
||||||
}
|
|
||||||
} else if spec.Pending() && runner.config.FailOnPending {
|
|
||||||
runner.reportSpecWillRun(spec.Summary(runner.suiteID))
|
|
||||||
suiteFailed = true
|
|
||||||
runner.reportSpecDidComplete(spec.Summary(runner.suiteID), spec.Failed())
|
|
||||||
} else {
|
|
||||||
runner.reportSpecWillRun(spec.Summary(runner.suiteID))
|
|
||||||
runner.reportSpecDidComplete(spec.Summary(runner.suiteID), spec.Failed())
|
|
||||||
}
|
|
||||||
|
|
||||||
if spec.Failed() && runner.config.FailFast {
|
|
||||||
skipRemainingSpecs = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return !suiteFailed
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) runSpec(spec *spec.Spec) (passed bool) {
|
|
||||||
maxAttempts := 1
|
|
||||||
if runner.config.FlakeAttempts > 0 {
|
|
||||||
// uninitialized configs count as 1
|
|
||||||
maxAttempts = runner.config.FlakeAttempts
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < maxAttempts; i++ {
|
|
||||||
runner.reportSpecWillRun(spec.Summary(runner.suiteID))
|
|
||||||
runner.runningSpec = spec
|
|
||||||
spec.Run(runner.writer)
|
|
||||||
runner.runningSpec = nil
|
|
||||||
runner.reportSpecDidComplete(spec.Summary(runner.suiteID), spec.Failed())
|
|
||||||
if !spec.Failed() {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) CurrentSpecSummary() (*types.SpecSummary, bool) {
|
|
||||||
if runner.runningSpec == nil {
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
|
|
||||||
return runner.runningSpec.Summary(runner.suiteID), true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) registerForInterrupts(signalRegistered chan struct{}) {
|
|
||||||
c := make(chan os.Signal, 1)
|
|
||||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
|
||||||
close(signalRegistered)
|
|
||||||
|
|
||||||
<-c
|
|
||||||
signal.Stop(c)
|
|
||||||
runner.markInterrupted()
|
|
||||||
go runner.registerForHardInterrupts()
|
|
||||||
runner.writer.DumpOutWithHeader(`
|
|
||||||
Received interrupt. Emitting contents of GinkgoWriter...
|
|
||||||
---------------------------------------------------------
|
|
||||||
`)
|
|
||||||
if runner.afterSuiteNode != nil {
|
|
||||||
fmt.Fprint(os.Stderr, `
|
|
||||||
---------------------------------------------------------
|
|
||||||
Received interrupt. Running AfterSuite...
|
|
||||||
^C again to terminate immediately
|
|
||||||
`)
|
|
||||||
runner.runAfterSuite()
|
|
||||||
}
|
|
||||||
runner.reportSuiteDidEnd(false)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) registerForHardInterrupts() {
|
|
||||||
c := make(chan os.Signal, 1)
|
|
||||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
|
||||||
|
|
||||||
<-c
|
|
||||||
fmt.Fprintln(os.Stderr, "\nReceived second interrupt. Shutting down.")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) blockForeverIfInterrupted() {
|
|
||||||
runner.lock.Lock()
|
|
||||||
interrupted := runner.interrupted
|
|
||||||
runner.lock.Unlock()
|
|
||||||
|
|
||||||
if interrupted {
|
|
||||||
select {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) markInterrupted() {
|
|
||||||
runner.lock.Lock()
|
|
||||||
defer runner.lock.Unlock()
|
|
||||||
runner.interrupted = true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) wasInterrupted() bool {
|
|
||||||
runner.lock.Lock()
|
|
||||||
defer runner.lock.Unlock()
|
|
||||||
return runner.interrupted
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) reportSuiteWillBegin() {
|
|
||||||
runner.startTime = time.Now()
|
|
||||||
summary := runner.suiteWillBeginSummary()
|
|
||||||
for _, reporter := range runner.reporters {
|
|
||||||
reporter.SpecSuiteWillBegin(runner.config, summary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) reportBeforeSuite(summary *types.SetupSummary) {
|
|
||||||
for _, reporter := range runner.reporters {
|
|
||||||
reporter.BeforeSuiteDidRun(summary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) reportAfterSuite(summary *types.SetupSummary) {
|
|
||||||
for _, reporter := range runner.reporters {
|
|
||||||
reporter.AfterSuiteDidRun(summary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) reportSpecWillRun(summary *types.SpecSummary) {
|
|
||||||
runner.writer.Truncate()
|
|
||||||
|
|
||||||
for _, reporter := range runner.reporters {
|
|
||||||
reporter.SpecWillRun(summary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) reportSpecDidComplete(summary *types.SpecSummary, failed bool) {
|
|
||||||
if failed && len(summary.CapturedOutput) == 0 {
|
|
||||||
summary.CapturedOutput = string(runner.writer.Bytes())
|
|
||||||
}
|
|
||||||
for i := len(runner.reporters) - 1; i >= 1; i-- {
|
|
||||||
runner.reporters[i].SpecDidComplete(summary)
|
|
||||||
}
|
|
||||||
|
|
||||||
if failed {
|
|
||||||
runner.writer.DumpOut()
|
|
||||||
}
|
|
||||||
|
|
||||||
runner.reporters[0].SpecDidComplete(summary)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) reportSuiteDidEnd(success bool) {
|
|
||||||
summary := runner.suiteDidEndSummary(success)
|
|
||||||
summary.RunTime = time.Since(runner.startTime)
|
|
||||||
for _, reporter := range runner.reporters {
|
|
||||||
reporter.SpecSuiteDidEnd(summary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) countSpecsThatRanSatisfying(filter func(ex *spec.Spec) bool) (count int) {
|
|
||||||
count = 0
|
|
||||||
|
|
||||||
for _, spec := range runner.processedSpecs {
|
|
||||||
if filter(spec) {
|
|
||||||
count++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return count
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) suiteDidEndSummary(success bool) *types.SuiteSummary {
|
|
||||||
numberOfSpecsThatWillBeRun := runner.countSpecsThatRanSatisfying(func(ex *spec.Spec) bool {
|
|
||||||
return !ex.Skipped() && !ex.Pending()
|
|
||||||
})
|
|
||||||
|
|
||||||
numberOfPendingSpecs := runner.countSpecsThatRanSatisfying(func(ex *spec.Spec) bool {
|
|
||||||
return ex.Pending()
|
|
||||||
})
|
|
||||||
|
|
||||||
numberOfSkippedSpecs := runner.countSpecsThatRanSatisfying(func(ex *spec.Spec) bool {
|
|
||||||
return ex.Skipped()
|
|
||||||
})
|
|
||||||
|
|
||||||
numberOfPassedSpecs := runner.countSpecsThatRanSatisfying(func(ex *spec.Spec) bool {
|
|
||||||
return ex.Passed()
|
|
||||||
})
|
|
||||||
|
|
||||||
numberOfFlakedSpecs := runner.countSpecsThatRanSatisfying(func(ex *spec.Spec) bool {
|
|
||||||
return ex.Flaked()
|
|
||||||
})
|
|
||||||
|
|
||||||
numberOfFailedSpecs := runner.countSpecsThatRanSatisfying(func(ex *spec.Spec) bool {
|
|
||||||
return ex.Failed()
|
|
||||||
})
|
|
||||||
|
|
||||||
if runner.beforeSuiteNode != nil && !runner.beforeSuiteNode.Passed() && !runner.config.DryRun {
|
|
||||||
var known bool
|
|
||||||
numberOfSpecsThatWillBeRun, known = runner.iterator.NumberOfSpecsThatWillBeRunIfKnown()
|
|
||||||
if !known {
|
|
||||||
numberOfSpecsThatWillBeRun = runner.iterator.NumberOfSpecsPriorToIteration()
|
|
||||||
}
|
|
||||||
numberOfFailedSpecs = numberOfSpecsThatWillBeRun
|
|
||||||
}
|
|
||||||
|
|
||||||
return &types.SuiteSummary{
|
|
||||||
SuiteDescription: runner.description,
|
|
||||||
SuiteSucceeded: success,
|
|
||||||
SuiteID: runner.suiteID,
|
|
||||||
|
|
||||||
NumberOfSpecsBeforeParallelization: runner.iterator.NumberOfSpecsPriorToIteration(),
|
|
||||||
NumberOfTotalSpecs: len(runner.processedSpecs),
|
|
||||||
NumberOfSpecsThatWillBeRun: numberOfSpecsThatWillBeRun,
|
|
||||||
NumberOfPendingSpecs: numberOfPendingSpecs,
|
|
||||||
NumberOfSkippedSpecs: numberOfSkippedSpecs,
|
|
||||||
NumberOfPassedSpecs: numberOfPassedSpecs,
|
|
||||||
NumberOfFailedSpecs: numberOfFailedSpecs,
|
|
||||||
NumberOfFlakedSpecs: numberOfFlakedSpecs,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runner *SpecRunner) suiteWillBeginSummary() *types.SuiteSummary {
|
|
||||||
numTotal, known := runner.iterator.NumberOfSpecsToProcessIfKnown()
|
|
||||||
if !known {
|
|
||||||
numTotal = -1
|
|
||||||
}
|
|
||||||
|
|
||||||
numToRun, known := runner.iterator.NumberOfSpecsThatWillBeRunIfKnown()
|
|
||||||
if !known {
|
|
||||||
numToRun = -1
|
|
||||||
}
|
|
||||||
|
|
||||||
return &types.SuiteSummary{
|
|
||||||
SuiteDescription: runner.description,
|
|
||||||
SuiteID: runner.suiteID,
|
|
||||||
|
|
||||||
NumberOfSpecsBeforeParallelization: runner.iterator.NumberOfSpecsPriorToIteration(),
|
|
||||||
NumberOfTotalSpecs: numTotal,
|
|
||||||
NumberOfSpecsThatWillBeRun: numToRun,
|
|
||||||
NumberOfPendingSpecs: -1,
|
|
||||||
NumberOfSkippedSpecs: -1,
|
|
||||||
NumberOfPassedSpecs: -1,
|
|
||||||
NumberOfFailedSpecs: -1,
|
|
||||||
NumberOfFlakedSpecs: -1,
|
|
||||||
}
|
|
||||||
}
|
|
183
vendor/github.com/onsi/ginkgo/internal/suite/suite.go
generated
vendored
183
vendor/github.com/onsi/ginkgo/internal/suite/suite.go
generated
vendored
|
@ -1,183 +0,0 @@
|
||||||
package suite
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/internal/spec_iterator"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/config"
|
|
||||||
"github.com/onsi/ginkgo/internal/containernode"
|
|
||||||
"github.com/onsi/ginkgo/internal/failer"
|
|
||||||
"github.com/onsi/ginkgo/internal/leafnodes"
|
|
||||||
"github.com/onsi/ginkgo/internal/spec"
|
|
||||||
"github.com/onsi/ginkgo/internal/specrunner"
|
|
||||||
"github.com/onsi/ginkgo/internal/writer"
|
|
||||||
"github.com/onsi/ginkgo/reporters"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ginkgoTestingT interface {
|
|
||||||
Fail()
|
|
||||||
}
|
|
||||||
|
|
||||||
type Suite struct {
|
|
||||||
topLevelContainer *containernode.ContainerNode
|
|
||||||
currentContainer *containernode.ContainerNode
|
|
||||||
containerIndex int
|
|
||||||
beforeSuiteNode leafnodes.SuiteNode
|
|
||||||
afterSuiteNode leafnodes.SuiteNode
|
|
||||||
runner *specrunner.SpecRunner
|
|
||||||
failer *failer.Failer
|
|
||||||
running bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(failer *failer.Failer) *Suite {
|
|
||||||
topLevelContainer := containernode.New("[Top Level]", types.FlagTypeNone, types.CodeLocation{})
|
|
||||||
|
|
||||||
return &Suite{
|
|
||||||
topLevelContainer: topLevelContainer,
|
|
||||||
currentContainer: topLevelContainer,
|
|
||||||
failer: failer,
|
|
||||||
containerIndex: 1,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *Suite) Run(t ginkgoTestingT, description string, reporters []reporters.Reporter, writer writer.WriterInterface, config config.GinkgoConfigType) (bool, bool) {
|
|
||||||
if config.ParallelTotal < 1 {
|
|
||||||
panic("ginkgo.parallel.total must be >= 1")
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.ParallelNode > config.ParallelTotal || config.ParallelNode < 1 {
|
|
||||||
panic("ginkgo.parallel.node is one-indexed and must be <= ginkgo.parallel.total")
|
|
||||||
}
|
|
||||||
|
|
||||||
r := rand.New(rand.NewSource(config.RandomSeed))
|
|
||||||
suite.topLevelContainer.Shuffle(r)
|
|
||||||
iterator, hasProgrammaticFocus := suite.generateSpecsIterator(description, config)
|
|
||||||
suite.runner = specrunner.New(description, suite.beforeSuiteNode, iterator, suite.afterSuiteNode, reporters, writer, config)
|
|
||||||
|
|
||||||
suite.running = true
|
|
||||||
success := suite.runner.Run()
|
|
||||||
if !success {
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
return success, hasProgrammaticFocus
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *Suite) generateSpecsIterator(description string, config config.GinkgoConfigType) (spec_iterator.SpecIterator, bool) {
|
|
||||||
specsSlice := []*spec.Spec{}
|
|
||||||
suite.topLevelContainer.BackPropagateProgrammaticFocus()
|
|
||||||
for _, collatedNodes := range suite.topLevelContainer.Collate() {
|
|
||||||
specsSlice = append(specsSlice, spec.New(collatedNodes.Subject, collatedNodes.Containers, config.EmitSpecProgress))
|
|
||||||
}
|
|
||||||
|
|
||||||
specs := spec.NewSpecs(specsSlice)
|
|
||||||
specs.RegexScansFilePath = config.RegexScansFilePath
|
|
||||||
|
|
||||||
if config.RandomizeAllSpecs {
|
|
||||||
specs.Shuffle(rand.New(rand.NewSource(config.RandomSeed)))
|
|
||||||
}
|
|
||||||
|
|
||||||
specs.ApplyFocus(description, config.FocusString, config.SkipString)
|
|
||||||
|
|
||||||
if config.SkipMeasurements {
|
|
||||||
specs.SkipMeasurements()
|
|
||||||
}
|
|
||||||
|
|
||||||
var iterator spec_iterator.SpecIterator
|
|
||||||
|
|
||||||
if config.ParallelTotal > 1 {
|
|
||||||
iterator = spec_iterator.NewParallelIterator(specs.Specs(), config.SyncHost)
|
|
||||||
resp, err := http.Get(config.SyncHost + "/has-counter")
|
|
||||||
if err != nil || resp.StatusCode != http.StatusOK {
|
|
||||||
iterator = spec_iterator.NewShardedParallelIterator(specs.Specs(), config.ParallelTotal, config.ParallelNode)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
iterator = spec_iterator.NewSerialIterator(specs.Specs())
|
|
||||||
}
|
|
||||||
|
|
||||||
return iterator, specs.HasProgrammaticFocus()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *Suite) CurrentRunningSpecSummary() (*types.SpecSummary, bool) {
|
|
||||||
return suite.runner.CurrentSpecSummary()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *Suite) SetBeforeSuiteNode(body interface{}, codeLocation types.CodeLocation, timeout time.Duration) {
|
|
||||||
if suite.beforeSuiteNode != nil {
|
|
||||||
panic("You may only call BeforeSuite once!")
|
|
||||||
}
|
|
||||||
suite.beforeSuiteNode = leafnodes.NewBeforeSuiteNode(body, codeLocation, timeout, suite.failer)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *Suite) SetAfterSuiteNode(body interface{}, codeLocation types.CodeLocation, timeout time.Duration) {
|
|
||||||
if suite.afterSuiteNode != nil {
|
|
||||||
panic("You may only call AfterSuite once!")
|
|
||||||
}
|
|
||||||
suite.afterSuiteNode = leafnodes.NewAfterSuiteNode(body, codeLocation, timeout, suite.failer)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *Suite) SetSynchronizedBeforeSuiteNode(bodyA interface{}, bodyB interface{}, codeLocation types.CodeLocation, timeout time.Duration) {
|
|
||||||
if suite.beforeSuiteNode != nil {
|
|
||||||
panic("You may only call BeforeSuite once!")
|
|
||||||
}
|
|
||||||
suite.beforeSuiteNode = leafnodes.NewSynchronizedBeforeSuiteNode(bodyA, bodyB, codeLocation, timeout, suite.failer)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *Suite) SetSynchronizedAfterSuiteNode(bodyA interface{}, bodyB interface{}, codeLocation types.CodeLocation, timeout time.Duration) {
|
|
||||||
if suite.afterSuiteNode != nil {
|
|
||||||
panic("You may only call AfterSuite once!")
|
|
||||||
}
|
|
||||||
suite.afterSuiteNode = leafnodes.NewSynchronizedAfterSuiteNode(bodyA, bodyB, codeLocation, timeout, suite.failer)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *Suite) PushContainerNode(text string, body func(), flag types.FlagType, codeLocation types.CodeLocation) {
|
|
||||||
container := containernode.New(text, flag, codeLocation)
|
|
||||||
suite.currentContainer.PushContainerNode(container)
|
|
||||||
|
|
||||||
previousContainer := suite.currentContainer
|
|
||||||
suite.currentContainer = container
|
|
||||||
suite.containerIndex++
|
|
||||||
|
|
||||||
body()
|
|
||||||
|
|
||||||
suite.containerIndex--
|
|
||||||
suite.currentContainer = previousContainer
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *Suite) PushItNode(text string, body interface{}, flag types.FlagType, codeLocation types.CodeLocation, timeout time.Duration) {
|
|
||||||
if suite.running {
|
|
||||||
suite.failer.Fail("You may only call It from within a Describe, Context or When", codeLocation)
|
|
||||||
}
|
|
||||||
suite.currentContainer.PushSubjectNode(leafnodes.NewItNode(text, body, flag, codeLocation, timeout, suite.failer, suite.containerIndex))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *Suite) PushMeasureNode(text string, body interface{}, flag types.FlagType, codeLocation types.CodeLocation, samples int) {
|
|
||||||
if suite.running {
|
|
||||||
suite.failer.Fail("You may only call Measure from within a Describe, Context or When", codeLocation)
|
|
||||||
}
|
|
||||||
suite.currentContainer.PushSubjectNode(leafnodes.NewMeasureNode(text, body, flag, codeLocation, samples, suite.failer, suite.containerIndex))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *Suite) PushBeforeEachNode(body interface{}, codeLocation types.CodeLocation, timeout time.Duration) {
|
|
||||||
if suite.running {
|
|
||||||
suite.failer.Fail("You may only call BeforeEach from within a Describe, Context or When", codeLocation)
|
|
||||||
}
|
|
||||||
suite.currentContainer.PushSetupNode(leafnodes.NewBeforeEachNode(body, codeLocation, timeout, suite.failer, suite.containerIndex))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *Suite) PushJustBeforeEachNode(body interface{}, codeLocation types.CodeLocation, timeout time.Duration) {
|
|
||||||
if suite.running {
|
|
||||||
suite.failer.Fail("You may only call JustBeforeEach from within a Describe, Context or When", codeLocation)
|
|
||||||
}
|
|
||||||
suite.currentContainer.PushSetupNode(leafnodes.NewJustBeforeEachNode(body, codeLocation, timeout, suite.failer, suite.containerIndex))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *Suite) PushAfterEachNode(body interface{}, codeLocation types.CodeLocation, timeout time.Duration) {
|
|
||||||
if suite.running {
|
|
||||||
suite.failer.Fail("You may only call AfterEach from within a Describe, Context or When", codeLocation)
|
|
||||||
}
|
|
||||||
suite.currentContainer.PushSetupNode(leafnodes.NewAfterEachNode(body, codeLocation, timeout, suite.failer, suite.containerIndex))
|
|
||||||
}
|
|
76
vendor/github.com/onsi/ginkgo/internal/testingtproxy/testing_t_proxy.go
generated
vendored
76
vendor/github.com/onsi/ginkgo/internal/testingtproxy/testing_t_proxy.go
generated
vendored
|
@ -1,76 +0,0 @@
|
||||||
package testingtproxy
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
type failFunc func(message string, callerSkip ...int)
|
|
||||||
|
|
||||||
func New(writer io.Writer, fail failFunc, offset int) *ginkgoTestingTProxy {
|
|
||||||
return &ginkgoTestingTProxy{
|
|
||||||
fail: fail,
|
|
||||||
offset: offset,
|
|
||||||
writer: writer,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type ginkgoTestingTProxy struct {
|
|
||||||
fail failFunc
|
|
||||||
offset int
|
|
||||||
writer io.Writer
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *ginkgoTestingTProxy) Error(args ...interface{}) {
|
|
||||||
t.fail(fmt.Sprintln(args...), t.offset)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *ginkgoTestingTProxy) Errorf(format string, args ...interface{}) {
|
|
||||||
t.fail(fmt.Sprintf(format, args...), t.offset)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *ginkgoTestingTProxy) Fail() {
|
|
||||||
t.fail("failed", t.offset)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *ginkgoTestingTProxy) FailNow() {
|
|
||||||
t.fail("failed", t.offset)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *ginkgoTestingTProxy) Fatal(args ...interface{}) {
|
|
||||||
t.fail(fmt.Sprintln(args...), t.offset)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *ginkgoTestingTProxy) Fatalf(format string, args ...interface{}) {
|
|
||||||
t.fail(fmt.Sprintf(format, args...), t.offset)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *ginkgoTestingTProxy) Log(args ...interface{}) {
|
|
||||||
fmt.Fprintln(t.writer, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *ginkgoTestingTProxy) Logf(format string, args ...interface{}) {
|
|
||||||
t.Log(fmt.Sprintf(format, args...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *ginkgoTestingTProxy) Failed() bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *ginkgoTestingTProxy) Parallel() {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *ginkgoTestingTProxy) Skip(args ...interface{}) {
|
|
||||||
fmt.Println(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *ginkgoTestingTProxy) Skipf(format string, args ...interface{}) {
|
|
||||||
t.Skip(fmt.Sprintf(format, args...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *ginkgoTestingTProxy) SkipNow() {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *ginkgoTestingTProxy) Skipped() bool {
|
|
||||||
return false
|
|
||||||
}
|
|
36
vendor/github.com/onsi/ginkgo/internal/writer/fake_writer.go
generated
vendored
36
vendor/github.com/onsi/ginkgo/internal/writer/fake_writer.go
generated
vendored
|
@ -1,36 +0,0 @@
|
||||||
package writer
|
|
||||||
|
|
||||||
type FakeGinkgoWriter struct {
|
|
||||||
EventStream []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewFake() *FakeGinkgoWriter {
|
|
||||||
return &FakeGinkgoWriter{
|
|
||||||
EventStream: []string{},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (writer *FakeGinkgoWriter) AddEvent(event string) {
|
|
||||||
writer.EventStream = append(writer.EventStream, event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (writer *FakeGinkgoWriter) Truncate() {
|
|
||||||
writer.EventStream = append(writer.EventStream, "TRUNCATE")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (writer *FakeGinkgoWriter) DumpOut() {
|
|
||||||
writer.EventStream = append(writer.EventStream, "DUMP")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (writer *FakeGinkgoWriter) DumpOutWithHeader(header string) {
|
|
||||||
writer.EventStream = append(writer.EventStream, "DUMP_WITH_HEADER: "+header)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (writer *FakeGinkgoWriter) Bytes() []byte {
|
|
||||||
writer.EventStream = append(writer.EventStream, "BYTES")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (writer *FakeGinkgoWriter) Write(data []byte) (n int, err error) {
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
89
vendor/github.com/onsi/ginkgo/internal/writer/writer.go
generated
vendored
89
vendor/github.com/onsi/ginkgo/internal/writer/writer.go
generated
vendored
|
@ -1,89 +0,0 @@
|
||||||
package writer
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"io"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
type WriterInterface interface {
|
|
||||||
io.Writer
|
|
||||||
|
|
||||||
Truncate()
|
|
||||||
DumpOut()
|
|
||||||
DumpOutWithHeader(header string)
|
|
||||||
Bytes() []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
type Writer struct {
|
|
||||||
buffer *bytes.Buffer
|
|
||||||
outWriter io.Writer
|
|
||||||
lock *sync.Mutex
|
|
||||||
stream bool
|
|
||||||
redirector io.Writer
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(outWriter io.Writer) *Writer {
|
|
||||||
return &Writer{
|
|
||||||
buffer: &bytes.Buffer{},
|
|
||||||
lock: &sync.Mutex{},
|
|
||||||
outWriter: outWriter,
|
|
||||||
stream: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Writer) AndRedirectTo(writer io.Writer) {
|
|
||||||
w.redirector = writer
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Writer) SetStream(stream bool) {
|
|
||||||
w.lock.Lock()
|
|
||||||
defer w.lock.Unlock()
|
|
||||||
w.stream = stream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Writer) Write(b []byte) (n int, err error) {
|
|
||||||
w.lock.Lock()
|
|
||||||
defer w.lock.Unlock()
|
|
||||||
|
|
||||||
n, err = w.buffer.Write(b)
|
|
||||||
if w.redirector != nil {
|
|
||||||
w.redirector.Write(b)
|
|
||||||
}
|
|
||||||
if w.stream {
|
|
||||||
return w.outWriter.Write(b)
|
|
||||||
}
|
|
||||||
return n, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Writer) Truncate() {
|
|
||||||
w.lock.Lock()
|
|
||||||
defer w.lock.Unlock()
|
|
||||||
w.buffer.Reset()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Writer) DumpOut() {
|
|
||||||
w.lock.Lock()
|
|
||||||
defer w.lock.Unlock()
|
|
||||||
if !w.stream {
|
|
||||||
w.buffer.WriteTo(w.outWriter)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Writer) Bytes() []byte {
|
|
||||||
w.lock.Lock()
|
|
||||||
defer w.lock.Unlock()
|
|
||||||
b := w.buffer.Bytes()
|
|
||||||
copied := make([]byte, len(b))
|
|
||||||
copy(copied, b)
|
|
||||||
return copied
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Writer) DumpOutWithHeader(header string) {
|
|
||||||
w.lock.Lock()
|
|
||||||
defer w.lock.Unlock()
|
|
||||||
if !w.stream && w.buffer.Len() > 0 {
|
|
||||||
w.outWriter.Write([]byte(header))
|
|
||||||
w.buffer.WriteTo(w.outWriter)
|
|
||||||
}
|
|
||||||
}
|
|
84
vendor/github.com/onsi/ginkgo/reporters/default_reporter.go
generated
vendored
84
vendor/github.com/onsi/ginkgo/reporters/default_reporter.go
generated
vendored
|
@ -1,84 +0,0 @@
|
||||||
/*
|
|
||||||
Ginkgo's Default Reporter
|
|
||||||
|
|
||||||
A number of command line flags are available to tweak Ginkgo's default output.
|
|
||||||
|
|
||||||
These are documented [here](http://onsi.github.io/ginkgo/#running_tests)
|
|
||||||
*/
|
|
||||||
package reporters
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/onsi/ginkgo/config"
|
|
||||||
"github.com/onsi/ginkgo/reporters/stenographer"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type DefaultReporter struct {
|
|
||||||
config config.DefaultReporterConfigType
|
|
||||||
stenographer stenographer.Stenographer
|
|
||||||
specSummaries []*types.SpecSummary
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewDefaultReporter(config config.DefaultReporterConfigType, stenographer stenographer.Stenographer) *DefaultReporter {
|
|
||||||
return &DefaultReporter{
|
|
||||||
config: config,
|
|
||||||
stenographer: stenographer,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *DefaultReporter) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) {
|
|
||||||
reporter.stenographer.AnnounceSuite(summary.SuiteDescription, config.RandomSeed, config.RandomizeAllSpecs, reporter.config.Succinct)
|
|
||||||
if config.ParallelTotal > 1 {
|
|
||||||
reporter.stenographer.AnnounceParallelRun(config.ParallelNode, config.ParallelTotal, reporter.config.Succinct)
|
|
||||||
} else {
|
|
||||||
reporter.stenographer.AnnounceNumberOfSpecs(summary.NumberOfSpecsThatWillBeRun, summary.NumberOfTotalSpecs, reporter.config.Succinct)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *DefaultReporter) BeforeSuiteDidRun(setupSummary *types.SetupSummary) {
|
|
||||||
if setupSummary.State != types.SpecStatePassed {
|
|
||||||
reporter.stenographer.AnnounceBeforeSuiteFailure(setupSummary, reporter.config.Succinct, reporter.config.FullTrace)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *DefaultReporter) AfterSuiteDidRun(setupSummary *types.SetupSummary) {
|
|
||||||
if setupSummary.State != types.SpecStatePassed {
|
|
||||||
reporter.stenographer.AnnounceAfterSuiteFailure(setupSummary, reporter.config.Succinct, reporter.config.FullTrace)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *DefaultReporter) SpecWillRun(specSummary *types.SpecSummary) {
|
|
||||||
if reporter.config.Verbose && !reporter.config.Succinct && specSummary.State != types.SpecStatePending && specSummary.State != types.SpecStateSkipped {
|
|
||||||
reporter.stenographer.AnnounceSpecWillRun(specSummary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *DefaultReporter) SpecDidComplete(specSummary *types.SpecSummary) {
|
|
||||||
switch specSummary.State {
|
|
||||||
case types.SpecStatePassed:
|
|
||||||
if specSummary.IsMeasurement {
|
|
||||||
reporter.stenographer.AnnounceSuccesfulMeasurement(specSummary, reporter.config.Succinct)
|
|
||||||
} else if specSummary.RunTime.Seconds() >= reporter.config.SlowSpecThreshold {
|
|
||||||
reporter.stenographer.AnnounceSuccesfulSlowSpec(specSummary, reporter.config.Succinct)
|
|
||||||
} else {
|
|
||||||
reporter.stenographer.AnnounceSuccesfulSpec(specSummary)
|
|
||||||
}
|
|
||||||
case types.SpecStatePending:
|
|
||||||
reporter.stenographer.AnnouncePendingSpec(specSummary, reporter.config.NoisyPendings && !reporter.config.Succinct)
|
|
||||||
case types.SpecStateSkipped:
|
|
||||||
reporter.stenographer.AnnounceSkippedSpec(specSummary, reporter.config.Succinct || !reporter.config.NoisySkippings, reporter.config.FullTrace)
|
|
||||||
case types.SpecStateTimedOut:
|
|
||||||
reporter.stenographer.AnnounceSpecTimedOut(specSummary, reporter.config.Succinct, reporter.config.FullTrace)
|
|
||||||
case types.SpecStatePanicked:
|
|
||||||
reporter.stenographer.AnnounceSpecPanicked(specSummary, reporter.config.Succinct, reporter.config.FullTrace)
|
|
||||||
case types.SpecStateFailed:
|
|
||||||
reporter.stenographer.AnnounceSpecFailed(specSummary, reporter.config.Succinct, reporter.config.FullTrace)
|
|
||||||
}
|
|
||||||
|
|
||||||
reporter.specSummaries = append(reporter.specSummaries, specSummary)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *DefaultReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {
|
|
||||||
reporter.stenographer.SummarizeFailures(reporter.specSummaries)
|
|
||||||
reporter.stenographer.AnnounceSpecRunCompletion(summary, reporter.config.Succinct)
|
|
||||||
}
|
|
59
vendor/github.com/onsi/ginkgo/reporters/fake_reporter.go
generated
vendored
59
vendor/github.com/onsi/ginkgo/reporters/fake_reporter.go
generated
vendored
|
@ -1,59 +0,0 @@
|
||||||
package reporters
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/onsi/ginkgo/config"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
//FakeReporter is useful for testing purposes
|
|
||||||
type FakeReporter struct {
|
|
||||||
Config config.GinkgoConfigType
|
|
||||||
|
|
||||||
BeginSummary *types.SuiteSummary
|
|
||||||
BeforeSuiteSummary *types.SetupSummary
|
|
||||||
SpecWillRunSummaries []*types.SpecSummary
|
|
||||||
SpecSummaries []*types.SpecSummary
|
|
||||||
AfterSuiteSummary *types.SetupSummary
|
|
||||||
EndSummary *types.SuiteSummary
|
|
||||||
|
|
||||||
SpecWillRunStub func(specSummary *types.SpecSummary)
|
|
||||||
SpecDidCompleteStub func(specSummary *types.SpecSummary)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewFakeReporter() *FakeReporter {
|
|
||||||
return &FakeReporter{
|
|
||||||
SpecWillRunSummaries: make([]*types.SpecSummary, 0),
|
|
||||||
SpecSummaries: make([]*types.SpecSummary, 0),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fakeR *FakeReporter) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) {
|
|
||||||
fakeR.Config = config
|
|
||||||
fakeR.BeginSummary = summary
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fakeR *FakeReporter) BeforeSuiteDidRun(setupSummary *types.SetupSummary) {
|
|
||||||
fakeR.BeforeSuiteSummary = setupSummary
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fakeR *FakeReporter) SpecWillRun(specSummary *types.SpecSummary) {
|
|
||||||
if fakeR.SpecWillRunStub != nil {
|
|
||||||
fakeR.SpecWillRunStub(specSummary)
|
|
||||||
}
|
|
||||||
fakeR.SpecWillRunSummaries = append(fakeR.SpecWillRunSummaries, specSummary)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fakeR *FakeReporter) SpecDidComplete(specSummary *types.SpecSummary) {
|
|
||||||
if fakeR.SpecDidCompleteStub != nil {
|
|
||||||
fakeR.SpecDidCompleteStub(specSummary)
|
|
||||||
}
|
|
||||||
fakeR.SpecSummaries = append(fakeR.SpecSummaries, specSummary)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fakeR *FakeReporter) AfterSuiteDidRun(setupSummary *types.SetupSummary) {
|
|
||||||
fakeR.AfterSuiteSummary = setupSummary
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fakeR *FakeReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {
|
|
||||||
fakeR.EndSummary = summary
|
|
||||||
}
|
|
152
vendor/github.com/onsi/ginkgo/reporters/junit_reporter.go
generated
vendored
152
vendor/github.com/onsi/ginkgo/reporters/junit_reporter.go
generated
vendored
|
@ -1,152 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
JUnit XML Reporter for Ginkgo
|
|
||||||
|
|
||||||
For usage instructions: http://onsi.github.io/ginkgo/#generating_junit_xml_output
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
package reporters
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/xml"
|
|
||||||
"fmt"
|
|
||||||
"math"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/config"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type JUnitTestSuite struct {
|
|
||||||
XMLName xml.Name `xml:"testsuite"`
|
|
||||||
TestCases []JUnitTestCase `xml:"testcase"`
|
|
||||||
Name string `xml:"name,attr"`
|
|
||||||
Tests int `xml:"tests,attr"`
|
|
||||||
Failures int `xml:"failures,attr"`
|
|
||||||
Errors int `xml:"errors,attr"`
|
|
||||||
Time float64 `xml:"time,attr"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type JUnitTestCase struct {
|
|
||||||
Name string `xml:"name,attr"`
|
|
||||||
ClassName string `xml:"classname,attr"`
|
|
||||||
FailureMessage *JUnitFailureMessage `xml:"failure,omitempty"`
|
|
||||||
Skipped *JUnitSkipped `xml:"skipped,omitempty"`
|
|
||||||
Time float64 `xml:"time,attr"`
|
|
||||||
SystemOut string `xml:"system-out,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type JUnitFailureMessage struct {
|
|
||||||
Type string `xml:"type,attr"`
|
|
||||||
Message string `xml:",chardata"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type JUnitSkipped struct {
|
|
||||||
XMLName xml.Name `xml:"skipped"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type JUnitReporter struct {
|
|
||||||
suite JUnitTestSuite
|
|
||||||
filename string
|
|
||||||
testSuiteName string
|
|
||||||
}
|
|
||||||
|
|
||||||
//NewJUnitReporter creates a new JUnit XML reporter. The XML will be stored in the passed in filename.
|
|
||||||
func NewJUnitReporter(filename string) *JUnitReporter {
|
|
||||||
return &JUnitReporter{
|
|
||||||
filename: filename,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *JUnitReporter) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) {
|
|
||||||
reporter.suite = JUnitTestSuite{
|
|
||||||
Name: summary.SuiteDescription,
|
|
||||||
TestCases: []JUnitTestCase{},
|
|
||||||
}
|
|
||||||
reporter.testSuiteName = summary.SuiteDescription
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *JUnitReporter) SpecWillRun(specSummary *types.SpecSummary) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *JUnitReporter) BeforeSuiteDidRun(setupSummary *types.SetupSummary) {
|
|
||||||
reporter.handleSetupSummary("BeforeSuite", setupSummary)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *JUnitReporter) AfterSuiteDidRun(setupSummary *types.SetupSummary) {
|
|
||||||
reporter.handleSetupSummary("AfterSuite", setupSummary)
|
|
||||||
}
|
|
||||||
|
|
||||||
func failureMessage(failure types.SpecFailure) string {
|
|
||||||
return fmt.Sprintf("%s\n%s\n%s", failure.ComponentCodeLocation.String(), failure.Message, failure.Location.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *JUnitReporter) handleSetupSummary(name string, setupSummary *types.SetupSummary) {
|
|
||||||
if setupSummary.State != types.SpecStatePassed {
|
|
||||||
testCase := JUnitTestCase{
|
|
||||||
Name: name,
|
|
||||||
ClassName: reporter.testSuiteName,
|
|
||||||
}
|
|
||||||
|
|
||||||
testCase.FailureMessage = &JUnitFailureMessage{
|
|
||||||
Type: reporter.failureTypeForState(setupSummary.State),
|
|
||||||
Message: failureMessage(setupSummary.Failure),
|
|
||||||
}
|
|
||||||
testCase.SystemOut = setupSummary.CapturedOutput
|
|
||||||
testCase.Time = setupSummary.RunTime.Seconds()
|
|
||||||
reporter.suite.TestCases = append(reporter.suite.TestCases, testCase)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *JUnitReporter) SpecDidComplete(specSummary *types.SpecSummary) {
|
|
||||||
testCase := JUnitTestCase{
|
|
||||||
Name: strings.Join(specSummary.ComponentTexts[1:], " "),
|
|
||||||
ClassName: reporter.testSuiteName,
|
|
||||||
}
|
|
||||||
if specSummary.State == types.SpecStateFailed || specSummary.State == types.SpecStateTimedOut || specSummary.State == types.SpecStatePanicked {
|
|
||||||
testCase.FailureMessage = &JUnitFailureMessage{
|
|
||||||
Type: reporter.failureTypeForState(specSummary.State),
|
|
||||||
Message: failureMessage(specSummary.Failure),
|
|
||||||
}
|
|
||||||
testCase.SystemOut = specSummary.CapturedOutput
|
|
||||||
}
|
|
||||||
if specSummary.State == types.SpecStateSkipped || specSummary.State == types.SpecStatePending {
|
|
||||||
testCase.Skipped = &JUnitSkipped{}
|
|
||||||
}
|
|
||||||
testCase.Time = specSummary.RunTime.Seconds()
|
|
||||||
reporter.suite.TestCases = append(reporter.suite.TestCases, testCase)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *JUnitReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {
|
|
||||||
reporter.suite.Tests = summary.NumberOfSpecsThatWillBeRun
|
|
||||||
reporter.suite.Time = math.Trunc(summary.RunTime.Seconds() * 1000 / 1000)
|
|
||||||
reporter.suite.Failures = summary.NumberOfFailedSpecs
|
|
||||||
reporter.suite.Errors = 0
|
|
||||||
file, err := os.Create(reporter.filename)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Failed to create JUnit report file: %s\n\t%s", reporter.filename, err.Error())
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
file.WriteString(xml.Header)
|
|
||||||
encoder := xml.NewEncoder(file)
|
|
||||||
encoder.Indent(" ", " ")
|
|
||||||
err = encoder.Encode(reporter.suite)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Failed to generate JUnit report\n\t%s", err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *JUnitReporter) failureTypeForState(state types.SpecState) string {
|
|
||||||
switch state {
|
|
||||||
case types.SpecStateFailed:
|
|
||||||
return "Failure"
|
|
||||||
case types.SpecStateTimedOut:
|
|
||||||
return "Timeout"
|
|
||||||
case types.SpecStatePanicked:
|
|
||||||
return "Panic"
|
|
||||||
default:
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
}
|
|
15
vendor/github.com/onsi/ginkgo/reporters/reporter.go
generated
vendored
15
vendor/github.com/onsi/ginkgo/reporters/reporter.go
generated
vendored
|
@ -1,15 +0,0 @@
|
||||||
package reporters
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/onsi/ginkgo/config"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Reporter interface {
|
|
||||||
SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary)
|
|
||||||
BeforeSuiteDidRun(setupSummary *types.SetupSummary)
|
|
||||||
SpecWillRun(specSummary *types.SpecSummary)
|
|
||||||
SpecDidComplete(specSummary *types.SpecSummary)
|
|
||||||
AfterSuiteDidRun(setupSummary *types.SetupSummary)
|
|
||||||
SpecSuiteDidEnd(summary *types.SuiteSummary)
|
|
||||||
}
|
|
64
vendor/github.com/onsi/ginkgo/reporters/stenographer/console_logging.go
generated
vendored
64
vendor/github.com/onsi/ginkgo/reporters/stenographer/console_logging.go
generated
vendored
|
@ -1,64 +0,0 @@
|
||||||
package stenographer
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (s *consoleStenographer) colorize(colorCode string, format string, args ...interface{}) string {
|
|
||||||
var out string
|
|
||||||
|
|
||||||
if len(args) > 0 {
|
|
||||||
out = fmt.Sprintf(format, args...)
|
|
||||||
} else {
|
|
||||||
out = format
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.color {
|
|
||||||
return fmt.Sprintf("%s%s%s", colorCode, out, defaultStyle)
|
|
||||||
} else {
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) printBanner(text string, bannerCharacter string) {
|
|
||||||
fmt.Fprintln(s.w, text)
|
|
||||||
fmt.Fprintln(s.w, strings.Repeat(bannerCharacter, len(text)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) printNewLine() {
|
|
||||||
fmt.Fprintln(s.w, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) printDelimiter() {
|
|
||||||
fmt.Fprintln(s.w, s.colorize(grayColor, "%s", strings.Repeat("-", 30)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) print(indentation int, format string, args ...interface{}) {
|
|
||||||
fmt.Fprint(s.w, s.indent(indentation, format, args...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) println(indentation int, format string, args ...interface{}) {
|
|
||||||
fmt.Fprintln(s.w, s.indent(indentation, format, args...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) indent(indentation int, format string, args ...interface{}) string {
|
|
||||||
var text string
|
|
||||||
|
|
||||||
if len(args) > 0 {
|
|
||||||
text = fmt.Sprintf(format, args...)
|
|
||||||
} else {
|
|
||||||
text = format
|
|
||||||
}
|
|
||||||
|
|
||||||
stringArray := strings.Split(text, "\n")
|
|
||||||
padding := ""
|
|
||||||
if indentation >= 0 {
|
|
||||||
padding = strings.Repeat(" ", indentation)
|
|
||||||
}
|
|
||||||
for i, s := range stringArray {
|
|
||||||
stringArray[i] = fmt.Sprintf("%s%s", padding, s)
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.Join(stringArray, "\n")
|
|
||||||
}
|
|
142
vendor/github.com/onsi/ginkgo/reporters/stenographer/fake_stenographer.go
generated
vendored
142
vendor/github.com/onsi/ginkgo/reporters/stenographer/fake_stenographer.go
generated
vendored
|
@ -1,142 +0,0 @@
|
||||||
package stenographer
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewFakeStenographerCall(method string, args ...interface{}) FakeStenographerCall {
|
|
||||||
return FakeStenographerCall{
|
|
||||||
Method: method,
|
|
||||||
Args: args,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type FakeStenographer struct {
|
|
||||||
calls []FakeStenographerCall
|
|
||||||
lock *sync.Mutex
|
|
||||||
}
|
|
||||||
|
|
||||||
type FakeStenographerCall struct {
|
|
||||||
Method string
|
|
||||||
Args []interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewFakeStenographer() *FakeStenographer {
|
|
||||||
stenographer := &FakeStenographer{
|
|
||||||
lock: &sync.Mutex{},
|
|
||||||
}
|
|
||||||
stenographer.Reset()
|
|
||||||
return stenographer
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) Calls() []FakeStenographerCall {
|
|
||||||
stenographer.lock.Lock()
|
|
||||||
defer stenographer.lock.Unlock()
|
|
||||||
|
|
||||||
return stenographer.calls
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) Reset() {
|
|
||||||
stenographer.lock.Lock()
|
|
||||||
defer stenographer.lock.Unlock()
|
|
||||||
|
|
||||||
stenographer.calls = make([]FakeStenographerCall, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) CallsTo(method string) []FakeStenographerCall {
|
|
||||||
stenographer.lock.Lock()
|
|
||||||
defer stenographer.lock.Unlock()
|
|
||||||
|
|
||||||
results := make([]FakeStenographerCall, 0)
|
|
||||||
for _, call := range stenographer.calls {
|
|
||||||
if call.Method == method {
|
|
||||||
results = append(results, call)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) registerCall(method string, args ...interface{}) {
|
|
||||||
stenographer.lock.Lock()
|
|
||||||
defer stenographer.lock.Unlock()
|
|
||||||
|
|
||||||
stenographer.calls = append(stenographer.calls, NewFakeStenographerCall(method, args...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) AnnounceSuite(description string, randomSeed int64, randomizingAll bool, succinct bool) {
|
|
||||||
stenographer.registerCall("AnnounceSuite", description, randomSeed, randomizingAll, succinct)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) AnnounceAggregatedParallelRun(nodes int, succinct bool) {
|
|
||||||
stenographer.registerCall("AnnounceAggregatedParallelRun", nodes, succinct)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) AnnounceParallelRun(node int, nodes int, succinct bool) {
|
|
||||||
stenographer.registerCall("AnnounceParallelRun", node, nodes, succinct)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) AnnounceNumberOfSpecs(specsToRun int, total int, succinct bool) {
|
|
||||||
stenographer.registerCall("AnnounceNumberOfSpecs", specsToRun, total, succinct)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) AnnounceTotalNumberOfSpecs(total int, succinct bool) {
|
|
||||||
stenographer.registerCall("AnnounceTotalNumberOfSpecs", total, succinct)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) AnnounceSpecRunCompletion(summary *types.SuiteSummary, succinct bool) {
|
|
||||||
stenographer.registerCall("AnnounceSpecRunCompletion", summary, succinct)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) AnnounceSpecWillRun(spec *types.SpecSummary) {
|
|
||||||
stenographer.registerCall("AnnounceSpecWillRun", spec)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) AnnounceBeforeSuiteFailure(summary *types.SetupSummary, succinct bool, fullTrace bool) {
|
|
||||||
stenographer.registerCall("AnnounceBeforeSuiteFailure", summary, succinct, fullTrace)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) AnnounceAfterSuiteFailure(summary *types.SetupSummary, succinct bool, fullTrace bool) {
|
|
||||||
stenographer.registerCall("AnnounceAfterSuiteFailure", summary, succinct, fullTrace)
|
|
||||||
}
|
|
||||||
func (stenographer *FakeStenographer) AnnounceCapturedOutput(output string) {
|
|
||||||
stenographer.registerCall("AnnounceCapturedOutput", output)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) AnnounceSuccesfulSpec(spec *types.SpecSummary) {
|
|
||||||
stenographer.registerCall("AnnounceSuccesfulSpec", spec)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) AnnounceSuccesfulSlowSpec(spec *types.SpecSummary, succinct bool) {
|
|
||||||
stenographer.registerCall("AnnounceSuccesfulSlowSpec", spec, succinct)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) AnnounceSuccesfulMeasurement(spec *types.SpecSummary, succinct bool) {
|
|
||||||
stenographer.registerCall("AnnounceSuccesfulMeasurement", spec, succinct)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) AnnouncePendingSpec(spec *types.SpecSummary, noisy bool) {
|
|
||||||
stenographer.registerCall("AnnouncePendingSpec", spec, noisy)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) AnnounceSkippedSpec(spec *types.SpecSummary, succinct bool, fullTrace bool) {
|
|
||||||
stenographer.registerCall("AnnounceSkippedSpec", spec, succinct, fullTrace)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) AnnounceSpecTimedOut(spec *types.SpecSummary, succinct bool, fullTrace bool) {
|
|
||||||
stenographer.registerCall("AnnounceSpecTimedOut", spec, succinct, fullTrace)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) AnnounceSpecPanicked(spec *types.SpecSummary, succinct bool, fullTrace bool) {
|
|
||||||
stenographer.registerCall("AnnounceSpecPanicked", spec, succinct, fullTrace)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) AnnounceSpecFailed(spec *types.SpecSummary, succinct bool, fullTrace bool) {
|
|
||||||
stenographer.registerCall("AnnounceSpecFailed", spec, succinct, fullTrace)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (stenographer *FakeStenographer) SummarizeFailures(summaries []*types.SpecSummary) {
|
|
||||||
stenographer.registerCall("SummarizeFailures", summaries)
|
|
||||||
}
|
|
572
vendor/github.com/onsi/ginkgo/reporters/stenographer/stenographer.go
generated
vendored
572
vendor/github.com/onsi/ginkgo/reporters/stenographer/stenographer.go
generated
vendored
|
@ -1,572 +0,0 @@
|
||||||
/*
|
|
||||||
The stenographer is used by Ginkgo's reporters to generate output.
|
|
||||||
|
|
||||||
Move along, nothing to see here.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package stenographer
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"runtime"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
const defaultStyle = "\x1b[0m"
|
|
||||||
const boldStyle = "\x1b[1m"
|
|
||||||
const redColor = "\x1b[91m"
|
|
||||||
const greenColor = "\x1b[32m"
|
|
||||||
const yellowColor = "\x1b[33m"
|
|
||||||
const cyanColor = "\x1b[36m"
|
|
||||||
const grayColor = "\x1b[90m"
|
|
||||||
const lightGrayColor = "\x1b[37m"
|
|
||||||
|
|
||||||
type cursorStateType int
|
|
||||||
|
|
||||||
const (
|
|
||||||
cursorStateTop cursorStateType = iota
|
|
||||||
cursorStateStreaming
|
|
||||||
cursorStateMidBlock
|
|
||||||
cursorStateEndBlock
|
|
||||||
)
|
|
||||||
|
|
||||||
type Stenographer interface {
|
|
||||||
AnnounceSuite(description string, randomSeed int64, randomizingAll bool, succinct bool)
|
|
||||||
AnnounceAggregatedParallelRun(nodes int, succinct bool)
|
|
||||||
AnnounceParallelRun(node int, nodes int, succinct bool)
|
|
||||||
AnnounceTotalNumberOfSpecs(total int, succinct bool)
|
|
||||||
AnnounceNumberOfSpecs(specsToRun int, total int, succinct bool)
|
|
||||||
AnnounceSpecRunCompletion(summary *types.SuiteSummary, succinct bool)
|
|
||||||
|
|
||||||
AnnounceSpecWillRun(spec *types.SpecSummary)
|
|
||||||
AnnounceBeforeSuiteFailure(summary *types.SetupSummary, succinct bool, fullTrace bool)
|
|
||||||
AnnounceAfterSuiteFailure(summary *types.SetupSummary, succinct bool, fullTrace bool)
|
|
||||||
|
|
||||||
AnnounceCapturedOutput(output string)
|
|
||||||
|
|
||||||
AnnounceSuccesfulSpec(spec *types.SpecSummary)
|
|
||||||
AnnounceSuccesfulSlowSpec(spec *types.SpecSummary, succinct bool)
|
|
||||||
AnnounceSuccesfulMeasurement(spec *types.SpecSummary, succinct bool)
|
|
||||||
|
|
||||||
AnnouncePendingSpec(spec *types.SpecSummary, noisy bool)
|
|
||||||
AnnounceSkippedSpec(spec *types.SpecSummary, succinct bool, fullTrace bool)
|
|
||||||
|
|
||||||
AnnounceSpecTimedOut(spec *types.SpecSummary, succinct bool, fullTrace bool)
|
|
||||||
AnnounceSpecPanicked(spec *types.SpecSummary, succinct bool, fullTrace bool)
|
|
||||||
AnnounceSpecFailed(spec *types.SpecSummary, succinct bool, fullTrace bool)
|
|
||||||
|
|
||||||
SummarizeFailures(summaries []*types.SpecSummary)
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(color bool, enableFlakes bool, writer io.Writer) Stenographer {
|
|
||||||
denoter := "•"
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
denoter = "+"
|
|
||||||
}
|
|
||||||
return &consoleStenographer{
|
|
||||||
color: color,
|
|
||||||
denoter: denoter,
|
|
||||||
cursorState: cursorStateTop,
|
|
||||||
enableFlakes: enableFlakes,
|
|
||||||
w: writer,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type consoleStenographer struct {
|
|
||||||
color bool
|
|
||||||
denoter string
|
|
||||||
cursorState cursorStateType
|
|
||||||
enableFlakes bool
|
|
||||||
w io.Writer
|
|
||||||
}
|
|
||||||
|
|
||||||
var alternatingColors = []string{defaultStyle, grayColor}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) AnnounceSuite(description string, randomSeed int64, randomizingAll bool, succinct bool) {
|
|
||||||
if succinct {
|
|
||||||
s.print(0, "[%d] %s ", randomSeed, s.colorize(boldStyle, description))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
s.printBanner(fmt.Sprintf("Running Suite: %s", description), "=")
|
|
||||||
s.print(0, "Random Seed: %s", s.colorize(boldStyle, "%d", randomSeed))
|
|
||||||
if randomizingAll {
|
|
||||||
s.print(0, " - Will randomize all specs")
|
|
||||||
}
|
|
||||||
s.printNewLine()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) AnnounceParallelRun(node int, nodes int, succinct bool) {
|
|
||||||
if succinct {
|
|
||||||
s.print(0, "- node #%d ", node)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
s.println(0,
|
|
||||||
"Parallel test node %s/%s.",
|
|
||||||
s.colorize(boldStyle, "%d", node),
|
|
||||||
s.colorize(boldStyle, "%d", nodes),
|
|
||||||
)
|
|
||||||
s.printNewLine()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) AnnounceAggregatedParallelRun(nodes int, succinct bool) {
|
|
||||||
if succinct {
|
|
||||||
s.print(0, "- %d nodes ", nodes)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
s.println(0,
|
|
||||||
"Running in parallel across %s nodes",
|
|
||||||
s.colorize(boldStyle, "%d", nodes),
|
|
||||||
)
|
|
||||||
s.printNewLine()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) AnnounceNumberOfSpecs(specsToRun int, total int, succinct bool) {
|
|
||||||
if succinct {
|
|
||||||
s.print(0, "- %d/%d specs ", specsToRun, total)
|
|
||||||
s.stream()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
s.println(0,
|
|
||||||
"Will run %s of %s specs",
|
|
||||||
s.colorize(boldStyle, "%d", specsToRun),
|
|
||||||
s.colorize(boldStyle, "%d", total),
|
|
||||||
)
|
|
||||||
|
|
||||||
s.printNewLine()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) AnnounceTotalNumberOfSpecs(total int, succinct bool) {
|
|
||||||
if succinct {
|
|
||||||
s.print(0, "- %d specs ", total)
|
|
||||||
s.stream()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
s.println(0,
|
|
||||||
"Will run %s specs",
|
|
||||||
s.colorize(boldStyle, "%d", total),
|
|
||||||
)
|
|
||||||
|
|
||||||
s.printNewLine()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) AnnounceSpecRunCompletion(summary *types.SuiteSummary, succinct bool) {
|
|
||||||
if succinct && summary.SuiteSucceeded {
|
|
||||||
s.print(0, " %s %s ", s.colorize(greenColor, "SUCCESS!"), summary.RunTime)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
s.printNewLine()
|
|
||||||
color := greenColor
|
|
||||||
if !summary.SuiteSucceeded {
|
|
||||||
color = redColor
|
|
||||||
}
|
|
||||||
s.println(0, s.colorize(boldStyle+color, "Ran %d of %d Specs in %.3f seconds", summary.NumberOfSpecsThatWillBeRun, summary.NumberOfTotalSpecs, summary.RunTime.Seconds()))
|
|
||||||
|
|
||||||
status := ""
|
|
||||||
if summary.SuiteSucceeded {
|
|
||||||
status = s.colorize(boldStyle+greenColor, "SUCCESS!")
|
|
||||||
} else {
|
|
||||||
status = s.colorize(boldStyle+redColor, "FAIL!")
|
|
||||||
}
|
|
||||||
|
|
||||||
flakes := ""
|
|
||||||
if s.enableFlakes {
|
|
||||||
flakes = " | " + s.colorize(yellowColor+boldStyle, "%d Flaked", summary.NumberOfFlakedSpecs)
|
|
||||||
}
|
|
||||||
|
|
||||||
s.print(0,
|
|
||||||
"%s -- %s | %s | %s | %s\n",
|
|
||||||
status,
|
|
||||||
s.colorize(greenColor+boldStyle, "%d Passed", summary.NumberOfPassedSpecs),
|
|
||||||
s.colorize(redColor+boldStyle, "%d Failed", summary.NumberOfFailedSpecs)+flakes,
|
|
||||||
s.colorize(yellowColor+boldStyle, "%d Pending", summary.NumberOfPendingSpecs),
|
|
||||||
s.colorize(cyanColor+boldStyle, "%d Skipped", summary.NumberOfSkippedSpecs),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) AnnounceSpecWillRun(spec *types.SpecSummary) {
|
|
||||||
s.startBlock()
|
|
||||||
for i, text := range spec.ComponentTexts[1 : len(spec.ComponentTexts)-1] {
|
|
||||||
s.print(0, s.colorize(alternatingColors[i%2], text)+" ")
|
|
||||||
}
|
|
||||||
|
|
||||||
indentation := 0
|
|
||||||
if len(spec.ComponentTexts) > 2 {
|
|
||||||
indentation = 1
|
|
||||||
s.printNewLine()
|
|
||||||
}
|
|
||||||
index := len(spec.ComponentTexts) - 1
|
|
||||||
s.print(indentation, s.colorize(boldStyle, spec.ComponentTexts[index]))
|
|
||||||
s.printNewLine()
|
|
||||||
s.print(indentation, s.colorize(lightGrayColor, spec.ComponentCodeLocations[index].String()))
|
|
||||||
s.printNewLine()
|
|
||||||
s.midBlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) AnnounceBeforeSuiteFailure(summary *types.SetupSummary, succinct bool, fullTrace bool) {
|
|
||||||
s.announceSetupFailure("BeforeSuite", summary, succinct, fullTrace)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) AnnounceAfterSuiteFailure(summary *types.SetupSummary, succinct bool, fullTrace bool) {
|
|
||||||
s.announceSetupFailure("AfterSuite", summary, succinct, fullTrace)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) announceSetupFailure(name string, summary *types.SetupSummary, succinct bool, fullTrace bool) {
|
|
||||||
s.startBlock()
|
|
||||||
var message string
|
|
||||||
switch summary.State {
|
|
||||||
case types.SpecStateFailed:
|
|
||||||
message = "Failure"
|
|
||||||
case types.SpecStatePanicked:
|
|
||||||
message = "Panic"
|
|
||||||
case types.SpecStateTimedOut:
|
|
||||||
message = "Timeout"
|
|
||||||
}
|
|
||||||
|
|
||||||
s.println(0, s.colorize(redColor+boldStyle, "%s [%.3f seconds]", message, summary.RunTime.Seconds()))
|
|
||||||
|
|
||||||
indentation := s.printCodeLocationBlock([]string{name}, []types.CodeLocation{summary.CodeLocation}, summary.ComponentType, 0, summary.State, true)
|
|
||||||
|
|
||||||
s.printNewLine()
|
|
||||||
s.printFailure(indentation, summary.State, summary.Failure, fullTrace)
|
|
||||||
|
|
||||||
s.endBlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) AnnounceCapturedOutput(output string) {
|
|
||||||
if output == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
s.startBlock()
|
|
||||||
s.println(0, output)
|
|
||||||
s.midBlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) AnnounceSuccesfulSpec(spec *types.SpecSummary) {
|
|
||||||
s.print(0, s.colorize(greenColor, s.denoter))
|
|
||||||
s.stream()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) AnnounceSuccesfulSlowSpec(spec *types.SpecSummary, succinct bool) {
|
|
||||||
s.printBlockWithMessage(
|
|
||||||
s.colorize(greenColor, "%s [SLOW TEST:%.3f seconds]", s.denoter, spec.RunTime.Seconds()),
|
|
||||||
"",
|
|
||||||
spec,
|
|
||||||
succinct,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) AnnounceSuccesfulMeasurement(spec *types.SpecSummary, succinct bool) {
|
|
||||||
s.printBlockWithMessage(
|
|
||||||
s.colorize(greenColor, "%s [MEASUREMENT]", s.denoter),
|
|
||||||
s.measurementReport(spec, succinct),
|
|
||||||
spec,
|
|
||||||
succinct,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) AnnouncePendingSpec(spec *types.SpecSummary, noisy bool) {
|
|
||||||
if noisy {
|
|
||||||
s.printBlockWithMessage(
|
|
||||||
s.colorize(yellowColor, "P [PENDING]"),
|
|
||||||
"",
|
|
||||||
spec,
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
s.print(0, s.colorize(yellowColor, "P"))
|
|
||||||
s.stream()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) AnnounceSkippedSpec(spec *types.SpecSummary, succinct bool, fullTrace bool) {
|
|
||||||
// Skips at runtime will have a non-empty spec.Failure. All others should be succinct.
|
|
||||||
if succinct || spec.Failure == (types.SpecFailure{}) {
|
|
||||||
s.print(0, s.colorize(cyanColor, "S"))
|
|
||||||
s.stream()
|
|
||||||
} else {
|
|
||||||
s.startBlock()
|
|
||||||
s.println(0, s.colorize(cyanColor+boldStyle, "S [SKIPPING]%s [%.3f seconds]", s.failureContext(spec.Failure.ComponentType), spec.RunTime.Seconds()))
|
|
||||||
|
|
||||||
indentation := s.printCodeLocationBlock(spec.ComponentTexts, spec.ComponentCodeLocations, spec.Failure.ComponentType, spec.Failure.ComponentIndex, spec.State, succinct)
|
|
||||||
|
|
||||||
s.printNewLine()
|
|
||||||
s.printSkip(indentation, spec.Failure)
|
|
||||||
s.endBlock()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) AnnounceSpecTimedOut(spec *types.SpecSummary, succinct bool, fullTrace bool) {
|
|
||||||
s.printSpecFailure(fmt.Sprintf("%s... Timeout", s.denoter), spec, succinct, fullTrace)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) AnnounceSpecPanicked(spec *types.SpecSummary, succinct bool, fullTrace bool) {
|
|
||||||
s.printSpecFailure(fmt.Sprintf("%s! Panic", s.denoter), spec, succinct, fullTrace)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) AnnounceSpecFailed(spec *types.SpecSummary, succinct bool, fullTrace bool) {
|
|
||||||
s.printSpecFailure(fmt.Sprintf("%s Failure", s.denoter), spec, succinct, fullTrace)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) SummarizeFailures(summaries []*types.SpecSummary) {
|
|
||||||
failingSpecs := []*types.SpecSummary{}
|
|
||||||
|
|
||||||
for _, summary := range summaries {
|
|
||||||
if summary.HasFailureState() {
|
|
||||||
failingSpecs = append(failingSpecs, summary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(failingSpecs) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
s.printNewLine()
|
|
||||||
s.printNewLine()
|
|
||||||
plural := "s"
|
|
||||||
if len(failingSpecs) == 1 {
|
|
||||||
plural = ""
|
|
||||||
}
|
|
||||||
s.println(0, s.colorize(redColor+boldStyle, "Summarizing %d Failure%s:", len(failingSpecs), plural))
|
|
||||||
for _, summary := range failingSpecs {
|
|
||||||
s.printNewLine()
|
|
||||||
if summary.HasFailureState() {
|
|
||||||
if summary.TimedOut() {
|
|
||||||
s.print(0, s.colorize(redColor+boldStyle, "[Timeout...] "))
|
|
||||||
} else if summary.Panicked() {
|
|
||||||
s.print(0, s.colorize(redColor+boldStyle, "[Panic!] "))
|
|
||||||
} else if summary.Failed() {
|
|
||||||
s.print(0, s.colorize(redColor+boldStyle, "[Fail] "))
|
|
||||||
}
|
|
||||||
s.printSpecContext(summary.ComponentTexts, summary.ComponentCodeLocations, summary.Failure.ComponentType, summary.Failure.ComponentIndex, summary.State, true)
|
|
||||||
s.printNewLine()
|
|
||||||
s.println(0, s.colorize(lightGrayColor, summary.Failure.Location.String()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) startBlock() {
|
|
||||||
if s.cursorState == cursorStateStreaming {
|
|
||||||
s.printNewLine()
|
|
||||||
s.printDelimiter()
|
|
||||||
} else if s.cursorState == cursorStateMidBlock {
|
|
||||||
s.printNewLine()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) midBlock() {
|
|
||||||
s.cursorState = cursorStateMidBlock
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) endBlock() {
|
|
||||||
s.printDelimiter()
|
|
||||||
s.cursorState = cursorStateEndBlock
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) stream() {
|
|
||||||
s.cursorState = cursorStateStreaming
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) printBlockWithMessage(header string, message string, spec *types.SpecSummary, succinct bool) {
|
|
||||||
s.startBlock()
|
|
||||||
s.println(0, header)
|
|
||||||
|
|
||||||
indentation := s.printCodeLocationBlock(spec.ComponentTexts, spec.ComponentCodeLocations, types.SpecComponentTypeInvalid, 0, spec.State, succinct)
|
|
||||||
|
|
||||||
if message != "" {
|
|
||||||
s.printNewLine()
|
|
||||||
s.println(indentation, message)
|
|
||||||
}
|
|
||||||
|
|
||||||
s.endBlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) printSpecFailure(message string, spec *types.SpecSummary, succinct bool, fullTrace bool) {
|
|
||||||
s.startBlock()
|
|
||||||
s.println(0, s.colorize(redColor+boldStyle, "%s%s [%.3f seconds]", message, s.failureContext(spec.Failure.ComponentType), spec.RunTime.Seconds()))
|
|
||||||
|
|
||||||
indentation := s.printCodeLocationBlock(spec.ComponentTexts, spec.ComponentCodeLocations, spec.Failure.ComponentType, spec.Failure.ComponentIndex, spec.State, succinct)
|
|
||||||
|
|
||||||
s.printNewLine()
|
|
||||||
s.printFailure(indentation, spec.State, spec.Failure, fullTrace)
|
|
||||||
s.endBlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) failureContext(failedComponentType types.SpecComponentType) string {
|
|
||||||
switch failedComponentType {
|
|
||||||
case types.SpecComponentTypeBeforeSuite:
|
|
||||||
return " in Suite Setup (BeforeSuite)"
|
|
||||||
case types.SpecComponentTypeAfterSuite:
|
|
||||||
return " in Suite Teardown (AfterSuite)"
|
|
||||||
case types.SpecComponentTypeBeforeEach:
|
|
||||||
return " in Spec Setup (BeforeEach)"
|
|
||||||
case types.SpecComponentTypeJustBeforeEach:
|
|
||||||
return " in Spec Setup (JustBeforeEach)"
|
|
||||||
case types.SpecComponentTypeAfterEach:
|
|
||||||
return " in Spec Teardown (AfterEach)"
|
|
||||||
}
|
|
||||||
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) printSkip(indentation int, spec types.SpecFailure) {
|
|
||||||
s.println(indentation, s.colorize(cyanColor, spec.Message))
|
|
||||||
s.printNewLine()
|
|
||||||
s.println(indentation, spec.Location.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) printFailure(indentation int, state types.SpecState, failure types.SpecFailure, fullTrace bool) {
|
|
||||||
if state == types.SpecStatePanicked {
|
|
||||||
s.println(indentation, s.colorize(redColor+boldStyle, failure.Message))
|
|
||||||
s.println(indentation, s.colorize(redColor, failure.ForwardedPanic))
|
|
||||||
s.println(indentation, failure.Location.String())
|
|
||||||
s.printNewLine()
|
|
||||||
s.println(indentation, s.colorize(redColor, "Full Stack Trace"))
|
|
||||||
s.println(indentation, failure.Location.FullStackTrace)
|
|
||||||
} else {
|
|
||||||
s.println(indentation, s.colorize(redColor, failure.Message))
|
|
||||||
s.printNewLine()
|
|
||||||
s.println(indentation, failure.Location.String())
|
|
||||||
if fullTrace {
|
|
||||||
s.printNewLine()
|
|
||||||
s.println(indentation, s.colorize(redColor, "Full Stack Trace"))
|
|
||||||
s.println(indentation, failure.Location.FullStackTrace)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) printSpecContext(componentTexts []string, componentCodeLocations []types.CodeLocation, failedComponentType types.SpecComponentType, failedComponentIndex int, state types.SpecState, succinct bool) int {
|
|
||||||
startIndex := 1
|
|
||||||
indentation := 0
|
|
||||||
|
|
||||||
if len(componentTexts) == 1 {
|
|
||||||
startIndex = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := startIndex; i < len(componentTexts); i++ {
|
|
||||||
if (state.IsFailure() || state == types.SpecStateSkipped) && i == failedComponentIndex {
|
|
||||||
color := redColor
|
|
||||||
if state == types.SpecStateSkipped {
|
|
||||||
color = cyanColor
|
|
||||||
}
|
|
||||||
blockType := ""
|
|
||||||
switch failedComponentType {
|
|
||||||
case types.SpecComponentTypeBeforeSuite:
|
|
||||||
blockType = "BeforeSuite"
|
|
||||||
case types.SpecComponentTypeAfterSuite:
|
|
||||||
blockType = "AfterSuite"
|
|
||||||
case types.SpecComponentTypeBeforeEach:
|
|
||||||
blockType = "BeforeEach"
|
|
||||||
case types.SpecComponentTypeJustBeforeEach:
|
|
||||||
blockType = "JustBeforeEach"
|
|
||||||
case types.SpecComponentTypeAfterEach:
|
|
||||||
blockType = "AfterEach"
|
|
||||||
case types.SpecComponentTypeIt:
|
|
||||||
blockType = "It"
|
|
||||||
case types.SpecComponentTypeMeasure:
|
|
||||||
blockType = "Measurement"
|
|
||||||
}
|
|
||||||
if succinct {
|
|
||||||
s.print(0, s.colorize(color+boldStyle, "[%s] %s ", blockType, componentTexts[i]))
|
|
||||||
} else {
|
|
||||||
s.println(indentation, s.colorize(color+boldStyle, "%s [%s]", componentTexts[i], blockType))
|
|
||||||
s.println(indentation, s.colorize(grayColor, "%s", componentCodeLocations[i]))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if succinct {
|
|
||||||
s.print(0, s.colorize(alternatingColors[i%2], "%s ", componentTexts[i]))
|
|
||||||
} else {
|
|
||||||
s.println(indentation, componentTexts[i])
|
|
||||||
s.println(indentation, s.colorize(grayColor, "%s", componentCodeLocations[i]))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
indentation++
|
|
||||||
}
|
|
||||||
|
|
||||||
return indentation
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) printCodeLocationBlock(componentTexts []string, componentCodeLocations []types.CodeLocation, failedComponentType types.SpecComponentType, failedComponentIndex int, state types.SpecState, succinct bool) int {
|
|
||||||
indentation := s.printSpecContext(componentTexts, componentCodeLocations, failedComponentType, failedComponentIndex, state, succinct)
|
|
||||||
|
|
||||||
if succinct {
|
|
||||||
if len(componentTexts) > 0 {
|
|
||||||
s.printNewLine()
|
|
||||||
s.print(0, s.colorize(lightGrayColor, "%s", componentCodeLocations[len(componentCodeLocations)-1]))
|
|
||||||
}
|
|
||||||
s.printNewLine()
|
|
||||||
indentation = 1
|
|
||||||
} else {
|
|
||||||
indentation--
|
|
||||||
}
|
|
||||||
|
|
||||||
return indentation
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) orderedMeasurementKeys(measurements map[string]*types.SpecMeasurement) []string {
|
|
||||||
orderedKeys := make([]string, len(measurements))
|
|
||||||
for key, measurement := range measurements {
|
|
||||||
orderedKeys[measurement.Order] = key
|
|
||||||
}
|
|
||||||
return orderedKeys
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *consoleStenographer) measurementReport(spec *types.SpecSummary, succinct bool) string {
|
|
||||||
if len(spec.Measurements) == 0 {
|
|
||||||
return "Found no measurements"
|
|
||||||
}
|
|
||||||
|
|
||||||
message := []string{}
|
|
||||||
orderedKeys := s.orderedMeasurementKeys(spec.Measurements)
|
|
||||||
|
|
||||||
if succinct {
|
|
||||||
message = append(message, fmt.Sprintf("%s samples:", s.colorize(boldStyle, "%d", spec.NumberOfSamples)))
|
|
||||||
for _, key := range orderedKeys {
|
|
||||||
measurement := spec.Measurements[key]
|
|
||||||
message = append(message, fmt.Sprintf(" %s - %s: %s%s, %s: %s%s ± %s%s, %s: %s%s",
|
|
||||||
s.colorize(boldStyle, "%s", measurement.Name),
|
|
||||||
measurement.SmallestLabel,
|
|
||||||
s.colorize(greenColor, measurement.PrecisionFmt(), measurement.Smallest),
|
|
||||||
measurement.Units,
|
|
||||||
measurement.AverageLabel,
|
|
||||||
s.colorize(cyanColor, measurement.PrecisionFmt(), measurement.Average),
|
|
||||||
measurement.Units,
|
|
||||||
s.colorize(cyanColor, measurement.PrecisionFmt(), measurement.StdDeviation),
|
|
||||||
measurement.Units,
|
|
||||||
measurement.LargestLabel,
|
|
||||||
s.colorize(redColor, measurement.PrecisionFmt(), measurement.Largest),
|
|
||||||
measurement.Units,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
message = append(message, fmt.Sprintf("Ran %s samples:", s.colorize(boldStyle, "%d", spec.NumberOfSamples)))
|
|
||||||
for _, key := range orderedKeys {
|
|
||||||
measurement := spec.Measurements[key]
|
|
||||||
info := ""
|
|
||||||
if measurement.Info != nil {
|
|
||||||
message = append(message, fmt.Sprintf("%v", measurement.Info))
|
|
||||||
}
|
|
||||||
|
|
||||||
message = append(message, fmt.Sprintf("%s:\n%s %s: %s%s\n %s: %s%s\n %s: %s%s ± %s%s",
|
|
||||||
s.colorize(boldStyle, "%s", measurement.Name),
|
|
||||||
info,
|
|
||||||
measurement.SmallestLabel,
|
|
||||||
s.colorize(greenColor, measurement.PrecisionFmt(), measurement.Smallest),
|
|
||||||
measurement.Units,
|
|
||||||
measurement.LargestLabel,
|
|
||||||
s.colorize(redColor, measurement.PrecisionFmt(), measurement.Largest),
|
|
||||||
measurement.Units,
|
|
||||||
measurement.AverageLabel,
|
|
||||||
s.colorize(cyanColor, measurement.PrecisionFmt(), measurement.Average),
|
|
||||||
measurement.Units,
|
|
||||||
s.colorize(cyanColor, measurement.PrecisionFmt(), measurement.StdDeviation),
|
|
||||||
measurement.Units,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.Join(message, "\n")
|
|
||||||
}
|
|
21
vendor/github.com/onsi/ginkgo/reporters/stenographer/support/go-colorable/LICENSE
generated
vendored
21
vendor/github.com/onsi/ginkgo/reporters/stenographer/support/go-colorable/LICENSE
generated
vendored
|
@ -1,21 +0,0 @@
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2016 Yasuhiro Matsumoto
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
|
@ -1,24 +0,0 @@
|
||||||
// +build !windows
|
|
||||||
|
|
||||||
package colorable
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewColorable(file *os.File) io.Writer {
|
|
||||||
if file == nil {
|
|
||||||
panic("nil passed instead of *os.File to NewColorable()")
|
|
||||||
}
|
|
||||||
|
|
||||||
return file
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewColorableStdout() io.Writer {
|
|
||||||
return os.Stdout
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewColorableStderr() io.Writer {
|
|
||||||
return os.Stderr
|
|
||||||
}
|
|
|
@ -1,783 +0,0 @@
|
||||||
package colorable
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"math"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
foregroundBlue = 0x1
|
|
||||||
foregroundGreen = 0x2
|
|
||||||
foregroundRed = 0x4
|
|
||||||
foregroundIntensity = 0x8
|
|
||||||
foregroundMask = (foregroundRed | foregroundBlue | foregroundGreen | foregroundIntensity)
|
|
||||||
backgroundBlue = 0x10
|
|
||||||
backgroundGreen = 0x20
|
|
||||||
backgroundRed = 0x40
|
|
||||||
backgroundIntensity = 0x80
|
|
||||||
backgroundMask = (backgroundRed | backgroundBlue | backgroundGreen | backgroundIntensity)
|
|
||||||
)
|
|
||||||
|
|
||||||
type wchar uint16
|
|
||||||
type short int16
|
|
||||||
type dword uint32
|
|
||||||
type word uint16
|
|
||||||
|
|
||||||
type coord struct {
|
|
||||||
x short
|
|
||||||
y short
|
|
||||||
}
|
|
||||||
|
|
||||||
type smallRect struct {
|
|
||||||
left short
|
|
||||||
top short
|
|
||||||
right short
|
|
||||||
bottom short
|
|
||||||
}
|
|
||||||
|
|
||||||
type consoleScreenBufferInfo struct {
|
|
||||||
size coord
|
|
||||||
cursorPosition coord
|
|
||||||
attributes word
|
|
||||||
window smallRect
|
|
||||||
maximumWindowSize coord
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
kernel32 = syscall.NewLazyDLL("kernel32.dll")
|
|
||||||
procGetConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo")
|
|
||||||
procSetConsoleTextAttribute = kernel32.NewProc("SetConsoleTextAttribute")
|
|
||||||
procSetConsoleCursorPosition = kernel32.NewProc("SetConsoleCursorPosition")
|
|
||||||
procFillConsoleOutputCharacter = kernel32.NewProc("FillConsoleOutputCharacterW")
|
|
||||||
procFillConsoleOutputAttribute = kernel32.NewProc("FillConsoleOutputAttribute")
|
|
||||||
)
|
|
||||||
|
|
||||||
type Writer struct {
|
|
||||||
out io.Writer
|
|
||||||
handle syscall.Handle
|
|
||||||
lastbuf bytes.Buffer
|
|
||||||
oldattr word
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewColorable(file *os.File) io.Writer {
|
|
||||||
if file == nil {
|
|
||||||
panic("nil passed instead of *os.File to NewColorable()")
|
|
||||||
}
|
|
||||||
|
|
||||||
if isatty.IsTerminal(file.Fd()) {
|
|
||||||
var csbi consoleScreenBufferInfo
|
|
||||||
handle := syscall.Handle(file.Fd())
|
|
||||||
procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
|
|
||||||
return &Writer{out: file, handle: handle, oldattr: csbi.attributes}
|
|
||||||
} else {
|
|
||||||
return file
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewColorableStdout() io.Writer {
|
|
||||||
return NewColorable(os.Stdout)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewColorableStderr() io.Writer {
|
|
||||||
return NewColorable(os.Stderr)
|
|
||||||
}
|
|
||||||
|
|
||||||
var color256 = map[int]int{
|
|
||||||
0: 0x000000,
|
|
||||||
1: 0x800000,
|
|
||||||
2: 0x008000,
|
|
||||||
3: 0x808000,
|
|
||||||
4: 0x000080,
|
|
||||||
5: 0x800080,
|
|
||||||
6: 0x008080,
|
|
||||||
7: 0xc0c0c0,
|
|
||||||
8: 0x808080,
|
|
||||||
9: 0xff0000,
|
|
||||||
10: 0x00ff00,
|
|
||||||
11: 0xffff00,
|
|
||||||
12: 0x0000ff,
|
|
||||||
13: 0xff00ff,
|
|
||||||
14: 0x00ffff,
|
|
||||||
15: 0xffffff,
|
|
||||||
16: 0x000000,
|
|
||||||
17: 0x00005f,
|
|
||||||
18: 0x000087,
|
|
||||||
19: 0x0000af,
|
|
||||||
20: 0x0000d7,
|
|
||||||
21: 0x0000ff,
|
|
||||||
22: 0x005f00,
|
|
||||||
23: 0x005f5f,
|
|
||||||
24: 0x005f87,
|
|
||||||
25: 0x005faf,
|
|
||||||
26: 0x005fd7,
|
|
||||||
27: 0x005fff,
|
|
||||||
28: 0x008700,
|
|
||||||
29: 0x00875f,
|
|
||||||
30: 0x008787,
|
|
||||||
31: 0x0087af,
|
|
||||||
32: 0x0087d7,
|
|
||||||
33: 0x0087ff,
|
|
||||||
34: 0x00af00,
|
|
||||||
35: 0x00af5f,
|
|
||||||
36: 0x00af87,
|
|
||||||
37: 0x00afaf,
|
|
||||||
38: 0x00afd7,
|
|
||||||
39: 0x00afff,
|
|
||||||
40: 0x00d700,
|
|
||||||
41: 0x00d75f,
|
|
||||||
42: 0x00d787,
|
|
||||||
43: 0x00d7af,
|
|
||||||
44: 0x00d7d7,
|
|
||||||
45: 0x00d7ff,
|
|
||||||
46: 0x00ff00,
|
|
||||||
47: 0x00ff5f,
|
|
||||||
48: 0x00ff87,
|
|
||||||
49: 0x00ffaf,
|
|
||||||
50: 0x00ffd7,
|
|
||||||
51: 0x00ffff,
|
|
||||||
52: 0x5f0000,
|
|
||||||
53: 0x5f005f,
|
|
||||||
54: 0x5f0087,
|
|
||||||
55: 0x5f00af,
|
|
||||||
56: 0x5f00d7,
|
|
||||||
57: 0x5f00ff,
|
|
||||||
58: 0x5f5f00,
|
|
||||||
59: 0x5f5f5f,
|
|
||||||
60: 0x5f5f87,
|
|
||||||
61: 0x5f5faf,
|
|
||||||
62: 0x5f5fd7,
|
|
||||||
63: 0x5f5fff,
|
|
||||||
64: 0x5f8700,
|
|
||||||
65: 0x5f875f,
|
|
||||||
66: 0x5f8787,
|
|
||||||
67: 0x5f87af,
|
|
||||||
68: 0x5f87d7,
|
|
||||||
69: 0x5f87ff,
|
|
||||||
70: 0x5faf00,
|
|
||||||
71: 0x5faf5f,
|
|
||||||
72: 0x5faf87,
|
|
||||||
73: 0x5fafaf,
|
|
||||||
74: 0x5fafd7,
|
|
||||||
75: 0x5fafff,
|
|
||||||
76: 0x5fd700,
|
|
||||||
77: 0x5fd75f,
|
|
||||||
78: 0x5fd787,
|
|
||||||
79: 0x5fd7af,
|
|
||||||
80: 0x5fd7d7,
|
|
||||||
81: 0x5fd7ff,
|
|
||||||
82: 0x5fff00,
|
|
||||||
83: 0x5fff5f,
|
|
||||||
84: 0x5fff87,
|
|
||||||
85: 0x5fffaf,
|
|
||||||
86: 0x5fffd7,
|
|
||||||
87: 0x5fffff,
|
|
||||||
88: 0x870000,
|
|
||||||
89: 0x87005f,
|
|
||||||
90: 0x870087,
|
|
||||||
91: 0x8700af,
|
|
||||||
92: 0x8700d7,
|
|
||||||
93: 0x8700ff,
|
|
||||||
94: 0x875f00,
|
|
||||||
95: 0x875f5f,
|
|
||||||
96: 0x875f87,
|
|
||||||
97: 0x875faf,
|
|
||||||
98: 0x875fd7,
|
|
||||||
99: 0x875fff,
|
|
||||||
100: 0x878700,
|
|
||||||
101: 0x87875f,
|
|
||||||
102: 0x878787,
|
|
||||||
103: 0x8787af,
|
|
||||||
104: 0x8787d7,
|
|
||||||
105: 0x8787ff,
|
|
||||||
106: 0x87af00,
|
|
||||||
107: 0x87af5f,
|
|
||||||
108: 0x87af87,
|
|
||||||
109: 0x87afaf,
|
|
||||||
110: 0x87afd7,
|
|
||||||
111: 0x87afff,
|
|
||||||
112: 0x87d700,
|
|
||||||
113: 0x87d75f,
|
|
||||||
114: 0x87d787,
|
|
||||||
115: 0x87d7af,
|
|
||||||
116: 0x87d7d7,
|
|
||||||
117: 0x87d7ff,
|
|
||||||
118: 0x87ff00,
|
|
||||||
119: 0x87ff5f,
|
|
||||||
120: 0x87ff87,
|
|
||||||
121: 0x87ffaf,
|
|
||||||
122: 0x87ffd7,
|
|
||||||
123: 0x87ffff,
|
|
||||||
124: 0xaf0000,
|
|
||||||
125: 0xaf005f,
|
|
||||||
126: 0xaf0087,
|
|
||||||
127: 0xaf00af,
|
|
||||||
128: 0xaf00d7,
|
|
||||||
129: 0xaf00ff,
|
|
||||||
130: 0xaf5f00,
|
|
||||||
131: 0xaf5f5f,
|
|
||||||
132: 0xaf5f87,
|
|
||||||
133: 0xaf5faf,
|
|
||||||
134: 0xaf5fd7,
|
|
||||||
135: 0xaf5fff,
|
|
||||||
136: 0xaf8700,
|
|
||||||
137: 0xaf875f,
|
|
||||||
138: 0xaf8787,
|
|
||||||
139: 0xaf87af,
|
|
||||||
140: 0xaf87d7,
|
|
||||||
141: 0xaf87ff,
|
|
||||||
142: 0xafaf00,
|
|
||||||
143: 0xafaf5f,
|
|
||||||
144: 0xafaf87,
|
|
||||||
145: 0xafafaf,
|
|
||||||
146: 0xafafd7,
|
|
||||||
147: 0xafafff,
|
|
||||||
148: 0xafd700,
|
|
||||||
149: 0xafd75f,
|
|
||||||
150: 0xafd787,
|
|
||||||
151: 0xafd7af,
|
|
||||||
152: 0xafd7d7,
|
|
||||||
153: 0xafd7ff,
|
|
||||||
154: 0xafff00,
|
|
||||||
155: 0xafff5f,
|
|
||||||
156: 0xafff87,
|
|
||||||
157: 0xafffaf,
|
|
||||||
158: 0xafffd7,
|
|
||||||
159: 0xafffff,
|
|
||||||
160: 0xd70000,
|
|
||||||
161: 0xd7005f,
|
|
||||||
162: 0xd70087,
|
|
||||||
163: 0xd700af,
|
|
||||||
164: 0xd700d7,
|
|
||||||
165: 0xd700ff,
|
|
||||||
166: 0xd75f00,
|
|
||||||
167: 0xd75f5f,
|
|
||||||
168: 0xd75f87,
|
|
||||||
169: 0xd75faf,
|
|
||||||
170: 0xd75fd7,
|
|
||||||
171: 0xd75fff,
|
|
||||||
172: 0xd78700,
|
|
||||||
173: 0xd7875f,
|
|
||||||
174: 0xd78787,
|
|
||||||
175: 0xd787af,
|
|
||||||
176: 0xd787d7,
|
|
||||||
177: 0xd787ff,
|
|
||||||
178: 0xd7af00,
|
|
||||||
179: 0xd7af5f,
|
|
||||||
180: 0xd7af87,
|
|
||||||
181: 0xd7afaf,
|
|
||||||
182: 0xd7afd7,
|
|
||||||
183: 0xd7afff,
|
|
||||||
184: 0xd7d700,
|
|
||||||
185: 0xd7d75f,
|
|
||||||
186: 0xd7d787,
|
|
||||||
187: 0xd7d7af,
|
|
||||||
188: 0xd7d7d7,
|
|
||||||
189: 0xd7d7ff,
|
|
||||||
190: 0xd7ff00,
|
|
||||||
191: 0xd7ff5f,
|
|
||||||
192: 0xd7ff87,
|
|
||||||
193: 0xd7ffaf,
|
|
||||||
194: 0xd7ffd7,
|
|
||||||
195: 0xd7ffff,
|
|
||||||
196: 0xff0000,
|
|
||||||
197: 0xff005f,
|
|
||||||
198: 0xff0087,
|
|
||||||
199: 0xff00af,
|
|
||||||
200: 0xff00d7,
|
|
||||||
201: 0xff00ff,
|
|
||||||
202: 0xff5f00,
|
|
||||||
203: 0xff5f5f,
|
|
||||||
204: 0xff5f87,
|
|
||||||
205: 0xff5faf,
|
|
||||||
206: 0xff5fd7,
|
|
||||||
207: 0xff5fff,
|
|
||||||
208: 0xff8700,
|
|
||||||
209: 0xff875f,
|
|
||||||
210: 0xff8787,
|
|
||||||
211: 0xff87af,
|
|
||||||
212: 0xff87d7,
|
|
||||||
213: 0xff87ff,
|
|
||||||
214: 0xffaf00,
|
|
||||||
215: 0xffaf5f,
|
|
||||||
216: 0xffaf87,
|
|
||||||
217: 0xffafaf,
|
|
||||||
218: 0xffafd7,
|
|
||||||
219: 0xffafff,
|
|
||||||
220: 0xffd700,
|
|
||||||
221: 0xffd75f,
|
|
||||||
222: 0xffd787,
|
|
||||||
223: 0xffd7af,
|
|
||||||
224: 0xffd7d7,
|
|
||||||
225: 0xffd7ff,
|
|
||||||
226: 0xffff00,
|
|
||||||
227: 0xffff5f,
|
|
||||||
228: 0xffff87,
|
|
||||||
229: 0xffffaf,
|
|
||||||
230: 0xffffd7,
|
|
||||||
231: 0xffffff,
|
|
||||||
232: 0x080808,
|
|
||||||
233: 0x121212,
|
|
||||||
234: 0x1c1c1c,
|
|
||||||
235: 0x262626,
|
|
||||||
236: 0x303030,
|
|
||||||
237: 0x3a3a3a,
|
|
||||||
238: 0x444444,
|
|
||||||
239: 0x4e4e4e,
|
|
||||||
240: 0x585858,
|
|
||||||
241: 0x626262,
|
|
||||||
242: 0x6c6c6c,
|
|
||||||
243: 0x767676,
|
|
||||||
244: 0x808080,
|
|
||||||
245: 0x8a8a8a,
|
|
||||||
246: 0x949494,
|
|
||||||
247: 0x9e9e9e,
|
|
||||||
248: 0xa8a8a8,
|
|
||||||
249: 0xb2b2b2,
|
|
||||||
250: 0xbcbcbc,
|
|
||||||
251: 0xc6c6c6,
|
|
||||||
252: 0xd0d0d0,
|
|
||||||
253: 0xdadada,
|
|
||||||
254: 0xe4e4e4,
|
|
||||||
255: 0xeeeeee,
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Writer) Write(data []byte) (n int, err error) {
|
|
||||||
var csbi consoleScreenBufferInfo
|
|
||||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
|
||||||
|
|
||||||
er := bytes.NewBuffer(data)
|
|
||||||
loop:
|
|
||||||
for {
|
|
||||||
r1, _, err := procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
|
||||||
if r1 == 0 {
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
|
|
||||||
c1, _, err := er.ReadRune()
|
|
||||||
if err != nil {
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
if c1 != 0x1b {
|
|
||||||
fmt.Fprint(w.out, string(c1))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
c2, _, err := er.ReadRune()
|
|
||||||
if err != nil {
|
|
||||||
w.lastbuf.WriteRune(c1)
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
if c2 != 0x5b {
|
|
||||||
w.lastbuf.WriteRune(c1)
|
|
||||||
w.lastbuf.WriteRune(c2)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
var buf bytes.Buffer
|
|
||||||
var m rune
|
|
||||||
for {
|
|
||||||
c, _, err := er.ReadRune()
|
|
||||||
if err != nil {
|
|
||||||
w.lastbuf.WriteRune(c1)
|
|
||||||
w.lastbuf.WriteRune(c2)
|
|
||||||
w.lastbuf.Write(buf.Bytes())
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
if ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '@' {
|
|
||||||
m = c
|
|
||||||
break
|
|
||||||
}
|
|
||||||
buf.Write([]byte(string(c)))
|
|
||||||
}
|
|
||||||
|
|
||||||
var csbi consoleScreenBufferInfo
|
|
||||||
switch m {
|
|
||||||
case 'A':
|
|
||||||
n, err = strconv.Atoi(buf.String())
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
|
||||||
csbi.cursorPosition.y -= short(n)
|
|
||||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
|
||||||
case 'B':
|
|
||||||
n, err = strconv.Atoi(buf.String())
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
|
||||||
csbi.cursorPosition.y += short(n)
|
|
||||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
|
||||||
case 'C':
|
|
||||||
n, err = strconv.Atoi(buf.String())
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
|
||||||
csbi.cursorPosition.x -= short(n)
|
|
||||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
|
||||||
case 'D':
|
|
||||||
n, err = strconv.Atoi(buf.String())
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if n, err = strconv.Atoi(buf.String()); err == nil {
|
|
||||||
var csbi consoleScreenBufferInfo
|
|
||||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
|
||||||
csbi.cursorPosition.x += short(n)
|
|
||||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
|
||||||
}
|
|
||||||
case 'E':
|
|
||||||
n, err = strconv.Atoi(buf.String())
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
|
||||||
csbi.cursorPosition.x = 0
|
|
||||||
csbi.cursorPosition.y += short(n)
|
|
||||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
|
||||||
case 'F':
|
|
||||||
n, err = strconv.Atoi(buf.String())
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
|
||||||
csbi.cursorPosition.x = 0
|
|
||||||
csbi.cursorPosition.y -= short(n)
|
|
||||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
|
||||||
case 'G':
|
|
||||||
n, err = strconv.Atoi(buf.String())
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
|
||||||
csbi.cursorPosition.x = short(n)
|
|
||||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
|
||||||
case 'H':
|
|
||||||
token := strings.Split(buf.String(), ";")
|
|
||||||
if len(token) != 2 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
n1, err := strconv.Atoi(token[0])
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
n2, err := strconv.Atoi(token[1])
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
csbi.cursorPosition.x = short(n2)
|
|
||||||
csbi.cursorPosition.x = short(n1)
|
|
||||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
|
||||||
case 'J':
|
|
||||||
n, err := strconv.Atoi(buf.String())
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var cursor coord
|
|
||||||
switch n {
|
|
||||||
case 0:
|
|
||||||
cursor = coord{x: csbi.cursorPosition.x, y: csbi.cursorPosition.y}
|
|
||||||
case 1:
|
|
||||||
cursor = coord{x: csbi.window.left, y: csbi.window.top}
|
|
||||||
case 2:
|
|
||||||
cursor = coord{x: csbi.window.left, y: csbi.window.top}
|
|
||||||
}
|
|
||||||
var count, written dword
|
|
||||||
count = dword(csbi.size.x - csbi.cursorPosition.x + (csbi.size.y-csbi.cursorPosition.y)*csbi.size.x)
|
|
||||||
procFillConsoleOutputCharacter.Call(uintptr(w.handle), uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
|
|
||||||
procFillConsoleOutputAttribute.Call(uintptr(w.handle), uintptr(csbi.attributes), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
|
|
||||||
case 'K':
|
|
||||||
n, err := strconv.Atoi(buf.String())
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var cursor coord
|
|
||||||
switch n {
|
|
||||||
case 0:
|
|
||||||
cursor = coord{x: csbi.cursorPosition.x, y: csbi.cursorPosition.y}
|
|
||||||
case 1:
|
|
||||||
cursor = coord{x: csbi.window.left, y: csbi.window.top + csbi.cursorPosition.y}
|
|
||||||
case 2:
|
|
||||||
cursor = coord{x: csbi.window.left, y: csbi.window.top + csbi.cursorPosition.y}
|
|
||||||
}
|
|
||||||
var count, written dword
|
|
||||||
count = dword(csbi.size.x - csbi.cursorPosition.x)
|
|
||||||
procFillConsoleOutputCharacter.Call(uintptr(w.handle), uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
|
|
||||||
procFillConsoleOutputAttribute.Call(uintptr(w.handle), uintptr(csbi.attributes), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
|
|
||||||
case 'm':
|
|
||||||
attr := csbi.attributes
|
|
||||||
cs := buf.String()
|
|
||||||
if cs == "" {
|
|
||||||
procSetConsoleTextAttribute.Call(uintptr(w.handle), uintptr(w.oldattr))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
token := strings.Split(cs, ";")
|
|
||||||
for i := 0; i < len(token); i += 1 {
|
|
||||||
ns := token[i]
|
|
||||||
if n, err = strconv.Atoi(ns); err == nil {
|
|
||||||
switch {
|
|
||||||
case n == 0 || n == 100:
|
|
||||||
attr = w.oldattr
|
|
||||||
case 1 <= n && n <= 5:
|
|
||||||
attr |= foregroundIntensity
|
|
||||||
case n == 7:
|
|
||||||
attr = ((attr & foregroundMask) << 4) | ((attr & backgroundMask) >> 4)
|
|
||||||
case 22 == n || n == 25 || n == 25:
|
|
||||||
attr |= foregroundIntensity
|
|
||||||
case n == 27:
|
|
||||||
attr = ((attr & foregroundMask) << 4) | ((attr & backgroundMask) >> 4)
|
|
||||||
case 30 <= n && n <= 37:
|
|
||||||
attr = (attr & backgroundMask)
|
|
||||||
if (n-30)&1 != 0 {
|
|
||||||
attr |= foregroundRed
|
|
||||||
}
|
|
||||||
if (n-30)&2 != 0 {
|
|
||||||
attr |= foregroundGreen
|
|
||||||
}
|
|
||||||
if (n-30)&4 != 0 {
|
|
||||||
attr |= foregroundBlue
|
|
||||||
}
|
|
||||||
case n == 38: // set foreground color.
|
|
||||||
if i < len(token)-2 && (token[i+1] == "5" || token[i+1] == "05") {
|
|
||||||
if n256, err := strconv.Atoi(token[i+2]); err == nil {
|
|
||||||
if n256foreAttr == nil {
|
|
||||||
n256setup()
|
|
||||||
}
|
|
||||||
attr &= backgroundMask
|
|
||||||
attr |= n256foreAttr[n256]
|
|
||||||
i += 2
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
attr = attr & (w.oldattr & backgroundMask)
|
|
||||||
}
|
|
||||||
case n == 39: // reset foreground color.
|
|
||||||
attr &= backgroundMask
|
|
||||||
attr |= w.oldattr & foregroundMask
|
|
||||||
case 40 <= n && n <= 47:
|
|
||||||
attr = (attr & foregroundMask)
|
|
||||||
if (n-40)&1 != 0 {
|
|
||||||
attr |= backgroundRed
|
|
||||||
}
|
|
||||||
if (n-40)&2 != 0 {
|
|
||||||
attr |= backgroundGreen
|
|
||||||
}
|
|
||||||
if (n-40)&4 != 0 {
|
|
||||||
attr |= backgroundBlue
|
|
||||||
}
|
|
||||||
case n == 48: // set background color.
|
|
||||||
if i < len(token)-2 && token[i+1] == "5" {
|
|
||||||
if n256, err := strconv.Atoi(token[i+2]); err == nil {
|
|
||||||
if n256backAttr == nil {
|
|
||||||
n256setup()
|
|
||||||
}
|
|
||||||
attr &= foregroundMask
|
|
||||||
attr |= n256backAttr[n256]
|
|
||||||
i += 2
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
attr = attr & (w.oldattr & foregroundMask)
|
|
||||||
}
|
|
||||||
case n == 49: // reset foreground color.
|
|
||||||
attr &= foregroundMask
|
|
||||||
attr |= w.oldattr & backgroundMask
|
|
||||||
case 90 <= n && n <= 97:
|
|
||||||
attr = (attr & backgroundMask)
|
|
||||||
attr |= foregroundIntensity
|
|
||||||
if (n-90)&1 != 0 {
|
|
||||||
attr |= foregroundRed
|
|
||||||
}
|
|
||||||
if (n-90)&2 != 0 {
|
|
||||||
attr |= foregroundGreen
|
|
||||||
}
|
|
||||||
if (n-90)&4 != 0 {
|
|
||||||
attr |= foregroundBlue
|
|
||||||
}
|
|
||||||
case 100 <= n && n <= 107:
|
|
||||||
attr = (attr & foregroundMask)
|
|
||||||
attr |= backgroundIntensity
|
|
||||||
if (n-100)&1 != 0 {
|
|
||||||
attr |= backgroundRed
|
|
||||||
}
|
|
||||||
if (n-100)&2 != 0 {
|
|
||||||
attr |= backgroundGreen
|
|
||||||
}
|
|
||||||
if (n-100)&4 != 0 {
|
|
||||||
attr |= backgroundBlue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
procSetConsoleTextAttribute.Call(uintptr(w.handle), uintptr(attr))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return len(data) - w.lastbuf.Len(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type consoleColor struct {
|
|
||||||
rgb int
|
|
||||||
red bool
|
|
||||||
green bool
|
|
||||||
blue bool
|
|
||||||
intensity bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c consoleColor) foregroundAttr() (attr word) {
|
|
||||||
if c.red {
|
|
||||||
attr |= foregroundRed
|
|
||||||
}
|
|
||||||
if c.green {
|
|
||||||
attr |= foregroundGreen
|
|
||||||
}
|
|
||||||
if c.blue {
|
|
||||||
attr |= foregroundBlue
|
|
||||||
}
|
|
||||||
if c.intensity {
|
|
||||||
attr |= foregroundIntensity
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c consoleColor) backgroundAttr() (attr word) {
|
|
||||||
if c.red {
|
|
||||||
attr |= backgroundRed
|
|
||||||
}
|
|
||||||
if c.green {
|
|
||||||
attr |= backgroundGreen
|
|
||||||
}
|
|
||||||
if c.blue {
|
|
||||||
attr |= backgroundBlue
|
|
||||||
}
|
|
||||||
if c.intensity {
|
|
||||||
attr |= backgroundIntensity
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var color16 = []consoleColor{
|
|
||||||
consoleColor{0x000000, false, false, false, false},
|
|
||||||
consoleColor{0x000080, false, false, true, false},
|
|
||||||
consoleColor{0x008000, false, true, false, false},
|
|
||||||
consoleColor{0x008080, false, true, true, false},
|
|
||||||
consoleColor{0x800000, true, false, false, false},
|
|
||||||
consoleColor{0x800080, true, false, true, false},
|
|
||||||
consoleColor{0x808000, true, true, false, false},
|
|
||||||
consoleColor{0xc0c0c0, true, true, true, false},
|
|
||||||
consoleColor{0x808080, false, false, false, true},
|
|
||||||
consoleColor{0x0000ff, false, false, true, true},
|
|
||||||
consoleColor{0x00ff00, false, true, false, true},
|
|
||||||
consoleColor{0x00ffff, false, true, true, true},
|
|
||||||
consoleColor{0xff0000, true, false, false, true},
|
|
||||||
consoleColor{0xff00ff, true, false, true, true},
|
|
||||||
consoleColor{0xffff00, true, true, false, true},
|
|
||||||
consoleColor{0xffffff, true, true, true, true},
|
|
||||||
}
|
|
||||||
|
|
||||||
type hsv struct {
|
|
||||||
h, s, v float32
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a hsv) dist(b hsv) float32 {
|
|
||||||
dh := a.h - b.h
|
|
||||||
switch {
|
|
||||||
case dh > 0.5:
|
|
||||||
dh = 1 - dh
|
|
||||||
case dh < -0.5:
|
|
||||||
dh = -1 - dh
|
|
||||||
}
|
|
||||||
ds := a.s - b.s
|
|
||||||
dv := a.v - b.v
|
|
||||||
return float32(math.Sqrt(float64(dh*dh + ds*ds + dv*dv)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func toHSV(rgb int) hsv {
|
|
||||||
r, g, b := float32((rgb&0xFF0000)>>16)/256.0,
|
|
||||||
float32((rgb&0x00FF00)>>8)/256.0,
|
|
||||||
float32(rgb&0x0000FF)/256.0
|
|
||||||
min, max := minmax3f(r, g, b)
|
|
||||||
h := max - min
|
|
||||||
if h > 0 {
|
|
||||||
if max == r {
|
|
||||||
h = (g - b) / h
|
|
||||||
if h < 0 {
|
|
||||||
h += 6
|
|
||||||
}
|
|
||||||
} else if max == g {
|
|
||||||
h = 2 + (b-r)/h
|
|
||||||
} else {
|
|
||||||
h = 4 + (r-g)/h
|
|
||||||
}
|
|
||||||
}
|
|
||||||
h /= 6.0
|
|
||||||
s := max - min
|
|
||||||
if max != 0 {
|
|
||||||
s /= max
|
|
||||||
}
|
|
||||||
v := max
|
|
||||||
return hsv{h: h, s: s, v: v}
|
|
||||||
}
|
|
||||||
|
|
||||||
type hsvTable []hsv
|
|
||||||
|
|
||||||
func toHSVTable(rgbTable []consoleColor) hsvTable {
|
|
||||||
t := make(hsvTable, len(rgbTable))
|
|
||||||
for i, c := range rgbTable {
|
|
||||||
t[i] = toHSV(c.rgb)
|
|
||||||
}
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t hsvTable) find(rgb int) consoleColor {
|
|
||||||
hsv := toHSV(rgb)
|
|
||||||
n := 7
|
|
||||||
l := float32(5.0)
|
|
||||||
for i, p := range t {
|
|
||||||
d := hsv.dist(p)
|
|
||||||
if d < l {
|
|
||||||
l, n = d, i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return color16[n]
|
|
||||||
}
|
|
||||||
|
|
||||||
func minmax3f(a, b, c float32) (min, max float32) {
|
|
||||||
if a < b {
|
|
||||||
if b < c {
|
|
||||||
return a, c
|
|
||||||
} else if a < c {
|
|
||||||
return a, b
|
|
||||||
} else {
|
|
||||||
return c, b
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if a < c {
|
|
||||||
return b, c
|
|
||||||
} else if b < c {
|
|
||||||
return b, a
|
|
||||||
} else {
|
|
||||||
return c, a
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var n256foreAttr []word
|
|
||||||
var n256backAttr []word
|
|
||||||
|
|
||||||
func n256setup() {
|
|
||||||
n256foreAttr = make([]word, 256)
|
|
||||||
n256backAttr = make([]word, 256)
|
|
||||||
t := toHSVTable(color16)
|
|
||||||
for i, rgb := range color256 {
|
|
||||||
c := t.find(rgb)
|
|
||||||
n256foreAttr[i] = c.foregroundAttr()
|
|
||||||
n256backAttr[i] = c.backgroundAttr()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
package colorable
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
type NonColorable struct {
|
|
||||||
out io.Writer
|
|
||||||
lastbuf bytes.Buffer
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewNonColorable(w io.Writer) io.Writer {
|
|
||||||
return &NonColorable{out: w}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *NonColorable) Write(data []byte) (n int, err error) {
|
|
||||||
er := bytes.NewBuffer(data)
|
|
||||||
loop:
|
|
||||||
for {
|
|
||||||
c1, _, err := er.ReadRune()
|
|
||||||
if err != nil {
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
if c1 != 0x1b {
|
|
||||||
fmt.Fprint(w.out, string(c1))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
c2, _, err := er.ReadRune()
|
|
||||||
if err != nil {
|
|
||||||
w.lastbuf.WriteRune(c1)
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
if c2 != 0x5b {
|
|
||||||
w.lastbuf.WriteRune(c1)
|
|
||||||
w.lastbuf.WriteRune(c2)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
var buf bytes.Buffer
|
|
||||||
for {
|
|
||||||
c, _, err := er.ReadRune()
|
|
||||||
if err != nil {
|
|
||||||
w.lastbuf.WriteRune(c1)
|
|
||||||
w.lastbuf.WriteRune(c2)
|
|
||||||
w.lastbuf.Write(buf.Bytes())
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
if ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '@' {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
buf.Write([]byte(string(c)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return len(data) - w.lastbuf.Len(), nil
|
|
||||||
}
|
|
9
vendor/github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty/LICENSE
generated
vendored
9
vendor/github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty/LICENSE
generated
vendored
|
@ -1,9 +0,0 @@
|
||||||
Copyright (c) Yasuhiro MATSUMOTO <mattn.jp@gmail.com>
|
|
||||||
|
|
||||||
MIT License (Expat)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
2
vendor/github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty/doc.go
generated
vendored
2
vendor/github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty/doc.go
generated
vendored
|
@ -1,2 +0,0 @@
|
||||||
// Package isatty implements interface to isatty
|
|
||||||
package isatty
|
|
|
@ -1,9 +0,0 @@
|
||||||
// +build appengine
|
|
||||||
|
|
||||||
package isatty
|
|
||||||
|
|
||||||
// IsTerminal returns true if the file descriptor is terminal which
|
|
||||||
// is always false on on appengine classic which is a sandboxed PaaS.
|
|
||||||
func IsTerminal(fd uintptr) bool {
|
|
||||||
return false
|
|
||||||
}
|
|
18
vendor/github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty/isatty_bsd.go
generated
vendored
18
vendor/github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty/isatty_bsd.go
generated
vendored
|
@ -1,18 +0,0 @@
|
||||||
// +build darwin freebsd openbsd netbsd
|
|
||||||
// +build !appengine
|
|
||||||
|
|
||||||
package isatty
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
const ioctlReadTermios = syscall.TIOCGETA
|
|
||||||
|
|
||||||
// IsTerminal return true if the file descriptor is terminal.
|
|
||||||
func IsTerminal(fd uintptr) bool {
|
|
||||||
var termios syscall.Termios
|
|
||||||
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
|
|
||||||
return err == 0
|
|
||||||
}
|
|
18
vendor/github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty/isatty_linux.go
generated
vendored
18
vendor/github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty/isatty_linux.go
generated
vendored
|
@ -1,18 +0,0 @@
|
||||||
// +build linux
|
|
||||||
// +build !appengine
|
|
||||||
|
|
||||||
package isatty
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
const ioctlReadTermios = syscall.TCGETS
|
|
||||||
|
|
||||||
// IsTerminal return true if the file descriptor is terminal.
|
|
||||||
func IsTerminal(fd uintptr) bool {
|
|
||||||
var termios syscall.Termios
|
|
||||||
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
|
|
||||||
return err == 0
|
|
||||||
}
|
|
16
vendor/github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty/isatty_solaris.go
generated
vendored
16
vendor/github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty/isatty_solaris.go
generated
vendored
|
@ -1,16 +0,0 @@
|
||||||
// +build solaris
|
|
||||||
// +build !appengine
|
|
||||||
|
|
||||||
package isatty
|
|
||||||
|
|
||||||
import (
|
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
)
|
|
||||||
|
|
||||||
// IsTerminal returns true if the given file descriptor is a terminal.
|
|
||||||
// see: http://src.illumos.org/source/xref/illumos-gate/usr/src/lib/libbc/libc/gen/common/isatty.c
|
|
||||||
func IsTerminal(fd uintptr) bool {
|
|
||||||
var termio unix.Termio
|
|
||||||
err := unix.IoctlSetTermio(int(fd), unix.TCGETA, &termio)
|
|
||||||
return err == nil
|
|
||||||
}
|
|
19
vendor/github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty/isatty_windows.go
generated
vendored
19
vendor/github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty/isatty_windows.go
generated
vendored
|
@ -1,19 +0,0 @@
|
||||||
// +build windows
|
|
||||||
// +build !appengine
|
|
||||||
|
|
||||||
package isatty
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
var kernel32 = syscall.NewLazyDLL("kernel32.dll")
|
|
||||||
var procGetConsoleMode = kernel32.NewProc("GetConsoleMode")
|
|
||||||
|
|
||||||
// IsTerminal return true if the file descriptor is terminal.
|
|
||||||
func IsTerminal(fd uintptr) bool {
|
|
||||||
var st uint32
|
|
||||||
r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, fd, uintptr(unsafe.Pointer(&st)), 0)
|
|
||||||
return r != 0 && e == 0
|
|
||||||
}
|
|
93
vendor/github.com/onsi/ginkgo/reporters/teamcity_reporter.go
generated
vendored
93
vendor/github.com/onsi/ginkgo/reporters/teamcity_reporter.go
generated
vendored
|
@ -1,93 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
TeamCity Reporter for Ginkgo
|
|
||||||
|
|
||||||
Makes use of TeamCity's support for Service Messages
|
|
||||||
http://confluence.jetbrains.com/display/TCD7/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-ReportingTests
|
|
||||||
*/
|
|
||||||
|
|
||||||
package reporters
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/config"
|
|
||||||
"github.com/onsi/ginkgo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
messageId = "##teamcity"
|
|
||||||
)
|
|
||||||
|
|
||||||
type TeamCityReporter struct {
|
|
||||||
writer io.Writer
|
|
||||||
testSuiteName string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewTeamCityReporter(writer io.Writer) *TeamCityReporter {
|
|
||||||
return &TeamCityReporter{
|
|
||||||
writer: writer,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *TeamCityReporter) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) {
|
|
||||||
reporter.testSuiteName = escape(summary.SuiteDescription)
|
|
||||||
fmt.Fprintf(reporter.writer, "%s[testSuiteStarted name='%s']", messageId, reporter.testSuiteName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *TeamCityReporter) BeforeSuiteDidRun(setupSummary *types.SetupSummary) {
|
|
||||||
reporter.handleSetupSummary("BeforeSuite", setupSummary)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *TeamCityReporter) AfterSuiteDidRun(setupSummary *types.SetupSummary) {
|
|
||||||
reporter.handleSetupSummary("AfterSuite", setupSummary)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *TeamCityReporter) handleSetupSummary(name string, setupSummary *types.SetupSummary) {
|
|
||||||
if setupSummary.State != types.SpecStatePassed {
|
|
||||||
testName := escape(name)
|
|
||||||
fmt.Fprintf(reporter.writer, "%s[testStarted name='%s']", messageId, testName)
|
|
||||||
message := escape(setupSummary.Failure.ComponentCodeLocation.String())
|
|
||||||
details := escape(setupSummary.Failure.Message)
|
|
||||||
fmt.Fprintf(reporter.writer, "%s[testFailed name='%s' message='%s' details='%s']", messageId, testName, message, details)
|
|
||||||
durationInMilliseconds := setupSummary.RunTime.Seconds() * 1000
|
|
||||||
fmt.Fprintf(reporter.writer, "%s[testFinished name='%s' duration='%v']", messageId, testName, durationInMilliseconds)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *TeamCityReporter) SpecWillRun(specSummary *types.SpecSummary) {
|
|
||||||
testName := escape(strings.Join(specSummary.ComponentTexts[1:], " "))
|
|
||||||
fmt.Fprintf(reporter.writer, "%s[testStarted name='%s']", messageId, testName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *TeamCityReporter) SpecDidComplete(specSummary *types.SpecSummary) {
|
|
||||||
testName := escape(strings.Join(specSummary.ComponentTexts[1:], " "))
|
|
||||||
|
|
||||||
if specSummary.State == types.SpecStateFailed || specSummary.State == types.SpecStateTimedOut || specSummary.State == types.SpecStatePanicked {
|
|
||||||
message := escape(specSummary.Failure.ComponentCodeLocation.String())
|
|
||||||
details := escape(specSummary.Failure.Message)
|
|
||||||
fmt.Fprintf(reporter.writer, "%s[testFailed name='%s' message='%s' details='%s']", messageId, testName, message, details)
|
|
||||||
}
|
|
||||||
if specSummary.State == types.SpecStateSkipped || specSummary.State == types.SpecStatePending {
|
|
||||||
fmt.Fprintf(reporter.writer, "%s[testIgnored name='%s']", messageId, testName)
|
|
||||||
}
|
|
||||||
|
|
||||||
durationInMilliseconds := specSummary.RunTime.Seconds() * 1000
|
|
||||||
fmt.Fprintf(reporter.writer, "%s[testFinished name='%s' duration='%v']", messageId, testName, durationInMilliseconds)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reporter *TeamCityReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {
|
|
||||||
fmt.Fprintf(reporter.writer, "%s[testSuiteFinished name='%s']", messageId, reporter.testSuiteName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func escape(output string) string {
|
|
||||||
output = strings.Replace(output, "|", "||", -1)
|
|
||||||
output = strings.Replace(output, "'", "|'", -1)
|
|
||||||
output = strings.Replace(output, "\n", "|n", -1)
|
|
||||||
output = strings.Replace(output, "\r", "|r", -1)
|
|
||||||
output = strings.Replace(output, "[", "|[", -1)
|
|
||||||
output = strings.Replace(output, "]", "|]", -1)
|
|
||||||
return output
|
|
||||||
}
|
|
15
vendor/github.com/onsi/ginkgo/types/code_location.go
generated
vendored
15
vendor/github.com/onsi/ginkgo/types/code_location.go
generated
vendored
|
@ -1,15 +0,0 @@
|
||||||
package types
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CodeLocation struct {
|
|
||||||
FileName string
|
|
||||||
LineNumber int
|
|
||||||
FullStackTrace string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (codeLocation CodeLocation) String() string {
|
|
||||||
return fmt.Sprintf("%s:%d", codeLocation.FileName, codeLocation.LineNumber)
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue