Update go dependencies
This commit is contained in:
parent
c639f490b1
commit
d3c957192e
125 changed files with 12284 additions and 0 deletions
201
vendor/github.com/go-logr/logr/LICENSE
generated
vendored
Normal file
201
vendor/github.com/go-logr/logr/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
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 {yyyy} {name of copyright owner}
|
||||
|
||||
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.
|
||||
36
vendor/github.com/go-logr/logr/README.md
generated
vendored
Normal file
36
vendor/github.com/go-logr/logr/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# A more minimal logging API for Go
|
||||
|
||||
Before you consider this package, please read [this blog post by the inimitable
|
||||
Dave Cheney](http://dave.cheney.net/2015/11/05/lets-talk-about-logging). I
|
||||
really appreciate what he has to say, and it largely aligns with my own
|
||||
experiences. Too many choices of levels means inconsistent logs.
|
||||
|
||||
This package offers a purely abstract interface, based on these ideas but with
|
||||
a few twists. Code can depend on just this interface and have the actual
|
||||
logging implementation be injected from callers. Ideally only `main()` knows
|
||||
what logging implementation is being used.
|
||||
|
||||
# Differences from Dave's ideas
|
||||
|
||||
The main differences are:
|
||||
|
||||
1) Dave basically proposes doing away with the notion of a logging API in favor
|
||||
of `fmt.Printf()`. I disagree, especially when you consider things like output
|
||||
locations, timestamps, file and line decorations, and structured logging. I
|
||||
restrict the API to just 2 types of logs: info and error.
|
||||
|
||||
Info logs are things you want to tell the user which are not errors. Error
|
||||
logs are, well, errors. If your code receives an `error` from a subordinate
|
||||
function call and is logging that `error` *and not returning it*, use error
|
||||
logs.
|
||||
|
||||
2) Verbosity-levels on info logs. This gives developers a chance to indicate
|
||||
arbitrary grades of importance for info logs, without assigning names with
|
||||
semantic meaning such as "warning", "trace", and "debug". Superficially this
|
||||
may feel very similar, but the primary difference is the lack of semantics.
|
||||
Because verbosity is a numerical value, it's safe to assume that an app running
|
||||
with higher verbosity means more (and less important) logs will be generated.
|
||||
|
||||
This is a BETA grade API. I have implemented it for
|
||||
[glog](https://godoc.org/github.com/golang/glog). Until there is a significant
|
||||
2nd implementation, I don't really know how it will change.
|
||||
151
vendor/github.com/go-logr/logr/logr.go
generated
vendored
Normal file
151
vendor/github.com/go-logr/logr/logr.go
generated
vendored
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
// Package logr defines abstract interfaces for logging. Packages can depend on
|
||||
// these interfaces and callers can implement logging in whatever way is
|
||||
// appropriate.
|
||||
//
|
||||
// This design derives from Dave Cheney's blog:
|
||||
// http://dave.cheney.net/2015/11/05/lets-talk-about-logging
|
||||
//
|
||||
// This is a BETA grade API. Until there is a significant 2nd implementation,
|
||||
// I don't really know how it will change.
|
||||
//
|
||||
// The logging specifically makes it non-trivial to use format strings, to encourage
|
||||
// attaching structured information instead of unstructured format strings.
|
||||
//
|
||||
// Usage
|
||||
//
|
||||
// Logging is done using a Logger. Loggers can have name prefixes and named values
|
||||
// attached, so that all log messages logged with that Logger have some base context
|
||||
// associated.
|
||||
//
|
||||
// The term "key" is used to refer to the name associated with a particular value, to
|
||||
// disambiguate it from the general Logger name.
|
||||
//
|
||||
// For instance, suppose we're trying to reconcile the state of an object, and we want
|
||||
// to log that we've made some decision.
|
||||
//
|
||||
// With the traditional log package, we might write
|
||||
// log.Printf(
|
||||
// "decided to set field foo to value %q for object %s/%s",
|
||||
// targetValue, object.Namespace, object.Name)
|
||||
//
|
||||
// With logr's structured logging, we'd write
|
||||
// // elsewhere in the file, set up the logger to log with the prefix of "reconcilers",
|
||||
// // and the named value target-type=Foo, for extra context.
|
||||
// log := mainLogger.WithName("reconcilers").WithValues("target-type", "Foo")
|
||||
//
|
||||
// // later on...
|
||||
// log.Info("setting field foo on object", "value", targetValue, "object", object)
|
||||
//
|
||||
// Depending on our logging implementation, we could then make logging decisions based on field values
|
||||
// (like only logging such events for objects in a certain namespace), or copy the structured
|
||||
// information into a structured log store.
|
||||
//
|
||||
// For logging errors, Logger has a method called Error. Suppose we wanted to log an
|
||||
// error while reconciling. With the traditional log package, we might write
|
||||
// log.Errorf("unable to reconcile object %s/%s: %v", object.Namespace, object.Name, err)
|
||||
//
|
||||
// With logr, we'd instead write
|
||||
// // assuming the above setup for log
|
||||
// log.Error(err, "unable to reconcile object", "object", object)
|
||||
//
|
||||
// This functions similarly to:
|
||||
// log.Info("unable to reconcile object", "error", err, "object", object)
|
||||
//
|
||||
// However, it ensures that a standard key for the error value ("error") is used across all
|
||||
// error logging. Furthermore, certain implementations may choose to attach additional
|
||||
// information (such as stack traces) on calls to Error, so it's preferred to use Error
|
||||
// to log errors.
|
||||
//
|
||||
// Parts of a log line
|
||||
//
|
||||
// Each log message from a Logger has four types of context:
|
||||
// logger name, log verbosity, log message, and the named values.
|
||||
//
|
||||
// The Logger name constists of a series of name "segments" added by successive calls to WithName.
|
||||
// These name segments will be joined in some way by the underlying implementation. It is strongly
|
||||
// reccomended that name segements contain simple identifiers (letters, digits, and hyphen), and do
|
||||
// not contain characters that could muddle the log output or confuse the joining operation (e.g.
|
||||
// whitespace, commas, periods, slashes, brackets, quotes, etc).
|
||||
//
|
||||
// Log verbosity represents how little a log matters. Level zero, the default, matters most.
|
||||
// Increasing levels matter less and less. Try to avoid lots of different verbosity levels,
|
||||
// and instead provide useful keys, logger names, and log messages for users to filter on.
|
||||
// It's illegal to pass a log level below zero.
|
||||
//
|
||||
// The log message consists of a constant message attached to the the log line. This
|
||||
// should generally be a simple description of what's occuring, and should never be a format string.
|
||||
//
|
||||
// Variable information can then be attached using named values (key/value pairs). Keys are arbitrary
|
||||
// strings, while values may be any Go value.
|
||||
//
|
||||
// Key Naming Conventions
|
||||
//
|
||||
// While users are generally free to use key names of their choice, it's generally best to avoid
|
||||
// using the following keys, as they're frequently used by implementations:
|
||||
//
|
||||
// - `"error"`: the underlying error value in the `Error` method.
|
||||
// - `"stacktrace"`: the stack trace associated with a particular log line or error
|
||||
// (often from the `Error` message).
|
||||
// - `"caller"`: the calling information (file/line) of a particular log line.
|
||||
// - `"msg"`: the log message.
|
||||
// - `"level"`: the log level.
|
||||
// - `"ts"`: the timestamp for a log line.
|
||||
//
|
||||
// Implementations are encouraged to make use of these keys to represent the above
|
||||
// concepts, when neccessary (for example, in a pure-JSON output form, it would be
|
||||
// necessary to represent at least message and timestamp as ordinary named values).
|
||||
package logr
|
||||
|
||||
// TODO: consider adding back in format strings if they're really needed
|
||||
// TODO: consider other bits of zap/zapcore functionality like ObjectMarshaller (for arbitrary objects)
|
||||
// TODO: consider other bits of glog functionality like Flush, InfoDepth, OutputStats
|
||||
|
||||
// InfoLogger represents the ability to log non-error messages, at a particular verbosity.
|
||||
type InfoLogger interface {
|
||||
// Info logs a non-error message with the given key/value pairs as context.
|
||||
//
|
||||
// The msg argument should be used to add some constant description to
|
||||
// the log line. The key/value pairs can then be used to add additional
|
||||
// variable information. The key/value pairs should alternate string
|
||||
// keys and arbitrary values.
|
||||
Info(msg string, keysAndValues ...interface{})
|
||||
|
||||
// Enabled tests whether this InfoLogger is enabled. For example,
|
||||
// commandline flags might be used to set the logging verbosity and disable
|
||||
// some info logs.
|
||||
Enabled() bool
|
||||
}
|
||||
|
||||
// Logger represents the ability to log messages, both errors and not.
|
||||
type Logger interface {
|
||||
// All Loggers implement InfoLogger. Calling InfoLogger methods directly on
|
||||
// a Logger value is equivalent to calling them on a V(0) InfoLogger. For
|
||||
// example, logger.Info() produces the same result as logger.V(0).Info.
|
||||
InfoLogger
|
||||
|
||||
// Error logs an error, with the given message and key/value pairs as context.
|
||||
// It functions similarly to calling Info with the "error" named value, but may
|
||||
// have unique behavior, and should be preferred for logging errors (see the
|
||||
// package documentations for more information).
|
||||
//
|
||||
// The msg field should be used to add context to any underlying error,
|
||||
// while the err field should be used to attach the actual error that
|
||||
// triggered this log line, if present.
|
||||
Error(err error, msg string, keysAndValues ...interface{})
|
||||
|
||||
// V returns an InfoLogger value for a specific verbosity level. A higher
|
||||
// verbosity level means a log message is less important. It's illegal to
|
||||
// pass a log level less than zero.
|
||||
V(level int) InfoLogger
|
||||
|
||||
// WithValues adds some key-value pairs of context to a logger.
|
||||
// See Info for documentation on how key/value pairs work.
|
||||
WithValues(keysAndValues ...interface{}) Logger
|
||||
|
||||
// WithName adds a new element to the logger's name.
|
||||
// Successive calls with WithName continue to append
|
||||
// suffixes to the logger's name. It's strongly reccomended
|
||||
// that name segments contain only letters, digits, and hyphens
|
||||
// (see the package documentation for more information).
|
||||
WithName(name string) Logger
|
||||
}
|
||||
3
vendor/github.com/go-logr/zapr/.gitignore
generated
vendored
Normal file
3
vendor/github.com/go-logr/zapr/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
*~
|
||||
*.swp
|
||||
/vendor
|
||||
52
vendor/github.com/go-logr/zapr/Gopkg.lock
generated
vendored
Normal file
52
vendor/github.com/go-logr/zapr/Gopkg.lock
generated
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
digest = "1:edd2fa4578eb086265db78a9201d15e76b298dfd0d5c379da83e9c61712cf6df"
|
||||
name = "github.com/go-logr/logr"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "9fb12b3b21c5415d16ac18dc5cd42c1cfdd40c4e"
|
||||
version = "v0.1.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:3c1a69cdae3501bf75e76d0d86dc6f2b0a7421bc205c0cb7b96b19eed464a34d"
|
||||
name = "go.uber.org/atomic"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "1ea20fb1cbb1cc08cbd0d913a96dead89aa18289"
|
||||
version = "v1.3.2"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:60bf2a5e347af463c42ed31a493d817f8a72f102543060ed992754e689805d1a"
|
||||
name = "go.uber.org/multierr"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "3c4937480c32f4c13a875a1829af76c98ca3d40a"
|
||||
version = "v1.1.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:9580b1b079114140ade8cec957685344d14f00119e0241f6b369633cb346eeb3"
|
||||
name = "go.uber.org/zap"
|
||||
packages = [
|
||||
".",
|
||||
"buffer",
|
||||
"internal/bufferpool",
|
||||
"internal/color",
|
||||
"internal/exit",
|
||||
"zapcore",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "eeedf312bc6c57391d84767a4cd413f02a917974"
|
||||
version = "v1.8.0"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
input-imports = [
|
||||
"github.com/go-logr/logr",
|
||||
"go.uber.org/zap",
|
||||
"go.uber.org/zap/zapcore",
|
||||
]
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
38
vendor/github.com/go-logr/zapr/Gopkg.toml
generated
vendored
Normal file
38
vendor/github.com/go-logr/zapr/Gopkg.toml
generated
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# Gopkg.toml example
|
||||
#
|
||||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
|
||||
# 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/go-logr/logr"
|
||||
version = "0.1.0"
|
||||
|
||||
[[constraint]]
|
||||
name = "go.uber.org/zap"
|
||||
version = "1.8.0"
|
||||
|
||||
[prune]
|
||||
go-tests = true
|
||||
unused-packages = true
|
||||
201
vendor/github.com/go-logr/zapr/LICENSE
generated
vendored
Normal file
201
vendor/github.com/go-logr/zapr/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
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 {yyyy} {name of copyright owner}
|
||||
|
||||
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.
|
||||
45
vendor/github.com/go-logr/zapr/README.md
generated
vendored
Normal file
45
vendor/github.com/go-logr/zapr/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
Zapr :zap:
|
||||
==========
|
||||
|
||||
A [logr](https://github.com/go-logr/logr) implementation using
|
||||
[Zap](go.uber.org/zap).
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/directxman12/zapr"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var log logr.Logger
|
||||
|
||||
zapLog, err := zap.NewDevelopment()
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("who watches the watchmen (%v)?", err))
|
||||
}
|
||||
log = zapr.NewLogger(zapLog)
|
||||
|
||||
log.Info("Logr in action!", "the answer", 42)
|
||||
}
|
||||
```
|
||||
|
||||
Implementation Details
|
||||
----------------------
|
||||
|
||||
For the most part, concepts in Zap correspond directly with those in logr.
|
||||
|
||||
Unlike Zap, all fields *must* be in the form of suggared fields --
|
||||
it's illegal to pass a strongly-typed Zap field in a key position to any
|
||||
of the logging methods (`Log`, `Error`).
|
||||
|
||||
Levels in logr correspond to custom debug levels in Zap. Any given level
|
||||
in logr is represents by its inverse in Zap (`zapLevel = -1*logrLevel`).
|
||||
|
||||
For example `V(2)` is equivalent to log level -2 in Zap, while `V(1)` is
|
||||
equivalent to Zap's `DebugLevel`.
|
||||
163
vendor/github.com/go-logr/zapr/zapr.go
generated
vendored
Normal file
163
vendor/github.com/go-logr/zapr/zapr.go
generated
vendored
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
// Copyright 2018 Solly Ross
|
||||
//
|
||||
// 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.
|
||||
|
||||
// package zapr defines an implementation of the github.com/go-logr/logr
|
||||
// interfaces built on top of Zap (go.uber.org/zap).
|
||||
//
|
||||
// Usage
|
||||
//
|
||||
// A new logr.Logger can be constructed from an existing zap.Logger using
|
||||
// the NewLogger function:
|
||||
//
|
||||
// log := zapr.NewLogger(someZapLogger)
|
||||
//
|
||||
// Implementation Details
|
||||
//
|
||||
// For the most part, concepts in Zap correspond directly with those in
|
||||
// logr.
|
||||
//
|
||||
// Unlike Zap, all fields *must* be in the form of suggared fields --
|
||||
// it's illegal to pass a strongly-typed Zap field in a key position
|
||||
// to any of the log methods.
|
||||
//
|
||||
// Levels in logr correspond to custom debug levels in Zap. Any given level
|
||||
// in logr is represents by its inverse in zap (`zapLevel = -1*logrLevel`).
|
||||
// For example V(2) is equivalent to log level -2 in Zap, while V(1) is
|
||||
// equivalent to Zap's DebugLevel.
|
||||
package zapr
|
||||
|
||||
import (
|
||||
"github.com/go-logr/logr"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
// noopInfoLogger is a logr.InfoLogger that's always disabled, and does nothing.
|
||||
type noopInfoLogger struct{}
|
||||
|
||||
func (l *noopInfoLogger) Enabled() bool { return false }
|
||||
func (l *noopInfoLogger) Info(_ string, _ ...interface{}) {}
|
||||
|
||||
var disabledInfoLogger = &noopInfoLogger{}
|
||||
|
||||
// NB: right now, we always use the equivalent of sugared logging.
|
||||
// This is necessary, since logr doesn't define non-suggared types,
|
||||
// and using zap-specific non-suggared types would make uses tied
|
||||
// directly to Zap.
|
||||
|
||||
// infoLogger is a logr.InfoLogger that uses Zap to log at a particular
|
||||
// level. The level has already been converted to a Zap level, which
|
||||
// is to say that `logrLevel = -1*zapLevel`.
|
||||
type infoLogger struct {
|
||||
lvl zapcore.Level
|
||||
l *zap.Logger
|
||||
}
|
||||
|
||||
func (l *infoLogger) Enabled() bool { return true }
|
||||
func (l *infoLogger) Info(msg string, keysAndVals ...interface{}) {
|
||||
if checkedEntry := l.l.Check(l.lvl, msg); checkedEntry != nil {
|
||||
checkedEntry.Write(handleFields(l.l, keysAndVals)...)
|
||||
}
|
||||
}
|
||||
|
||||
// zapLogger is a logr.Logger that uses Zap to log.
|
||||
type zapLogger struct {
|
||||
// NB: this looks very similar to zap.SugaredLogger, but
|
||||
// deals with our desire to have multiple verbosity levels.
|
||||
l *zap.Logger
|
||||
infoLogger
|
||||
}
|
||||
|
||||
// handleFields converts a bunch of arbitrary key-value pairs into Zap fields. It takes
|
||||
// additional pre-converted Zap fields, for use with automatically attached fields, like
|
||||
// `error`.
|
||||
func handleFields(l *zap.Logger, args []interface{}, additional ...zap.Field) []zap.Field {
|
||||
// a slightly modified version of zap.SugaredLogger.sweetenFields
|
||||
if len(args) == 0 {
|
||||
// fast-return if we have no suggared fields.
|
||||
return additional
|
||||
}
|
||||
|
||||
// unlike Zap, we can be pretty sure users aren't passing structured
|
||||
// fields (since logr has no concept of that), so guess that we need a
|
||||
// little less space.
|
||||
fields := make([]zap.Field, 0, len(args)/2+len(additional))
|
||||
for i := 0; i < len(args); {
|
||||
// check just in case for strongly-typed Zap fields, which is illegal (since
|
||||
// it breaks implementation agnosticism), so we can give a better error message.
|
||||
if _, ok := args[i].(zap.Field); ok {
|
||||
l.DPanic("strongly-typed Zap Field passed to logr", zap.Any("zap field", args[i]))
|
||||
break
|
||||
}
|
||||
|
||||
// make sure this isn't a mismatched key
|
||||
if i == len(args)-1 {
|
||||
l.DPanic("odd number of arguments passed as key-value pairs for logging", zap.Any("ignored key", args[i]))
|
||||
break
|
||||
}
|
||||
|
||||
// process a key-value pair,
|
||||
// ensuring that the key is a string
|
||||
key, val := args[i], args[i+1]
|
||||
keyStr, isString := key.(string)
|
||||
if !isString {
|
||||
// if the key isn't a string, DPanic and stop logging
|
||||
l.DPanic("non-string key argument passed to logging, ignoring all later arguments", zap.Any("invalid key", key))
|
||||
break
|
||||
}
|
||||
|
||||
fields = append(fields, zap.Any(keyStr, val))
|
||||
i += 2
|
||||
}
|
||||
|
||||
return append(fields, additional...)
|
||||
}
|
||||
|
||||
func (l *zapLogger) Error(err error, msg string, keysAndVals ...interface{}) {
|
||||
if checkedEntry := l.l.Check(zap.ErrorLevel, msg); checkedEntry != nil {
|
||||
checkedEntry.Write(handleFields(l.l, keysAndVals, zap.Error(err))...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *zapLogger) V(level int) logr.InfoLogger {
|
||||
lvl := zapcore.Level(-1 * level)
|
||||
if l.l.Core().Enabled(lvl) {
|
||||
return &infoLogger{
|
||||
lvl: lvl,
|
||||
l: l.l,
|
||||
}
|
||||
}
|
||||
return disabledInfoLogger
|
||||
}
|
||||
|
||||
func (l *zapLogger) WithValues(keysAndValues ...interface{}) logr.Logger {
|
||||
newLogger := l.l.With(handleFields(l.l, keysAndValues)...)
|
||||
return NewLogger(newLogger)
|
||||
}
|
||||
|
||||
func (l *zapLogger) WithName(name string) logr.Logger {
|
||||
newLogger := l.l.Named(name)
|
||||
return NewLogger(newLogger)
|
||||
}
|
||||
|
||||
// NewLogger creates a new logr.Logger using the given Zap Logger to log.
|
||||
func NewLogger(l *zap.Logger) logr.Logger {
|
||||
return &zapLogger{
|
||||
l: l,
|
||||
infoLogger: infoLogger{
|
||||
l: l,
|
||||
lvl: zap.InfoLevel,
|
||||
},
|
||||
}
|
||||
}
|
||||
245
vendor/github.com/onsi/gomega/gbytes/buffer.go
generated
vendored
Normal file
245
vendor/github.com/onsi/gomega/gbytes/buffer.go
generated
vendored
Normal file
|
|
@ -0,0 +1,245 @@
|
|||
/*
|
||||
Package gbytes provides a buffer that supports incrementally detecting input.
|
||||
|
||||
You use gbytes.Buffer with the gbytes.Say matcher. When Say finds a match, it fastforwards the buffer's read cursor to the end of that match.
|
||||
|
||||
Subsequent matches against the buffer will only operate against data that appears *after* the read cursor.
|
||||
|
||||
The read cursor is an opaque implementation detail that you cannot access. You should use the Say matcher to sift through the buffer. You can always
|
||||
access the entire buffer's contents with Contents().
|
||||
|
||||
*/
|
||||
package gbytes
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"regexp"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
/*
|
||||
gbytes.Buffer implements an io.Writer and can be used with the gbytes.Say matcher.
|
||||
|
||||
You should only use a gbytes.Buffer in test code. It stores all writes in an in-memory buffer - behavior that is inappropriate for production code!
|
||||
*/
|
||||
type Buffer struct {
|
||||
contents []byte
|
||||
readCursor uint64
|
||||
lock *sync.Mutex
|
||||
detectCloser chan interface{}
|
||||
closed bool
|
||||
}
|
||||
|
||||
/*
|
||||
NewBuffer returns a new gbytes.Buffer
|
||||
*/
|
||||
func NewBuffer() *Buffer {
|
||||
return &Buffer{
|
||||
lock: &sync.Mutex{},
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
BufferWithBytes returns a new gbytes.Buffer seeded with the passed in bytes
|
||||
*/
|
||||
func BufferWithBytes(bytes []byte) *Buffer {
|
||||
return &Buffer{
|
||||
lock: &sync.Mutex{},
|
||||
contents: bytes,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
BufferReader returns a new gbytes.Buffer that wraps a reader. The reader's contents are read into
|
||||
the Buffer via io.Copy
|
||||
*/
|
||||
func BufferReader(reader io.Reader) *Buffer {
|
||||
b := &Buffer{
|
||||
lock: &sync.Mutex{},
|
||||
}
|
||||
|
||||
go func() {
|
||||
io.Copy(b, reader)
|
||||
b.Close()
|
||||
}()
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
/*
|
||||
Write implements the io.Writer interface
|
||||
*/
|
||||
func (b *Buffer) Write(p []byte) (n int, err error) {
|
||||
b.lock.Lock()
|
||||
defer b.lock.Unlock()
|
||||
|
||||
if b.closed {
|
||||
return 0, errors.New("attempt to write to closed buffer")
|
||||
}
|
||||
|
||||
b.contents = append(b.contents, p...)
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
/*
|
||||
Read implements the io.Reader interface. It advances the
|
||||
cursor as it reads.
|
||||
|
||||
Returns an error if called after Close.
|
||||
*/
|
||||
func (b *Buffer) Read(d []byte) (int, error) {
|
||||
b.lock.Lock()
|
||||
defer b.lock.Unlock()
|
||||
|
||||
if b.closed {
|
||||
return 0, errors.New("attempt to read from closed buffer")
|
||||
}
|
||||
|
||||
if uint64(len(b.contents)) <= b.readCursor {
|
||||
return 0, io.EOF
|
||||
}
|
||||
|
||||
n := copy(d, b.contents[b.readCursor:])
|
||||
b.readCursor += uint64(n)
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
/*
|
||||
Close signifies that the buffer will no longer be written to
|
||||
*/
|
||||
func (b *Buffer) Close() error {
|
||||
b.lock.Lock()
|
||||
defer b.lock.Unlock()
|
||||
|
||||
b.closed = true
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
Closed returns true if the buffer has been closed
|
||||
*/
|
||||
func (b *Buffer) Closed() bool {
|
||||
b.lock.Lock()
|
||||
defer b.lock.Unlock()
|
||||
|
||||
return b.closed
|
||||
}
|
||||
|
||||
/*
|
||||
Contents returns all data ever written to the buffer.
|
||||
*/
|
||||
func (b *Buffer) Contents() []byte {
|
||||
b.lock.Lock()
|
||||
defer b.lock.Unlock()
|
||||
|
||||
contents := make([]byte, len(b.contents))
|
||||
copy(contents, b.contents)
|
||||
return contents
|
||||
}
|
||||
|
||||
/*
|
||||
Detect takes a regular expression and returns a channel.
|
||||
|
||||
The channel will receive true the first time data matching the regular expression is written to the buffer.
|
||||
The channel is subsequently closed and the buffer's read-cursor is fast-forwarded to just after the matching region.
|
||||
|
||||
You typically don't need to use Detect and should use the ghttp.Say matcher instead. Detect is useful, however, in cases where your code must
|
||||
be branch and handle different outputs written to the buffer.
|
||||
|
||||
For example, consider a buffer hooked up to the stdout of a client library. You may (or may not, depending on state outside of your control) need to authenticate the client library.
|
||||
|
||||
You could do something like:
|
||||
|
||||
select {
|
||||
case <-buffer.Detect("You are not logged in"):
|
||||
//log in
|
||||
case <-buffer.Detect("Success"):
|
||||
//carry on
|
||||
case <-time.After(time.Second):
|
||||
//welp
|
||||
}
|
||||
buffer.CancelDetects()
|
||||
|
||||
You should always call CancelDetects after using Detect. This will close any channels that have not detected and clean up the goroutines that were spawned to support them.
|
||||
|
||||
Finally, you can pass detect a format string followed by variadic arguments. This will construct the regexp using fmt.Sprintf.
|
||||
*/
|
||||
func (b *Buffer) Detect(desired string, args ...interface{}) chan bool {
|
||||
formattedRegexp := desired
|
||||
if len(args) > 0 {
|
||||
formattedRegexp = fmt.Sprintf(desired, args...)
|
||||
}
|
||||
re := regexp.MustCompile(formattedRegexp)
|
||||
|
||||
b.lock.Lock()
|
||||
defer b.lock.Unlock()
|
||||
|
||||
if b.detectCloser == nil {
|
||||
b.detectCloser = make(chan interface{})
|
||||
}
|
||||
|
||||
closer := b.detectCloser
|
||||
response := make(chan bool)
|
||||
go func() {
|
||||
ticker := time.NewTicker(10 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
defer close(response)
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
b.lock.Lock()
|
||||
data, cursor := b.contents[b.readCursor:], b.readCursor
|
||||
loc := re.FindIndex(data)
|
||||
b.lock.Unlock()
|
||||
|
||||
if loc != nil {
|
||||
response <- true
|
||||
b.lock.Lock()
|
||||
newCursorPosition := cursor + uint64(loc[1])
|
||||
if newCursorPosition >= b.readCursor {
|
||||
b.readCursor = newCursorPosition
|
||||
}
|
||||
b.lock.Unlock()
|
||||
return
|
||||
}
|
||||
case <-closer:
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
/*
|
||||
CancelDetects cancels any pending detects and cleans up their goroutines. You should always call this when you're done with a set of Detect channels.
|
||||
*/
|
||||
func (b *Buffer) CancelDetects() {
|
||||
b.lock.Lock()
|
||||
defer b.lock.Unlock()
|
||||
|
||||
close(b.detectCloser)
|
||||
b.detectCloser = nil
|
||||
}
|
||||
|
||||
func (b *Buffer) didSay(re *regexp.Regexp) (bool, []byte) {
|
||||
b.lock.Lock()
|
||||
defer b.lock.Unlock()
|
||||
|
||||
unreadBytes := b.contents[b.readCursor:]
|
||||
copyOfUnreadBytes := make([]byte, len(unreadBytes))
|
||||
copy(copyOfUnreadBytes, unreadBytes)
|
||||
|
||||
loc := re.FindIndex(unreadBytes)
|
||||
|
||||
if loc != nil {
|
||||
b.readCursor += uint64(loc[1])
|
||||
return true, copyOfUnreadBytes
|
||||
}
|
||||
return false, copyOfUnreadBytes
|
||||
}
|
||||
85
vendor/github.com/onsi/gomega/gbytes/io_wrappers.go
generated
vendored
Normal file
85
vendor/github.com/onsi/gomega/gbytes/io_wrappers.go
generated
vendored
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
package gbytes
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ErrTimeout is returned by TimeoutCloser, TimeoutReader, and TimeoutWriter when the underlying Closer/Reader/Writer does not return within the specified timeout
|
||||
var ErrTimeout = errors.New("timeout occurred")
|
||||
|
||||
// TimeoutCloser returns an io.Closer that wraps the passed-in io.Closer. If the underlying Closer fails to close within the alloted timeout ErrTimeout is returned.
|
||||
func TimeoutCloser(c io.Closer, timeout time.Duration) io.Closer {
|
||||
return timeoutReaderWriterCloser{c: c, d: timeout}
|
||||
}
|
||||
|
||||
// TimeoutReader returns an io.Reader that wraps the passed-in io.Reader. If the underlying Reader fails to read within the alloted timeout ErrTimeout is returned.
|
||||
func TimeoutReader(r io.Reader, timeout time.Duration) io.Reader {
|
||||
return timeoutReaderWriterCloser{r: r, d: timeout}
|
||||
}
|
||||
|
||||
// TimeoutWriter returns an io.Writer that wraps the passed-in io.Writer. If the underlying Writer fails to write within the alloted timeout ErrTimeout is returned.
|
||||
func TimeoutWriter(w io.Writer, timeout time.Duration) io.Writer {
|
||||
return timeoutReaderWriterCloser{w: w, d: timeout}
|
||||
}
|
||||
|
||||
type timeoutReaderWriterCloser struct {
|
||||
c io.Closer
|
||||
w io.Writer
|
||||
r io.Reader
|
||||
d time.Duration
|
||||
}
|
||||
|
||||
func (t timeoutReaderWriterCloser) Close() error {
|
||||
done := make(chan struct{})
|
||||
var err error
|
||||
|
||||
go func() {
|
||||
err = t.c.Close()
|
||||
close(done)
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-done:
|
||||
return err
|
||||
case <-time.After(t.d):
|
||||
return ErrTimeout
|
||||
}
|
||||
}
|
||||
|
||||
func (t timeoutReaderWriterCloser) Read(p []byte) (int, error) {
|
||||
done := make(chan struct{})
|
||||
var n int
|
||||
var err error
|
||||
|
||||
go func() {
|
||||
n, err = t.r.Read(p)
|
||||
close(done)
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-done:
|
||||
return n, err
|
||||
case <-time.After(t.d):
|
||||
return 0, ErrTimeout
|
||||
}
|
||||
}
|
||||
|
||||
func (t timeoutReaderWriterCloser) Write(p []byte) (int, error) {
|
||||
done := make(chan struct{})
|
||||
var n int
|
||||
var err error
|
||||
|
||||
go func() {
|
||||
n, err = t.w.Write(p)
|
||||
close(done)
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-done:
|
||||
return n, err
|
||||
case <-time.After(t.d):
|
||||
return 0, ErrTimeout
|
||||
}
|
||||
}
|
||||
104
vendor/github.com/onsi/gomega/gbytes/say_matcher.go
generated
vendored
Normal file
104
vendor/github.com/onsi/gomega/gbytes/say_matcher.go
generated
vendored
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
package gbytes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
//Objects satisfying the BufferProvider can be used with the Say matcher.
|
||||
type BufferProvider interface {
|
||||
Buffer() *Buffer
|
||||
}
|
||||
|
||||
/*
|
||||
Say is a Gomega matcher that operates on gbytes.Buffers:
|
||||
|
||||
Expect(buffer).Should(Say("something"))
|
||||
|
||||
will succeed if the unread portion of the buffer matches the regular expression "something".
|
||||
|
||||
When Say succeeds, it fast forwards the gbytes.Buffer's read cursor to just after the succesful match.
|
||||
Thus, subsequent calls to Say will only match against the unread portion of the buffer
|
||||
|
||||
Say pairs very well with Eventually. To assert that a buffer eventually receives data matching "[123]-star" within 3 seconds you can:
|
||||
|
||||
Eventually(buffer, 3).Should(Say("[123]-star"))
|
||||
|
||||
Ditto with consistently. To assert that a buffer does not receive data matching "never-see-this" for 1 second you can:
|
||||
|
||||
Consistently(buffer, 1).ShouldNot(Say("never-see-this"))
|
||||
|
||||
In addition to bytes.Buffers, Say can operate on objects that implement the gbytes.BufferProvider interface.
|
||||
In such cases, Say simply operates on the *gbytes.Buffer returned by Buffer()
|
||||
|
||||
If the buffer is closed, the Say matcher will tell Eventually to abort.
|
||||
*/
|
||||
func Say(expected string, args ...interface{}) *sayMatcher {
|
||||
if len(args) > 0 {
|
||||
expected = fmt.Sprintf(expected, args...)
|
||||
}
|
||||
return &sayMatcher{
|
||||
re: regexp.MustCompile(expected),
|
||||
}
|
||||
}
|
||||
|
||||
type sayMatcher struct {
|
||||
re *regexp.Regexp
|
||||
receivedSayings []byte
|
||||
}
|
||||
|
||||
func (m *sayMatcher) buffer(actual interface{}) (*Buffer, bool) {
|
||||
var buffer *Buffer
|
||||
|
||||
switch x := actual.(type) {
|
||||
case *Buffer:
|
||||
buffer = x
|
||||
case BufferProvider:
|
||||
buffer = x.Buffer()
|
||||
default:
|
||||
return nil, false
|
||||
}
|
||||
|
||||
return buffer, true
|
||||
}
|
||||
|
||||
func (m *sayMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
buffer, ok := m.buffer(actual)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("Say must be passed a *gbytes.Buffer or BufferProvider. Got:\n%s", format.Object(actual, 1))
|
||||
}
|
||||
|
||||
didSay, sayings := buffer.didSay(m.re)
|
||||
m.receivedSayings = sayings
|
||||
|
||||
return didSay, nil
|
||||
}
|
||||
|
||||
func (m *sayMatcher) FailureMessage(actual interface{}) (message string) {
|
||||
return fmt.Sprintf(
|
||||
"Got stuck at:\n%s\nWaiting for:\n%s",
|
||||
format.IndentString(string(m.receivedSayings), 1),
|
||||
format.IndentString(m.re.String(), 1),
|
||||
)
|
||||
}
|
||||
|
||||
func (m *sayMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||
return fmt.Sprintf(
|
||||
"Saw:\n%s\nWhich matches the unexpected:\n%s",
|
||||
format.IndentString(string(m.receivedSayings), 1),
|
||||
format.IndentString(m.re.String(), 1),
|
||||
)
|
||||
}
|
||||
|
||||
func (m *sayMatcher) MatchMayChangeInTheFuture(actual interface{}) bool {
|
||||
switch x := actual.(type) {
|
||||
case *Buffer:
|
||||
return !x.Closed()
|
||||
case BufferProvider:
|
||||
return !x.Buffer().Closed()
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
112
vendor/github.com/onsi/gomega/gexec/build.go
generated
vendored
Normal file
112
vendor/github.com/onsi/gomega/gexec/build.go
generated
vendored
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
package gexec
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"go/build"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
mu sync.Mutex
|
||||
tmpDir string
|
||||
)
|
||||
|
||||
/*
|
||||
Build uses go build to compile the package at packagePath. The resulting binary is saved off in a temporary directory.
|
||||
A path pointing to this binary is returned.
|
||||
|
||||
Build uses the $GOPATH set in your environment. If $GOPATH is not set and you are using Go 1.8+,
|
||||
it will use the default GOPATH instead. It passes the variadic args on to `go build`.
|
||||
*/
|
||||
func Build(packagePath string, args ...string) (compiledPath string, err error) {
|
||||
return doBuild(build.Default.GOPATH, packagePath, nil, args...)
|
||||
}
|
||||
|
||||
/*
|
||||
BuildWithEnvironment is identical to Build but allows you to specify env vars to be set at build time.
|
||||
*/
|
||||
func BuildWithEnvironment(packagePath string, env []string, args ...string) (compiledPath string, err error) {
|
||||
return doBuild(build.Default.GOPATH, packagePath, env, args...)
|
||||
}
|
||||
|
||||
/*
|
||||
BuildIn is identical to Build but allows you to specify a custom $GOPATH (the first argument).
|
||||
*/
|
||||
func BuildIn(gopath string, packagePath string, args ...string) (compiledPath string, err error) {
|
||||
return doBuild(gopath, packagePath, nil, args...)
|
||||
}
|
||||
|
||||
func replaceGoPath(environ []string, newGoPath string) []string {
|
||||
newEnviron := []string{}
|
||||
for _, v := range environ {
|
||||
if !strings.HasPrefix(v, "GOPATH=") {
|
||||
newEnviron = append(newEnviron, v)
|
||||
}
|
||||
}
|
||||
return append(newEnviron, "GOPATH="+newGoPath)
|
||||
}
|
||||
|
||||
func doBuild(gopath, packagePath string, env []string, args ...string) (compiledPath string, err error) {
|
||||
tmpDir, err := temporaryDirectory()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if len(gopath) == 0 {
|
||||
return "", errors.New("$GOPATH not provided when building " + packagePath)
|
||||
}
|
||||
|
||||
executable := filepath.Join(tmpDir, path.Base(packagePath))
|
||||
if runtime.GOOS == "windows" {
|
||||
executable = executable + ".exe"
|
||||
}
|
||||
|
||||
cmdArgs := append([]string{"build"}, args...)
|
||||
cmdArgs = append(cmdArgs, "-o", executable, packagePath)
|
||||
|
||||
build := exec.Command("go", cmdArgs...)
|
||||
build.Env = replaceGoPath(os.Environ(), gopath)
|
||||
build.Env = append(build.Env, env...)
|
||||
|
||||
output, err := build.CombinedOutput()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Failed to build %s:\n\nError:\n%s\n\nOutput:\n%s", packagePath, err, string(output))
|
||||
}
|
||||
|
||||
return executable, nil
|
||||
}
|
||||
|
||||
/*
|
||||
You should call CleanupBuildArtifacts before your test ends to clean up any temporary artifacts generated by
|
||||
gexec. In Ginkgo this is typically done in an AfterSuite callback.
|
||||
*/
|
||||
func CleanupBuildArtifacts() {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if tmpDir != "" {
|
||||
os.RemoveAll(tmpDir)
|
||||
tmpDir = ""
|
||||
}
|
||||
}
|
||||
|
||||
func temporaryDirectory() (string, error) {
|
||||
var err error
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if tmpDir == "" {
|
||||
tmpDir, err = ioutil.TempDir("", "gexec_artifacts")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
return ioutil.TempDir(tmpDir, "g")
|
||||
}
|
||||
86
vendor/github.com/onsi/gomega/gexec/exit_matcher.go
generated
vendored
Normal file
86
vendor/github.com/onsi/gomega/gexec/exit_matcher.go
generated
vendored
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
package gexec
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
/*
|
||||
The Exit matcher operates on a session:
|
||||
|
||||
Expect(session).Should(Exit(<optional status code>))
|
||||
|
||||
Exit passes if the session has already exited.
|
||||
|
||||
If no status code is provided, then Exit will succeed if the session has exited regardless of exit code.
|
||||
Otherwise, Exit will only succeed if the process has exited with the provided status code.
|
||||
|
||||
Note that the process must have already exited. To wait for a process to exit, use Eventually:
|
||||
|
||||
Eventually(session, 3).Should(Exit(0))
|
||||
*/
|
||||
func Exit(optionalExitCode ...int) *exitMatcher {
|
||||
exitCode := -1
|
||||
if len(optionalExitCode) > 0 {
|
||||
exitCode = optionalExitCode[0]
|
||||
}
|
||||
|
||||
return &exitMatcher{
|
||||
exitCode: exitCode,
|
||||
}
|
||||
}
|
||||
|
||||
type exitMatcher struct {
|
||||
exitCode int
|
||||
didExit bool
|
||||
actualExitCode int
|
||||
}
|
||||
|
||||
type Exiter interface {
|
||||
ExitCode() int
|
||||
}
|
||||
|
||||
func (m *exitMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
exiter, ok := actual.(Exiter)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("Exit must be passed a gexec.Exiter (Missing method ExitCode() int) Got:\n%s", format.Object(actual, 1))
|
||||
}
|
||||
|
||||
m.actualExitCode = exiter.ExitCode()
|
||||
|
||||
if m.actualExitCode == -1 {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if m.exitCode == -1 {
|
||||
return true, nil
|
||||
}
|
||||
return m.exitCode == m.actualExitCode, nil
|
||||
}
|
||||
|
||||
func (m *exitMatcher) FailureMessage(actual interface{}) (message string) {
|
||||
if m.actualExitCode == -1 {
|
||||
return "Expected process to exit. It did not."
|
||||
}
|
||||
return format.Message(m.actualExitCode, "to match exit code:", m.exitCode)
|
||||
}
|
||||
|
||||
func (m *exitMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||
if m.actualExitCode == -1 {
|
||||
return "you really shouldn't be able to see this!"
|
||||
} else {
|
||||
if m.exitCode == -1 {
|
||||
return "Expected process not to exit. It did."
|
||||
}
|
||||
return format.Message(m.actualExitCode, "not to match exit code:", m.exitCode)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *exitMatcher) MatchMayChangeInTheFuture(actual interface{}) bool {
|
||||
session, ok := actual.(*Session)
|
||||
if ok {
|
||||
return session.ExitCode() == -1
|
||||
}
|
||||
return true
|
||||
}
|
||||
53
vendor/github.com/onsi/gomega/gexec/prefixed_writer.go
generated
vendored
Normal file
53
vendor/github.com/onsi/gomega/gexec/prefixed_writer.go
generated
vendored
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package gexec
|
||||
|
||||
import (
|
||||
"io"
|
||||
"sync"
|
||||
)
|
||||
|
||||
/*
|
||||
PrefixedWriter wraps an io.Writer, emiting the passed in prefix at the beginning of each new line.
|
||||
This can be useful when running multiple gexec.Sessions concurrently - you can prefix the log output of each
|
||||
session by passing in a PrefixedWriter:
|
||||
|
||||
gexec.Start(cmd, NewPrefixedWriter("[my-cmd] ", GinkgoWriter), NewPrefixedWriter("[my-cmd] ", GinkgoWriter))
|
||||
*/
|
||||
type PrefixedWriter struct {
|
||||
prefix []byte
|
||||
writer io.Writer
|
||||
lock *sync.Mutex
|
||||
atStartOfLine bool
|
||||
}
|
||||
|
||||
func NewPrefixedWriter(prefix string, writer io.Writer) *PrefixedWriter {
|
||||
return &PrefixedWriter{
|
||||
prefix: []byte(prefix),
|
||||
writer: writer,
|
||||
lock: &sync.Mutex{},
|
||||
atStartOfLine: true,
|
||||
}
|
||||
}
|
||||
|
||||
func (w *PrefixedWriter) Write(b []byte) (int, error) {
|
||||
w.lock.Lock()
|
||||
defer w.lock.Unlock()
|
||||
|
||||
toWrite := []byte{}
|
||||
|
||||
for _, c := range b {
|
||||
if w.atStartOfLine {
|
||||
toWrite = append(toWrite, w.prefix...)
|
||||
}
|
||||
|
||||
toWrite = append(toWrite, c)
|
||||
|
||||
w.atStartOfLine = c == '\n'
|
||||
}
|
||||
|
||||
_, err := w.writer.Write(toWrite)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return len(b), nil
|
||||
}
|
||||
303
vendor/github.com/onsi/gomega/gexec/session.go
generated
vendored
Normal file
303
vendor/github.com/onsi/gomega/gexec/session.go
generated
vendored
Normal file
|
|
@ -0,0 +1,303 @@
|
|||
/*
|
||||
Package gexec provides support for testing external processes.
|
||||
*/
|
||||
package gexec
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/onsi/gomega/gbytes"
|
||||
)
|
||||
|
||||
const INVALID_EXIT_CODE = 254
|
||||
|
||||
type Session struct {
|
||||
//The wrapped command
|
||||
Command *exec.Cmd
|
||||
|
||||
//A *gbytes.Buffer connected to the command's stdout
|
||||
Out *gbytes.Buffer
|
||||
|
||||
//A *gbytes.Buffer connected to the command's stderr
|
||||
Err *gbytes.Buffer
|
||||
|
||||
//A channel that will close when the command exits
|
||||
Exited <-chan struct{}
|
||||
|
||||
lock *sync.Mutex
|
||||
exitCode int
|
||||
}
|
||||
|
||||
/*
|
||||
Start starts the passed-in *exec.Cmd command. It wraps the command in a *gexec.Session.
|
||||
|
||||
The session pipes the command's stdout and stderr to two *gbytes.Buffers available as properties on the session: session.Out and session.Err.
|
||||
These buffers can be used with the gbytes.Say matcher to match against unread output:
|
||||
|
||||
Expect(session.Out).Should(gbytes.Say("foo-out"))
|
||||
Expect(session.Err).Should(gbytes.Say("foo-err"))
|
||||
|
||||
In addition, Session satisfies the gbytes.BufferProvider interface and provides the stdout *gbytes.Buffer. This allows you to replace the first line, above, with:
|
||||
|
||||
Expect(session).Should(gbytes.Say("foo-out"))
|
||||
|
||||
When outWriter and/or errWriter are non-nil, the session will pipe stdout and/or stderr output both into the session *gybtes.Buffers and to the passed-in outWriter/errWriter.
|
||||
This is useful for capturing the process's output or logging it to screen. In particular, when using Ginkgo it can be convenient to direct output to the GinkgoWriter:
|
||||
|
||||
session, err := Start(command, GinkgoWriter, GinkgoWriter)
|
||||
|
||||
This will log output when running tests in verbose mode, but - otherwise - will only log output when a test fails.
|
||||
|
||||
The session wrapper is responsible for waiting on the *exec.Cmd command. You *should not* call command.Wait() yourself.
|
||||
Instead, to assert that the command has exited you can use the gexec.Exit matcher:
|
||||
|
||||
Expect(session).Should(gexec.Exit())
|
||||
|
||||
When the session exits it closes the stdout and stderr gbytes buffers. This will short circuit any
|
||||
Eventuallys waiting for the buffers to Say something.
|
||||
*/
|
||||
func Start(command *exec.Cmd, outWriter io.Writer, errWriter io.Writer) (*Session, error) {
|
||||
exited := make(chan struct{})
|
||||
|
||||
session := &Session{
|
||||
Command: command,
|
||||
Out: gbytes.NewBuffer(),
|
||||
Err: gbytes.NewBuffer(),
|
||||
Exited: exited,
|
||||
lock: &sync.Mutex{},
|
||||
exitCode: -1,
|
||||
}
|
||||
|
||||
var commandOut, commandErr io.Writer
|
||||
|
||||
commandOut, commandErr = session.Out, session.Err
|
||||
|
||||
if outWriter != nil {
|
||||
commandOut = io.MultiWriter(commandOut, outWriter)
|
||||
}
|
||||
|
||||
if errWriter != nil {
|
||||
commandErr = io.MultiWriter(commandErr, errWriter)
|
||||
}
|
||||
|
||||
command.Stdout = commandOut
|
||||
command.Stderr = commandErr
|
||||
|
||||
err := command.Start()
|
||||
if err == nil {
|
||||
go session.monitorForExit(exited)
|
||||
trackedSessionsMutex.Lock()
|
||||
defer trackedSessionsMutex.Unlock()
|
||||
trackedSessions = append(trackedSessions, session)
|
||||
}
|
||||
|
||||
return session, err
|
||||
}
|
||||
|
||||
/*
|
||||
Buffer implements the gbytes.BufferProvider interface and returns s.Out
|
||||
This allows you to make gbytes.Say matcher assertions against stdout without having to reference .Out:
|
||||
|
||||
Eventually(session).Should(gbytes.Say("foo"))
|
||||
*/
|
||||
func (s *Session) Buffer() *gbytes.Buffer {
|
||||
return s.Out
|
||||
}
|
||||
|
||||
/*
|
||||
ExitCode returns the wrapped command's exit code. If the command hasn't exited yet, ExitCode returns -1.
|
||||
|
||||
To assert that the command has exited it is more convenient to use the Exit matcher:
|
||||
|
||||
Eventually(s).Should(gexec.Exit())
|
||||
|
||||
When the process exits because it has received a particular signal, the exit code will be 128+signal-value
|
||||
(See http://www.tldp.org/LDP/abs/html/exitcodes.html and http://man7.org/linux/man-pages/man7/signal.7.html)
|
||||
|
||||
*/
|
||||
func (s *Session) ExitCode() int {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
return s.exitCode
|
||||
}
|
||||
|
||||
/*
|
||||
Wait waits until the wrapped command exits. It can be passed an optional timeout.
|
||||
If the command does not exit within the timeout, Wait will trigger a test failure.
|
||||
|
||||
Wait returns the session, making it possible to chain:
|
||||
|
||||
session.Wait().Out.Contents()
|
||||
|
||||
will wait for the command to exit then return the entirety of Out's contents.
|
||||
|
||||
Wait uses eventually under the hood and accepts the same timeout/polling intervals that eventually does.
|
||||
*/
|
||||
func (s *Session) Wait(timeout ...interface{}) *Session {
|
||||
EventuallyWithOffset(1, s, timeout...).Should(Exit())
|
||||
return s
|
||||
}
|
||||
|
||||
/*
|
||||
Kill sends the running command a SIGKILL signal. It does not wait for the process to exit.
|
||||
|
||||
If the command has already exited, Kill returns silently.
|
||||
|
||||
The session is returned to enable chaining.
|
||||
*/
|
||||
func (s *Session) Kill() *Session {
|
||||
return s.Signal(syscall.SIGKILL)
|
||||
}
|
||||
|
||||
/*
|
||||
Interrupt sends the running command a SIGINT signal. It does not wait for the process to exit.
|
||||
|
||||
If the command has already exited, Interrupt returns silently.
|
||||
|
||||
The session is returned to enable chaining.
|
||||
*/
|
||||
func (s *Session) Interrupt() *Session {
|
||||
return s.Signal(syscall.SIGINT)
|
||||
}
|
||||
|
||||
/*
|
||||
Terminate sends the running command a SIGTERM signal. It does not wait for the process to exit.
|
||||
|
||||
If the command has already exited, Terminate returns silently.
|
||||
|
||||
The session is returned to enable chaining.
|
||||
*/
|
||||
func (s *Session) Terminate() *Session {
|
||||
return s.Signal(syscall.SIGTERM)
|
||||
}
|
||||
|
||||
/*
|
||||
Signal sends the running command the passed in signal. It does not wait for the process to exit.
|
||||
|
||||
If the command has already exited, Signal returns silently.
|
||||
|
||||
The session is returned to enable chaining.
|
||||
*/
|
||||
func (s *Session) Signal(signal os.Signal) *Session {
|
||||
if s.processIsAlive() {
|
||||
s.Command.Process.Signal(signal)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Session) monitorForExit(exited chan<- struct{}) {
|
||||
err := s.Command.Wait()
|
||||
s.lock.Lock()
|
||||
s.Out.Close()
|
||||
s.Err.Close()
|
||||
status := s.Command.ProcessState.Sys().(syscall.WaitStatus)
|
||||
if status.Signaled() {
|
||||
s.exitCode = 128 + int(status.Signal())
|
||||
} else {
|
||||
exitStatus := status.ExitStatus()
|
||||
if exitStatus == -1 && err != nil {
|
||||
s.exitCode = INVALID_EXIT_CODE
|
||||
}
|
||||
s.exitCode = exitStatus
|
||||
}
|
||||
s.lock.Unlock()
|
||||
|
||||
close(exited)
|
||||
}
|
||||
|
||||
func (s *Session) processIsAlive() bool {
|
||||
return s.ExitCode() == -1 && s.Command.Process != nil
|
||||
}
|
||||
|
||||
var trackedSessions = []*Session{}
|
||||
var trackedSessionsMutex = &sync.Mutex{}
|
||||
|
||||
/*
|
||||
Kill sends a SIGKILL signal to all the processes started by Run, and waits for them to exit.
|
||||
The timeout specified is applied to each process killed.
|
||||
|
||||
If any of the processes already exited, KillAndWait returns silently.
|
||||
*/
|
||||
func KillAndWait(timeout ...interface{}) {
|
||||
trackedSessionsMutex.Lock()
|
||||
defer trackedSessionsMutex.Unlock()
|
||||
for _, session := range trackedSessions {
|
||||
session.Kill().Wait(timeout...)
|
||||
}
|
||||
trackedSessions = []*Session{}
|
||||
}
|
||||
|
||||
/*
|
||||
Kill sends a SIGTERM signal to all the processes started by Run, and waits for them to exit.
|
||||
The timeout specified is applied to each process killed.
|
||||
|
||||
If any of the processes already exited, TerminateAndWait returns silently.
|
||||
*/
|
||||
func TerminateAndWait(timeout ...interface{}) {
|
||||
trackedSessionsMutex.Lock()
|
||||
defer trackedSessionsMutex.Unlock()
|
||||
for _, session := range trackedSessions {
|
||||
session.Terminate().Wait(timeout...)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Kill sends a SIGKILL signal to all the processes started by Run.
|
||||
It does not wait for the processes to exit.
|
||||
|
||||
If any of the processes already exited, Kill returns silently.
|
||||
*/
|
||||
func Kill() {
|
||||
trackedSessionsMutex.Lock()
|
||||
defer trackedSessionsMutex.Unlock()
|
||||
for _, session := range trackedSessions {
|
||||
session.Kill()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Terminate sends a SIGTERM signal to all the processes started by Run.
|
||||
It does not wait for the processes to exit.
|
||||
|
||||
If any of the processes already exited, Terminate returns silently.
|
||||
*/
|
||||
func Terminate() {
|
||||
trackedSessionsMutex.Lock()
|
||||
defer trackedSessionsMutex.Unlock()
|
||||
for _, session := range trackedSessions {
|
||||
session.Terminate()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Signal sends the passed in signal to all the processes started by Run.
|
||||
It does not wait for the processes to exit.
|
||||
|
||||
If any of the processes already exited, Signal returns silently.
|
||||
*/
|
||||
func Signal(signal os.Signal) {
|
||||
trackedSessionsMutex.Lock()
|
||||
defer trackedSessionsMutex.Unlock()
|
||||
for _, session := range trackedSessions {
|
||||
session.Signal(signal)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Interrupt sends the SIGINT signal to all the processes started by Run.
|
||||
It does not wait for the processes to exit.
|
||||
|
||||
If any of the processes already exited, Interrupt returns silently.
|
||||
*/
|
||||
func Interrupt() {
|
||||
trackedSessionsMutex.Lock()
|
||||
defer trackedSessionsMutex.Unlock()
|
||||
for _, session := range trackedSessions {
|
||||
session.Interrupt()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue