├── .gitignore ├── Godeps ├── Godeps.json ├── Readme └── _workspace │ ├── .gitignore │ └── src │ └── github.com │ ├── garyburd │ └── redigo │ │ ├── internal │ │ ├── commandinfo.go │ │ └── redistest │ │ │ └── testdb.go │ │ └── redis │ │ ├── conn.go │ │ ├── conn_test.go │ │ ├── doc.go │ │ ├── log.go │ │ ├── pool.go │ │ ├── pool_test.go │ │ ├── pubsub.go │ │ ├── pubsub_test.go │ │ ├── redis.go │ │ ├── reply.go │ │ ├── reply_test.go │ │ ├── scan.go │ │ ├── scan_test.go │ │ ├── script.go │ │ ├── script_test.go │ │ ├── test_test.go │ │ └── zpop_example_test.go │ ├── onsi │ ├── ginkgo │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── CHANGELOG.md │ │ ├── MIT.LICENSE │ │ ├── README.md │ │ ├── config │ │ │ └── config.go │ │ ├── ginkgo │ │ │ ├── bootstrap_command.go │ │ │ ├── convert │ │ │ │ ├── ginkgo_ast_nodes.go │ │ │ │ ├── import.go │ │ │ │ ├── package_rewriter.go │ │ │ │ ├── test_finder.go │ │ │ │ ├── testfile_rewriter.go │ │ │ │ └── testing_t_rewriter.go │ │ │ ├── convert_command.go │ │ │ ├── generate_command.go │ │ │ ├── help_command.go │ │ │ ├── interrupt_handler.go │ │ │ ├── main.go │ │ │ ├── nodot │ │ │ │ ├── nodot.go │ │ │ │ ├── nodot_suite_test.go │ │ │ │ └── nodot_test.go │ │ │ ├── nodot_command.go │ │ │ ├── notifications.go │ │ │ ├── run_and_watch_command_flags.go │ │ │ ├── run_command.go │ │ │ ├── suite_runner.go │ │ │ ├── testrunner │ │ │ │ ├── log_writer.go │ │ │ │ ├── run_result.go │ │ │ │ └── test_runner.go │ │ │ ├── testsuite │ │ │ │ ├── test_suite.go │ │ │ │ ├── testsuite_suite_test.go │ │ │ │ └── testsuite_test.go │ │ │ ├── unfocus_command.go │ │ │ ├── version_command.go │ │ │ ├── watch │ │ │ │ ├── delta.go │ │ │ │ ├── delta_tracker.go │ │ │ │ ├── dependencies.go │ │ │ │ ├── package_hash.go │ │ │ │ ├── package_hashes.go │ │ │ │ └── suite.go │ │ │ └── watch_command.go │ │ ├── ginkgo_dsl.go │ │ ├── integration │ │ │ ├── convert_test.go │ │ │ ├── coverage_test.go │ │ │ ├── fail_test.go │ │ │ ├── flags_test.go │ │ │ ├── integration.go │ │ │ ├── integration_suite_test.go │ │ │ ├── run_test.go │ │ │ ├── subcommand_test.go │ │ │ ├── suite_setup_test.go │ │ │ ├── tags_test.go │ │ │ ├── verbose_and_succinct_test.go │ │ │ └── watch_test.go │ │ ├── internal │ │ │ ├── codelocation │ │ │ │ ├── code_location.go │ │ │ │ ├── code_location_suite_test.go │ │ │ │ └── code_location_test.go │ │ │ ├── containernode │ │ │ │ ├── container_node.go │ │ │ │ ├── container_node_suite_test.go │ │ │ │ └── container_node_test.go │ │ │ ├── failer │ │ │ │ ├── failer.go │ │ │ │ ├── failer_suite_test.go │ │ │ │ └── failer_test.go │ │ │ ├── leafnodes │ │ │ │ ├── benchmarker.go │ │ │ │ ├── interfaces.go │ │ │ │ ├── it_node.go │ │ │ │ ├── it_node_test.go │ │ │ │ ├── leaf_node_suite_test.go │ │ │ │ ├── measure_node.go │ │ │ │ ├── measure_node_test.go │ │ │ │ ├── runner.go │ │ │ │ ├── setup_nodes.go │ │ │ │ ├── setup_nodes_test.go │ │ │ │ ├── shared_runner_test.go │ │ │ │ ├── suite_nodes.go │ │ │ │ ├── suite_nodes_test.go │ │ │ │ ├── synchronized_after_suite_node.go │ │ │ │ ├── synchronized_after_suite_node_test.go │ │ │ │ ├── synchronized_before_suite_node.go │ │ │ │ └── synchronized_before_suite_node_test.go │ │ │ ├── remote │ │ │ │ ├── aggregator.go │ │ │ │ ├── aggregator_test.go │ │ │ │ ├── fake_output_interceptor_test.go │ │ │ │ ├── fake_poster_test.go │ │ │ │ ├── forwarding_reporter.go │ │ │ │ ├── forwarding_reporter_test.go │ │ │ │ ├── output_interceptor.go │ │ │ │ ├── output_interceptor_test.go │ │ │ │ ├── output_interceptor_unix.go │ │ │ │ ├── output_interceptor_win.go │ │ │ │ ├── remote_suite_test.go │ │ │ │ ├── server.go │ │ │ │ └── server_test.go │ │ │ ├── spec │ │ │ │ ├── index_computer.go │ │ │ │ ├── index_computer_test.go │ │ │ │ ├── spec.go │ │ │ │ ├── spec_suite_test.go │ │ │ │ ├── spec_test.go │ │ │ │ ├── specs.go │ │ │ │ └── specs_test.go │ │ │ ├── specrunner │ │ │ │ ├── random_id.go │ │ │ │ ├── spec_runner.go │ │ │ │ ├── spec_runner_suite_test.go │ │ │ │ └── spec_runner_test.go │ │ │ ├── suite │ │ │ │ ├── suite.go │ │ │ │ ├── suite_suite_test.go │ │ │ │ └── suite_test.go │ │ │ ├── testingtproxy │ │ │ │ └── testing_t_proxy.go │ │ │ └── writer │ │ │ │ ├── fake_writer.go │ │ │ │ ├── writer.go │ │ │ │ ├── writer_suite_test.go │ │ │ │ └── writer_test.go │ │ ├── reporters │ │ │ ├── default_reporter.go │ │ │ ├── default_reporter_test.go │ │ │ ├── fake_reporter.go │ │ │ ├── junit_reporter.go │ │ │ ├── junit_reporter_test.go │ │ │ ├── reporter.go │ │ │ ├── reporters_suite_test.go │ │ │ ├── stenographer │ │ │ │ ├── console_logging.go │ │ │ │ ├── fake_stenographer.go │ │ │ │ └── stenographer.go │ │ │ ├── teamcity_reporter.go │ │ │ └── teamcity_reporter_test.go │ │ └── types │ │ │ ├── code_location.go │ │ │ ├── synchronization.go │ │ │ ├── types.go │ │ │ ├── types_suite_test.go │ │ │ └── types_test.go │ └── gomega │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── CHANGELOG.md │ │ ├── MIT.LICENSE │ │ ├── README.md │ │ ├── format │ │ ├── format.go │ │ ├── format_suite_test.go │ │ └── format_test.go │ │ ├── gbytes │ │ ├── buffer.go │ │ ├── buffer_test.go │ │ ├── gbuffer_suite_test.go │ │ ├── say_matcher.go │ │ └── say_matcher_test.go │ │ ├── gexec │ │ ├── build.go │ │ ├── exit_matcher.go │ │ ├── exit_matcher_test.go │ │ ├── gexec_suite_test.go │ │ ├── prefixed_writer.go │ │ ├── prefixed_writer_test.go │ │ ├── session.go │ │ └── session_test.go │ │ ├── ghttp │ │ ├── handlers.go │ │ ├── test_server.go │ │ ├── test_server_suite_test.go │ │ └── test_server_test.go │ │ ├── gomega_dsl.go │ │ ├── internal │ │ ├── assertion │ │ │ ├── assertion.go │ │ │ ├── assertion_suite_test.go │ │ │ └── assertion_test.go │ │ ├── asyncassertion │ │ │ ├── async_assertion.go │ │ │ ├── async_assertion_suite_test.go │ │ │ └── async_assertion_test.go │ │ ├── fakematcher │ │ │ └── fake_matcher.go │ │ └── testingtsupport │ │ │ ├── testing_t_support.go │ │ │ └── testing_t_support_test.go │ │ ├── matchers.go │ │ ├── matchers │ │ ├── assignable_to_type_of_matcher.go │ │ ├── assignable_to_type_of_matcher_test.go │ │ ├── be_closed_matcher.go │ │ ├── be_closed_matcher_test.go │ │ ├── be_empty_matcher.go │ │ ├── be_empty_matcher_test.go │ │ ├── be_equivalent_to_matcher.go │ │ ├── be_equivalent_to_matcher_test.go │ │ ├── be_false_matcher.go │ │ ├── be_false_matcher_test.go │ │ ├── be_nil_matcher.go │ │ ├── be_nil_matcher_test.go │ │ ├── be_numerically_matcher.go │ │ ├── be_numerically_matcher_test.go │ │ ├── be_sent_matcher.go │ │ ├── be_sent_matcher_test.go │ │ ├── be_temporally_matcher.go │ │ ├── be_temporally_matcher_test.go │ │ ├── be_true_matcher.go │ │ ├── be_true_matcher_test.go │ │ ├── be_zero_matcher.go │ │ ├── be_zero_matcher_test.go │ │ ├── consist_of.go │ │ ├── consist_of_test.go │ │ ├── contain_element_matcher.go │ │ ├── contain_element_matcher_test.go │ │ ├── contain_substring_matcher.go │ │ ├── contain_substring_matcher_test.go │ │ ├── equal_matcher.go │ │ ├── equal_matcher_test.go │ │ ├── have_key_matcher.go │ │ ├── have_key_matcher_test.go │ │ ├── have_key_with_value_matcher.go │ │ ├── have_key_with_value_matcher_test.go │ │ ├── have_len_matcher.go │ │ ├── have_len_matcher_test.go │ │ ├── have_occurred_matcher.go │ │ ├── have_occurred_matcher_test.go │ │ ├── match_error_matcher.go │ │ ├── match_error_matcher_test.go │ │ ├── match_json_matcher.go │ │ ├── match_json_matcher_test.go │ │ ├── match_regexp_matcher.go │ │ ├── match_regexp_matcher_test.go │ │ ├── matcher_tests_suite_test.go │ │ ├── panic_matcher.go │ │ ├── panic_matcher_test.go │ │ ├── receive_matcher.go │ │ ├── receive_matcher_test.go │ │ ├── support │ │ │ └── goraph │ │ │ │ ├── MIT.LICENSE │ │ │ │ ├── bipartitegraph │ │ │ │ ├── bipartitegraph.go │ │ │ │ └── bipartitegraphmatching.go │ │ │ │ ├── edge │ │ │ │ └── edge.go │ │ │ │ ├── node │ │ │ │ └── node.go │ │ │ │ └── util │ │ │ │ └── util.go │ │ └── type_support.go │ │ └── types │ │ └── types.go │ └── xchapter7x │ └── goutil │ ├── .gitignore │ ├── Godeps │ ├── Godeps.json │ └── Readme │ ├── LICENSE │ ├── README.md │ ├── callchain.go │ ├── callchain_test.go │ ├── goutil_suite_test.go │ ├── itertools │ ├── each.go │ ├── each_test.go │ ├── filter.go │ ├── filter_test.go │ ├── iterConfig.go │ ├── iterate.go │ ├── iterate_test.go │ ├── itertools_suite_test.go │ ├── map.go │ ├── map_test.go │ ├── pair.go │ ├── pair_test.go │ ├── range.go │ ├── range_test.go │ ├── zip.go │ └── zip_test.go │ ├── samples │ └── example.go │ ├── testCoverage │ ├── unpack.go │ ├── unpack_test.go │ └── wercker.yml ├── README.md ├── coverage ├── engines ├── localengine │ ├── local_engine.go │ ├── local_engine_suite_test.go │ └── local_engine_test.go ├── localpubsub │ ├── local_pubsub_engine.go │ ├── local_pubsub_engine_suite_test.go │ ├── local_pubsub_engine_test.go │ ├── pubsub_interface.go │ ├── pubsub_receiver.go │ └── pubsub_receiver_test.go └── storageinterface │ └── storage_engine_interface.go ├── flipper.go ├── flipper_test.go ├── sample ├── local │ └── main.go └── localpubsub │ └── main.go ├── testCoverage ├── toggle.go ├── toggle_suite_test.go ├── toggle_test.go └── wercker.yml /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /Godeps/Godeps.json: -------------------------------------------------------------------------------- 1 | { 2 | "ImportPath": "github.com/xchapter7x/toggle", 3 | "GoVersion": "go1.3", 4 | "Packages": [ 5 | "./..." 6 | ], 7 | "Deps": [ 8 | { 9 | "ImportPath": "github.com/garyburd/redigo/internal", 10 | "Rev": "cca3df8fa0670249a3f746bcc062c69aeba0517c" 11 | }, 12 | { 13 | "ImportPath": "github.com/garyburd/redigo/redis", 14 | "Rev": "cca3df8fa0670249a3f746bcc062c69aeba0517c" 15 | }, 16 | { 17 | "ImportPath": "github.com/onsi/ginkgo", 18 | "Comment": "v1.0.0-28-g6481765", 19 | "Rev": "6481765dda39cbaae281109e6945449642329197" 20 | }, 21 | { 22 | "ImportPath": "github.com/onsi/gomega", 23 | "Rev": "4699d5a664396173c7d9fcef9e88be297c7bae13" 24 | }, 25 | { 26 | "ImportPath": "github.com/xchapter7x/goutil", 27 | "Rev": "daf40c9d46272a2e8932a1d851a10054de210931" 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /Godeps/Readme: -------------------------------------------------------------------------------- 1 | This directory tree is generated automatically by godep. 2 | 3 | Please do not edit. 4 | 5 | See https://github.com/tools/godep for more information. 6 | -------------------------------------------------------------------------------- /Godeps/_workspace/.gitignore: -------------------------------------------------------------------------------- 1 | /pkg 2 | /bin 3 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/garyburd/redigo/internal/commandinfo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Gary Burd 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package internal // import "github.com/garyburd/redigo/internal" 16 | 17 | import ( 18 | "strings" 19 | ) 20 | 21 | const ( 22 | WatchState = 1 << iota 23 | MultiState 24 | SubscribeState 25 | MonitorState 26 | ) 27 | 28 | type CommandInfo struct { 29 | Set, Clear int 30 | } 31 | 32 | var commandInfos = map[string]CommandInfo{ 33 | "WATCH": {Set: WatchState}, 34 | "UNWATCH": {Clear: WatchState}, 35 | "MULTI": {Set: MultiState}, 36 | "EXEC": {Clear: WatchState | MultiState}, 37 | "DISCARD": {Clear: WatchState | MultiState}, 38 | "PSUBSCRIBE": {Set: SubscribeState}, 39 | "SUBSCRIBE": {Set: SubscribeState}, 40 | "MONITOR": {Set: MonitorState}, 41 | } 42 | 43 | func LookupCommandInfo(commandName string) CommandInfo { 44 | return commandInfos[strings.ToUpper(commandName)] 45 | } 46 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/garyburd/redigo/internal/redistest/testdb.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Gary Burd 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | // Package redistest contains utilities for writing Redigo tests. 16 | package redistest 17 | 18 | import ( 19 | "errors" 20 | "time" 21 | 22 | "github.com/garyburd/redigo/redis" 23 | ) 24 | 25 | type testConn struct { 26 | redis.Conn 27 | } 28 | 29 | func (t testConn) Close() error { 30 | _, err := t.Conn.Do("SELECT", "9") 31 | if err != nil { 32 | return nil 33 | } 34 | _, err = t.Conn.Do("FLUSHDB") 35 | if err != nil { 36 | return err 37 | } 38 | return t.Conn.Close() 39 | } 40 | 41 | // Dial dials the local Redis server and selects database 9. To prevent 42 | // stomping on real data, DialTestDB fails if database 9 contains data. The 43 | // returned connection flushes database 9 on close. 44 | func Dial() (redis.Conn, error) { 45 | c, err := redis.DialTimeout("tcp", ":6379", 0, 1*time.Second, 1*time.Second) 46 | if err != nil { 47 | return nil, err 48 | } 49 | 50 | _, err = c.Do("SELECT", "9") 51 | if err != nil { 52 | return nil, err 53 | } 54 | 55 | n, err := redis.Int(c.Do("DBSIZE")) 56 | if err != nil { 57 | return nil, err 58 | } 59 | 60 | if n != 0 { 61 | return nil, errors.New("database #9 is not empty, test can not continue") 62 | } 63 | 64 | return testConn{c}, nil 65 | } 66 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/garyburd/redigo/redis/redis.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Gary Burd 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package redis 16 | 17 | // Error represents an error returned in a command reply. 18 | type Error string 19 | 20 | func (err Error) Error() string { return string(err) } 21 | 22 | // Conn represents a connection to a Redis server. 23 | type Conn interface { 24 | // Close closes the connection. 25 | Close() error 26 | 27 | // Err returns a non-nil value if the connection is broken. The returned 28 | // value is either the first non-nil value returned from the underlying 29 | // network connection or a protocol parsing error. Applications should 30 | // close broken connections. 31 | Err() error 32 | 33 | // Do sends a command to the server and returns the received reply. 34 | Do(commandName string, args ...interface{}) (reply interface{}, err error) 35 | 36 | // Send writes the command to the client's output buffer. 37 | Send(commandName string, args ...interface{}) error 38 | 39 | // Flush flushes the output buffer to the Redis server. 40 | Flush() error 41 | 42 | // Receive receives a single reply from the Redis server 43 | Receive() (reply interface{}, err error) 44 | } 45 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/garyburd/redigo/redis/test_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Gary Burd 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package redis 16 | 17 | import ( 18 | "bufio" 19 | "net" 20 | "time" 21 | ) 22 | 23 | func SetNowFunc(f func() time.Time) { 24 | nowFunc = f 25 | } 26 | 27 | type nopCloser struct{ net.Conn } 28 | 29 | func (nopCloser) Close() error { return nil } 30 | 31 | // NewConnBufio is a hook for tests. 32 | func NewConnBufio(rw bufio.ReadWriter) Conn { 33 | return &conn{br: rw.Reader, bw: rw.Writer, conn: nopCloser{}} 34 | } 35 | 36 | var ( 37 | ErrNegativeInt = errNegativeInt 38 | ) 39 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | TODO 3 | tmp/**/* 4 | *.coverprofile -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.3 4 | 5 | install: 6 | - go get -v ./... 7 | - go get code.google.com/p/go.tools/cmd/cover 8 | - go get github.com/onsi/gomega 9 | - go install github.com/onsi/ginkgo/ginkgo 10 | - export PATH=$PATH:$HOME/gopath/bin 11 | 12 | script: $HOME/gopath/bin/ginkgo -r --randomizeAllSpecs --failOnPending --randomizeSuites --race 13 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/MIT.LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Onsi Fakhouri 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/ginkgo/convert/import.go: -------------------------------------------------------------------------------- 1 | package convert 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "go/ast" 7 | ) 8 | 9 | /* 10 | * Given the root node of an AST, returns the node containing the 11 | * import statements for the file. 12 | */ 13 | func importsForRootNode(rootNode *ast.File) (imports *ast.GenDecl, err error) { 14 | for _, declaration := range rootNode.Decls { 15 | decl, ok := declaration.(*ast.GenDecl) 16 | if !ok || len(decl.Specs) == 0 { 17 | continue 18 | } 19 | 20 | _, ok = decl.Specs[0].(*ast.ImportSpec) 21 | if ok { 22 | imports = decl 23 | return 24 | } 25 | } 26 | 27 | err = errors.New(fmt.Sprintf("Could not find imports for root node:\n\t%#v\n", rootNode)) 28 | return 29 | } 30 | 31 | /* 32 | * Removes "testing" import, if present 33 | */ 34 | func removeTestingImport(rootNode *ast.File) { 35 | importDecl, err := importsForRootNode(rootNode) 36 | if err != nil { 37 | panic(err.Error()) 38 | } 39 | 40 | var index int 41 | for i, importSpec := range importDecl.Specs { 42 | importSpec := importSpec.(*ast.ImportSpec) 43 | if importSpec.Path.Value == "\"testing\"" { 44 | index = i 45 | break 46 | } 47 | } 48 | 49 | importDecl.Specs = append(importDecl.Specs[:index], importDecl.Specs[index+1:]...) 50 | } 51 | 52 | /* 53 | * Adds import statements for onsi/ginkgo, if missing 54 | */ 55 | func addGinkgoImports(rootNode *ast.File) { 56 | importDecl, err := importsForRootNode(rootNode) 57 | if err != nil { 58 | panic(err.Error()) 59 | } 60 | 61 | if len(importDecl.Specs) == 0 { 62 | // TODO: might need to create a import decl here 63 | panic("unimplemented : expected to find an imports block") 64 | } 65 | 66 | needsGinkgo := true 67 | for _, importSpec := range importDecl.Specs { 68 | importSpec, ok := importSpec.(*ast.ImportSpec) 69 | if !ok { 70 | continue 71 | } 72 | 73 | if importSpec.Path.Value == "\"github.com/onsi/ginkgo\"" { 74 | needsGinkgo = false 75 | } 76 | } 77 | 78 | if needsGinkgo { 79 | importDecl.Specs = append(importDecl.Specs, createImport(".", "\"github.com/onsi/ginkgo\"")) 80 | } 81 | } 82 | 83 | /* 84 | * convenience function to create an import statement 85 | */ 86 | func createImport(name, path string) *ast.ImportSpec { 87 | return &ast.ImportSpec{ 88 | Name: &ast.Ident{Name: name}, 89 | Path: &ast.BasicLit{Kind: 9, Value: path}, 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/ginkgo/convert/test_finder.go: -------------------------------------------------------------------------------- 1 | package convert 2 | 3 | import ( 4 | "go/ast" 5 | "regexp" 6 | ) 7 | 8 | /* 9 | * Given a root node, walks its top level statements and returns 10 | * points to function nodes to rewrite as It statements. 11 | * These functions, according to Go testing convention, must be named 12 | * TestWithCamelCasedName and receive a single *testing.T argument. 13 | */ 14 | func findTestFuncs(rootNode *ast.File) (testsToRewrite []*ast.FuncDecl) { 15 | testNameRegexp := regexp.MustCompile("^Test[0-9A-Z].+") 16 | 17 | ast.Inspect(rootNode, func(node ast.Node) bool { 18 | if node == nil { 19 | return false 20 | } 21 | 22 | switch node := node.(type) { 23 | case *ast.FuncDecl: 24 | matches := testNameRegexp.MatchString(node.Name.Name) 25 | 26 | if matches && receivesTestingT(node) { 27 | testsToRewrite = append(testsToRewrite, node) 28 | } 29 | } 30 | 31 | return true 32 | }) 33 | 34 | return 35 | } 36 | 37 | /* 38 | * convenience function that looks at args to a function and determines if its 39 | * params include an argument of type *testing.T 40 | */ 41 | func receivesTestingT(node *ast.FuncDecl) bool { 42 | if len(node.Type.Params.List) != 1 { 43 | return false 44 | } 45 | 46 | base, ok := node.Type.Params.List[0].Type.(*ast.StarExpr) 47 | if !ok { 48 | return false 49 | } 50 | 51 | intermediate := base.X.(*ast.SelectorExpr) 52 | isTestingPackage := intermediate.X.(*ast.Ident).Name == "testing" 53 | isTestingT := intermediate.Sel.Name == "T" 54 | 55 | return isTestingPackage && isTestingT 56 | } 57 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/ginkgo/convert_command.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "github.com/onsi/ginkgo/ginkgo/convert" 7 | "os" 8 | ) 9 | 10 | func BuildConvertCommand() *Command { 11 | return &Command{ 12 | Name: "convert", 13 | FlagSet: flag.NewFlagSet("convert", flag.ExitOnError), 14 | UsageCommand: "ginkgo convert /path/to/package", 15 | Usage: []string{ 16 | "Convert the package at the passed in path from an XUnit-style test to a Ginkgo-style test", 17 | }, 18 | Command: convertPackage, 19 | } 20 | } 21 | 22 | func convertPackage(args []string, additionalArgs []string) { 23 | if len(args) != 1 { 24 | println(fmt.Sprintf("usage: ginkgo convert /path/to/your/package")) 25 | os.Exit(1) 26 | } 27 | 28 | defer func() { 29 | err := recover() 30 | if err != nil { 31 | switch err := err.(type) { 32 | case error: 33 | println(err.Error()) 34 | case string: 35 | println(err) 36 | default: 37 | println(fmt.Sprintf("unexpected error: %#v", err)) 38 | } 39 | os.Exit(1) 40 | } 41 | }() 42 | 43 | convert.RewritePackage(args[0]) 44 | } 45 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/ginkgo/help_command.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | ) 7 | 8 | func BuildHelpCommand() *Command { 9 | return &Command{ 10 | Name: "help", 11 | FlagSet: flag.NewFlagSet("help", flag.ExitOnError), 12 | UsageCommand: "ginkgo help ", 13 | Usage: []string{ 14 | "Print usage information. If a command is passed in, print usage information just for that command.", 15 | }, 16 | Command: printHelp, 17 | } 18 | } 19 | 20 | func printHelp(args []string, additionalArgs []string) { 21 | if len(args) == 0 { 22 | usage() 23 | } else { 24 | command, found := commandMatching(args[0]) 25 | if !found { 26 | complainAndQuit(fmt.Sprintf("Unkown command: %s", args[0])) 27 | } 28 | 29 | usageForCommand(command, true) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/ginkgo/interrupt_handler.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "os/signal" 6 | "sync" 7 | ) 8 | 9 | type InterruptHandler struct { 10 | interruptCount int 11 | lock *sync.Mutex 12 | C chan bool 13 | } 14 | 15 | func NewInterruptHandler() *InterruptHandler { 16 | h := &InterruptHandler{ 17 | lock: &sync.Mutex{}, 18 | C: make(chan bool, 0), 19 | } 20 | 21 | go h.handleInterrupt() 22 | 23 | return h 24 | } 25 | 26 | func (h *InterruptHandler) WasInterrupted() bool { 27 | h.lock.Lock() 28 | defer h.lock.Unlock() 29 | 30 | return h.interruptCount > 0 31 | } 32 | 33 | func (h *InterruptHandler) handleInterrupt() { 34 | c := make(chan os.Signal, 1) 35 | signal.Notify(c, os.Interrupt) 36 | 37 | <-c 38 | signal.Stop(c) 39 | 40 | h.lock.Lock() 41 | h.interruptCount++ 42 | if h.interruptCount == 1 { 43 | close(h.C) 44 | } else if h.interruptCount > 5 { 45 | os.Exit(1) 46 | } 47 | h.lock.Unlock() 48 | 49 | go h.handleInterrupt() 50 | } 51 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/ginkgo/nodot_command.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "flag" 6 | "github.com/onsi/ginkgo/ginkgo/nodot" 7 | "io/ioutil" 8 | "os" 9 | "path/filepath" 10 | "regexp" 11 | ) 12 | 13 | func BuildNodotCommand() *Command { 14 | return &Command{ 15 | Name: "nodot", 16 | FlagSet: flag.NewFlagSet("bootstrap", flag.ExitOnError), 17 | UsageCommand: "ginkgo nodot", 18 | Usage: []string{ 19 | "Update the nodot declarations in your test suite", 20 | "Any missing declarations (from, say, a recently added matcher) will be added to your bootstrap file.", 21 | "If you've renamed a declaration, that name will be honored and not overwritten.", 22 | }, 23 | Command: updateNodot, 24 | } 25 | } 26 | 27 | func updateNodot(args []string, additionalArgs []string) { 28 | suiteFile, perm := findSuiteFile() 29 | 30 | data, err := ioutil.ReadFile(suiteFile) 31 | if err != nil { 32 | complainAndQuit("Failed to update nodot declarations: " + err.Error()) 33 | } 34 | 35 | content, err := nodot.ApplyNoDot(data) 36 | if err != nil { 37 | complainAndQuit("Failed to update nodot declarations: " + err.Error()) 38 | } 39 | ioutil.WriteFile(suiteFile, content, perm) 40 | 41 | goFmt(suiteFile) 42 | } 43 | 44 | func findSuiteFile() (string, os.FileMode) { 45 | workingDir, err := os.Getwd() 46 | if err != nil { 47 | complainAndQuit("Could not find suite file for nodot: " + err.Error()) 48 | } 49 | 50 | files, err := ioutil.ReadDir(workingDir) 51 | if err != nil { 52 | complainAndQuit("Could not find suite file for nodot: " + err.Error()) 53 | } 54 | 55 | re := regexp.MustCompile(`RunSpecs\(|RunSpecsWithDefaultAndCustomReporters\(|RunSpecsWithCustomReporters\(`) 56 | 57 | for _, file := range files { 58 | if file.IsDir() { 59 | continue 60 | } 61 | path := filepath.Join(workingDir, file.Name()) 62 | f, err := os.Open(path) 63 | if err != nil { 64 | complainAndQuit("Could not find suite file for nodot: " + err.Error()) 65 | } 66 | if re.MatchReader(bufio.NewReader(f)) { 67 | return path, file.Mode() 68 | } 69 | } 70 | 71 | complainAndQuit("Could not find a suite file for nodot: you need a bootstrap file that call's Ginkgo's RunSpecs() command.\nTry running ginkgo bootstrap first.") 72 | 73 | return "", 0 74 | } 75 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/ginkgo/notifications.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "os/exec" 7 | 8 | "github.com/onsi/ginkgo/ginkgo/testsuite" 9 | ) 10 | 11 | type Notifier struct { 12 | commandFlags *RunAndWatchCommandFlags 13 | } 14 | 15 | func NewNotifier(commandFlags *RunAndWatchCommandFlags) *Notifier { 16 | return &Notifier{ 17 | commandFlags: commandFlags, 18 | } 19 | } 20 | 21 | func (n *Notifier) VerifyNotificationsAreAvailable() { 22 | if n.commandFlags.Notify { 23 | _, err := exec.LookPath("terminal-notifier") 24 | if err != nil { 25 | fmt.Printf(`--notify requires terminal-notifier, which you don't seem to have installed. 26 | 27 | To remedy this: 28 | 29 | brew install terminal-notifier 30 | 31 | To learn more about terminal-notifier: 32 | 33 | https://github.com/alloy/terminal-notifier 34 | `) 35 | os.Exit(1) 36 | } 37 | } 38 | } 39 | 40 | func (n *Notifier) SendSuiteCompletionNotification(suite testsuite.TestSuite, suitePassed bool) { 41 | if suitePassed { 42 | n.SendNotification("Ginkgo [PASS]", fmt.Sprintf(`Test suite for "%s" passed.`, suite.PackageName)) 43 | } else { 44 | n.SendNotification("Ginkgo [FAIL]", fmt.Sprintf(`Test suite for "%s" failed.`, suite.PackageName)) 45 | } 46 | } 47 | 48 | func (n *Notifier) SendNotification(title string, subtitle string) { 49 | args := []string{"-title", title, "-subtitle", subtitle, "-group", "com.onsi.ginkgo"} 50 | 51 | terminal := os.Getenv("TERM_PROGRAM") 52 | if terminal == "iTerm.app" { 53 | args = append(args, "-activate", "com.googlecode.iterm2") 54 | } else if terminal == "Apple_Terminal" { 55 | args = append(args, "-activate", "com.apple.Terminal") 56 | } 57 | 58 | if n.commandFlags.Notify { 59 | exec.Command("terminal-notifier", args...).Run() 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/ginkgo/testrunner/log_writer.go: -------------------------------------------------------------------------------- 1 | package testrunner 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "io" 7 | "log" 8 | "strings" 9 | "sync" 10 | ) 11 | 12 | type logWriter struct { 13 | buffer *bytes.Buffer 14 | lock *sync.Mutex 15 | log *log.Logger 16 | } 17 | 18 | func newLogWriter(target io.Writer, node int) *logWriter { 19 | return &logWriter{ 20 | buffer: &bytes.Buffer{}, 21 | lock: &sync.Mutex{}, 22 | log: log.New(target, fmt.Sprintf("[%d] ", node), 0), 23 | } 24 | } 25 | 26 | func (w *logWriter) Write(data []byte) (n int, err error) { 27 | w.lock.Lock() 28 | defer w.lock.Unlock() 29 | 30 | w.buffer.Write(data) 31 | contents := w.buffer.String() 32 | 33 | lines := strings.Split(contents, "\n") 34 | for _, line := range lines[0 : len(lines)-1] { 35 | w.log.Println(line) 36 | } 37 | 38 | w.buffer.Reset() 39 | w.buffer.Write([]byte(lines[len(lines)-1])) 40 | return len(data), nil 41 | } 42 | 43 | func (w *logWriter) Close() error { 44 | w.lock.Lock() 45 | defer w.lock.Unlock() 46 | 47 | if w.buffer.Len() > 0 { 48 | w.log.Println(w.buffer.String()) 49 | } 50 | 51 | return nil 52 | } 53 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/ginkgo/testrunner/run_result.go: -------------------------------------------------------------------------------- 1 | package testrunner 2 | 3 | type RunResult struct { 4 | Passed bool 5 | HasProgrammaticFocus bool 6 | } 7 | 8 | func PassingRunResult() RunResult { 9 | return RunResult{ 10 | Passed: true, 11 | HasProgrammaticFocus: false, 12 | } 13 | } 14 | 15 | func FailingRunResult() RunResult { 16 | return RunResult{ 17 | Passed: false, 18 | HasProgrammaticFocus: false, 19 | } 20 | } 21 | 22 | func (r RunResult) Merge(o RunResult) RunResult { 23 | return RunResult{ 24 | Passed: r.Passed && o.Passed, 25 | HasProgrammaticFocus: r.HasProgrammaticFocus || o.HasProgrammaticFocus, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/ginkgo/testsuite/test_suite.go: -------------------------------------------------------------------------------- 1 | package testsuite 2 | 3 | import ( 4 | "io/ioutil" 5 | "os" 6 | "path/filepath" 7 | "regexp" 8 | ) 9 | 10 | type TestSuite struct { 11 | Path string 12 | PackageName string 13 | IsGinkgo bool 14 | } 15 | 16 | func SuitesInDir(dir string, recurse bool) []TestSuite { 17 | suites := []TestSuite{} 18 | files, _ := ioutil.ReadDir(dir) 19 | re := regexp.MustCompile(`_test\.go$`) 20 | for _, file := range files { 21 | if !file.IsDir() && re.Match([]byte(file.Name())) { 22 | suites = append(suites, New(dir, files)) 23 | break 24 | } 25 | } 26 | 27 | if recurse { 28 | re = regexp.MustCompile(`^[._]`) 29 | for _, file := range files { 30 | if file.IsDir() && !re.Match([]byte(file.Name())) { 31 | suites = append(suites, SuitesInDir(dir+"/"+file.Name(), recurse)...) 32 | } 33 | } 34 | } 35 | 36 | return suites 37 | } 38 | 39 | func New(dir string, files []os.FileInfo) TestSuite { 40 | dir, _ = filepath.Abs(dir) 41 | cwd, _ := os.Getwd() 42 | dir, _ = filepath.Rel(cwd, filepath.Clean(dir)) 43 | dir = "." + string(filepath.Separator) + dir 44 | 45 | return TestSuite{ 46 | Path: dir, 47 | PackageName: packageNameForSuite(dir), 48 | IsGinkgo: filesHaveGinkgoSuite(dir, files), 49 | } 50 | } 51 | 52 | func packageNameForSuite(dir string) string { 53 | path, _ := filepath.Abs(dir) 54 | return filepath.Base(path) 55 | } 56 | 57 | func filesHaveGinkgoSuite(dir string, files []os.FileInfo) bool { 58 | reTestFile := regexp.MustCompile(`_test\.go$`) 59 | reGinkgo := regexp.MustCompile(`package ginkgo|\/ginkgo"`) 60 | 61 | for _, file := range files { 62 | if !file.IsDir() && reTestFile.Match([]byte(file.Name())) { 63 | contents, _ := ioutil.ReadFile(dir + "/" + file.Name()) 64 | if reGinkgo.Match(contents) { 65 | return true 66 | } 67 | } 68 | } 69 | 70 | return false 71 | } 72 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/ginkgo/testsuite/testsuite_suite_test.go: -------------------------------------------------------------------------------- 1 | package testsuite_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | 7 | "testing" 8 | ) 9 | 10 | func TestTestsuite(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "Testsuite Suite") 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/ginkgo/unfocus_command.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "os/exec" 7 | ) 8 | 9 | func BuildUnfocusCommand() *Command { 10 | return &Command{ 11 | Name: "unfocus", 12 | AltName: "blur", 13 | FlagSet: flag.NewFlagSet("unfocus", flag.ExitOnError), 14 | UsageCommand: "ginkgo unfocus (or ginkgo blur)", 15 | Usage: []string{ 16 | "Recursively unfocuses any focused tests under the current directory", 17 | }, 18 | Command: unfocusSpecs, 19 | } 20 | } 21 | 22 | func unfocusSpecs([]string, []string) { 23 | unfocus("Describe") 24 | unfocus("Context") 25 | unfocus("It") 26 | unfocus("Measure") 27 | } 28 | 29 | func unfocus(component string) { 30 | fmt.Printf("Removing F%s...\n", component) 31 | cmd := exec.Command("gofmt", fmt.Sprintf("-r=F%s -> %s", component, component), "-w", ".") 32 | out, _ := cmd.CombinedOutput() 33 | if string(out) != "" { 34 | println(string(out)) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/ginkgo/version_command.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "github.com/onsi/ginkgo/config" 7 | ) 8 | 9 | func BuildVersionCommand() *Command { 10 | return &Command{ 11 | Name: "version", 12 | FlagSet: flag.NewFlagSet("version", flag.ExitOnError), 13 | UsageCommand: "ginkgo version", 14 | Usage: []string{ 15 | "Print Ginkgo's version", 16 | }, 17 | Command: printVersion, 18 | } 19 | } 20 | 21 | func printVersion([]string, []string) { 22 | fmt.Printf("Ginkgo Version %s\n", config.VERSION) 23 | } 24 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/ginkgo/watch/delta.go: -------------------------------------------------------------------------------- 1 | package watch 2 | 3 | import "sort" 4 | 5 | type Delta struct { 6 | ModifiedPackages []string 7 | 8 | NewSuites []*Suite 9 | RemovedSuites []*Suite 10 | modifiedSuites []*Suite 11 | } 12 | 13 | type DescendingByDelta []*Suite 14 | 15 | func (a DescendingByDelta) Len() int { return len(a) } 16 | func (a DescendingByDelta) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 17 | func (a DescendingByDelta) Less(i, j int) bool { return a[i].Delta() > a[j].Delta() } 18 | 19 | func (d Delta) ModifiedSuites() []*Suite { 20 | sort.Sort(DescendingByDelta(d.modifiedSuites)) 21 | return d.modifiedSuites 22 | } 23 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/ginkgo/watch/delta_tracker.go: -------------------------------------------------------------------------------- 1 | package watch 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/onsi/ginkgo/ginkgo/testsuite" 7 | ) 8 | 9 | type SuiteErrors map[testsuite.TestSuite]error 10 | 11 | type DeltaTracker struct { 12 | maxDepth int 13 | suites map[string]*Suite 14 | packageHashes *PackageHashes 15 | } 16 | 17 | func NewDeltaTracker(maxDepth int) *DeltaTracker { 18 | return &DeltaTracker{ 19 | maxDepth: maxDepth, 20 | packageHashes: NewPackageHashes(), 21 | suites: map[string]*Suite{}, 22 | } 23 | } 24 | 25 | func (d *DeltaTracker) Delta(suites []testsuite.TestSuite) (delta Delta, errors SuiteErrors) { 26 | errors = SuiteErrors{} 27 | delta.ModifiedPackages = d.packageHashes.CheckForChanges() 28 | 29 | providedSuitePaths := map[string]bool{} 30 | for _, suite := range suites { 31 | providedSuitePaths[suite.Path] = true 32 | } 33 | 34 | d.packageHashes.StartTrackingUsage() 35 | 36 | for _, suite := range d.suites { 37 | if providedSuitePaths[suite.Suite.Path] { 38 | if suite.Delta() > 0 { 39 | delta.modifiedSuites = append(delta.modifiedSuites, suite) 40 | } 41 | } else { 42 | delta.RemovedSuites = append(delta.RemovedSuites, suite) 43 | } 44 | } 45 | 46 | d.packageHashes.StopTrackingUsageAndPrune() 47 | 48 | for _, suite := range suites { 49 | _, ok := d.suites[suite.Path] 50 | if !ok { 51 | s, err := NewSuite(suite, d.maxDepth, d.packageHashes) 52 | if err != nil { 53 | errors[suite] = err 54 | continue 55 | } 56 | d.suites[suite.Path] = s 57 | delta.NewSuites = append(delta.NewSuites, s) 58 | } 59 | } 60 | 61 | return delta, errors 62 | } 63 | 64 | func (d *DeltaTracker) WillRun(suite testsuite.TestSuite) error { 65 | s, ok := d.suites[suite.Path] 66 | if !ok { 67 | return fmt.Errorf("unkown suite %s", suite.Path) 68 | } 69 | 70 | return s.MarkAsRunAndRecomputedDependencies(d.maxDepth) 71 | } 72 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/ginkgo/watch/dependencies.go: -------------------------------------------------------------------------------- 1 | package watch 2 | 3 | import ( 4 | "go/build" 5 | "regexp" 6 | ) 7 | 8 | var ginkgoAndGomegaFilter = regexp.MustCompile(`github\.com/onsi/ginkgo|github\.com/onsi/gomega`) 9 | 10 | type Dependencies struct { 11 | deps map[string]int 12 | } 13 | 14 | func NewDependencies(path string, maxDepth int) (Dependencies, error) { 15 | d := Dependencies{ 16 | deps: map[string]int{}, 17 | } 18 | 19 | if maxDepth == 0 { 20 | return d, nil 21 | } 22 | 23 | err := d.seedWithDepsForPackageAtPath(path) 24 | if err != nil { 25 | return d, err 26 | } 27 | 28 | for depth := 1; depth < maxDepth; depth++ { 29 | n := len(d.deps) 30 | d.addDepsForDepth(depth) 31 | if n == len(d.deps) { 32 | break 33 | } 34 | } 35 | 36 | return d, nil 37 | } 38 | 39 | func (d Dependencies) Dependencies() map[string]int { 40 | return d.deps 41 | } 42 | 43 | func (d Dependencies) seedWithDepsForPackageAtPath(path string) error { 44 | pkg, err := build.ImportDir(path, 0) 45 | if err != nil { 46 | return err 47 | } 48 | 49 | d.resolveAndAdd(pkg.Imports, 1) 50 | d.resolveAndAdd(pkg.TestImports, 1) 51 | d.resolveAndAdd(pkg.XTestImports, 1) 52 | 53 | delete(d.deps, pkg.Dir) 54 | return nil 55 | } 56 | 57 | func (d Dependencies) addDepsForDepth(depth int) { 58 | for dep, depDepth := range d.deps { 59 | if depDepth == depth { 60 | d.addDepsForDep(dep, depth+1) 61 | } 62 | } 63 | } 64 | 65 | func (d Dependencies) addDepsForDep(dep string, depth int) { 66 | pkg, err := build.ImportDir(dep, 0) 67 | if err != nil { 68 | println(err.Error()) 69 | return 70 | } 71 | d.resolveAndAdd(pkg.Imports, depth) 72 | } 73 | 74 | func (d Dependencies) resolveAndAdd(deps []string, depth int) { 75 | for _, dep := range deps { 76 | pkg, err := build.Import(dep, ".", 0) 77 | if err != nil { 78 | continue 79 | } 80 | if pkg.Goroot == false && !ginkgoAndGomegaFilter.Match([]byte(pkg.Dir)) { 81 | d.addDepIfNotPresent(pkg.Dir, depth) 82 | } 83 | } 84 | } 85 | 86 | func (d Dependencies) addDepIfNotPresent(dep string, depth int) { 87 | _, ok := d.deps[dep] 88 | if !ok { 89 | d.deps[dep] = depth 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/ginkgo/watch/package_hash.go: -------------------------------------------------------------------------------- 1 | package watch 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "os" 7 | "regexp" 8 | "time" 9 | ) 10 | 11 | var goRegExp = regexp.MustCompile(`\.go$`) 12 | var goTestRegExp = regexp.MustCompile(`_test\.go$`) 13 | 14 | type PackageHash struct { 15 | CodeModifiedTime time.Time 16 | TestModifiedTime time.Time 17 | Deleted bool 18 | 19 | path string 20 | codeHash string 21 | testHash string 22 | } 23 | 24 | func NewPackageHash(path string) *PackageHash { 25 | p := &PackageHash{ 26 | path: path, 27 | } 28 | 29 | p.codeHash, _, p.testHash, _, p.Deleted = p.computeHashes() 30 | 31 | return p 32 | } 33 | 34 | func (p *PackageHash) CheckForChanges() bool { 35 | codeHash, codeModifiedTime, testHash, testModifiedTime, deleted := p.computeHashes() 36 | 37 | if deleted { 38 | if p.Deleted == false { 39 | t := time.Now() 40 | p.CodeModifiedTime = t 41 | p.TestModifiedTime = t 42 | } 43 | p.Deleted = true 44 | return true 45 | } 46 | 47 | modified := false 48 | p.Deleted = false 49 | 50 | if p.codeHash != codeHash { 51 | p.CodeModifiedTime = codeModifiedTime 52 | modified = true 53 | } 54 | if p.testHash != testHash { 55 | p.TestModifiedTime = testModifiedTime 56 | modified = true 57 | } 58 | 59 | p.codeHash = codeHash 60 | p.testHash = testHash 61 | return modified 62 | } 63 | 64 | func (p *PackageHash) computeHashes() (codeHash string, codeModifiedTime time.Time, testHash string, testModifiedTime time.Time, deleted bool) { 65 | infos, err := ioutil.ReadDir(p.path) 66 | 67 | if err != nil { 68 | deleted = true 69 | return 70 | } 71 | 72 | for _, info := range infos { 73 | if info.IsDir() { 74 | continue 75 | } 76 | 77 | if goTestRegExp.Match([]byte(info.Name())) { 78 | testHash += p.hashForFileInfo(info) 79 | if info.ModTime().After(testModifiedTime) { 80 | testModifiedTime = info.ModTime() 81 | } 82 | continue 83 | } 84 | 85 | if goRegExp.Match([]byte(info.Name())) { 86 | codeHash += p.hashForFileInfo(info) 87 | if info.ModTime().After(codeModifiedTime) { 88 | codeModifiedTime = info.ModTime() 89 | } 90 | } 91 | } 92 | 93 | testHash += codeHash 94 | if codeModifiedTime.After(testModifiedTime) { 95 | testModifiedTime = codeModifiedTime 96 | } 97 | 98 | return 99 | } 100 | 101 | func (p *PackageHash) hashForFileInfo(info os.FileInfo) string { 102 | return fmt.Sprintf("%s_%d_%d", info.Name(), info.Size(), info.ModTime().UnixNano()) 103 | } 104 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/ginkgo/watch/package_hashes.go: -------------------------------------------------------------------------------- 1 | package watch 2 | 3 | import ( 4 | "path/filepath" 5 | "sync" 6 | ) 7 | 8 | type PackageHashes struct { 9 | PackageHashes map[string]*PackageHash 10 | usedPaths map[string]bool 11 | lock *sync.Mutex 12 | } 13 | 14 | func NewPackageHashes() *PackageHashes { 15 | return &PackageHashes{ 16 | PackageHashes: map[string]*PackageHash{}, 17 | usedPaths: nil, 18 | lock: &sync.Mutex{}, 19 | } 20 | } 21 | 22 | func (p *PackageHashes) CheckForChanges() []string { 23 | p.lock.Lock() 24 | defer p.lock.Unlock() 25 | 26 | modified := []string{} 27 | 28 | for _, packageHash := range p.PackageHashes { 29 | if packageHash.CheckForChanges() { 30 | modified = append(modified, packageHash.path) 31 | } 32 | } 33 | 34 | return modified 35 | } 36 | 37 | func (p *PackageHashes) Add(path string) *PackageHash { 38 | p.lock.Lock() 39 | defer p.lock.Unlock() 40 | 41 | path, _ = filepath.Abs(path) 42 | _, ok := p.PackageHashes[path] 43 | if !ok { 44 | p.PackageHashes[path] = NewPackageHash(path) 45 | } 46 | 47 | if p.usedPaths != nil { 48 | p.usedPaths[path] = true 49 | } 50 | return p.PackageHashes[path] 51 | } 52 | 53 | func (p *PackageHashes) Get(path string) *PackageHash { 54 | p.lock.Lock() 55 | defer p.lock.Unlock() 56 | 57 | path, _ = filepath.Abs(path) 58 | if p.usedPaths != nil { 59 | p.usedPaths[path] = true 60 | } 61 | return p.PackageHashes[path] 62 | } 63 | 64 | func (p *PackageHashes) StartTrackingUsage() { 65 | p.lock.Lock() 66 | defer p.lock.Unlock() 67 | 68 | p.usedPaths = map[string]bool{} 69 | } 70 | 71 | func (p *PackageHashes) StopTrackingUsageAndPrune() { 72 | p.lock.Lock() 73 | defer p.lock.Unlock() 74 | 75 | for path := range p.PackageHashes { 76 | if !p.usedPaths[path] { 77 | delete(p.PackageHashes, path) 78 | } 79 | } 80 | 81 | p.usedPaths = nil 82 | } 83 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/ginkgo/watch/suite.go: -------------------------------------------------------------------------------- 1 | package watch 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | "time" 7 | 8 | "github.com/onsi/ginkgo/ginkgo/testsuite" 9 | ) 10 | 11 | type Suite struct { 12 | Suite testsuite.TestSuite 13 | RunTime time.Time 14 | Dependencies Dependencies 15 | 16 | sharedPackageHashes *PackageHashes 17 | } 18 | 19 | func NewSuite(suite testsuite.TestSuite, maxDepth int, sharedPackageHashes *PackageHashes) (*Suite, error) { 20 | deps, err := NewDependencies(suite.Path, maxDepth) 21 | if err != nil { 22 | return nil, err 23 | } 24 | 25 | sharedPackageHashes.Add(suite.Path) 26 | for dep := range deps.Dependencies() { 27 | sharedPackageHashes.Add(dep) 28 | } 29 | 30 | return &Suite{ 31 | Suite: suite, 32 | Dependencies: deps, 33 | 34 | sharedPackageHashes: sharedPackageHashes, 35 | }, nil 36 | } 37 | 38 | func (s *Suite) Delta() float64 { 39 | delta := s.delta(s.Suite.Path, true, 0) * 1000 40 | for dep, depth := range s.Dependencies.Dependencies() { 41 | delta += s.delta(dep, false, depth) 42 | } 43 | return delta 44 | } 45 | 46 | func (s *Suite) MarkAsRunAndRecomputedDependencies(maxDepth int) error { 47 | s.RunTime = time.Now() 48 | 49 | deps, err := NewDependencies(s.Suite.Path, maxDepth) 50 | if err != nil { 51 | return err 52 | } 53 | 54 | s.sharedPackageHashes.Add(s.Suite.Path) 55 | for dep := range deps.Dependencies() { 56 | s.sharedPackageHashes.Add(dep) 57 | } 58 | 59 | s.Dependencies = deps 60 | 61 | return nil 62 | } 63 | 64 | func (s *Suite) Description() string { 65 | numDeps := len(s.Dependencies.Dependencies()) 66 | pluralizer := "ies" 67 | if numDeps == 1 { 68 | pluralizer = "y" 69 | } 70 | return fmt.Sprintf("%s [%d dependenc%s]", s.Suite.Path, numDeps, pluralizer) 71 | } 72 | 73 | func (s *Suite) delta(packagePath string, includeTests bool, depth int) float64 { 74 | return math.Max(float64(s.dt(packagePath, includeTests)), 0) / float64(depth+1) 75 | } 76 | 77 | func (s *Suite) dt(packagePath string, includeTests bool) time.Duration { 78 | packageHash := s.sharedPackageHashes.Get(packagePath) 79 | var modifiedTime time.Time 80 | if includeTests { 81 | modifiedTime = packageHash.TestModifiedTime 82 | } else { 83 | modifiedTime = packageHash.CodeModifiedTime 84 | } 85 | 86 | return modifiedTime.Sub(s.RunTime) 87 | } 88 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/integration/coverage_test.go: -------------------------------------------------------------------------------- 1 | package integration_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | "github.com/onsi/gomega/gexec" 7 | "os" 8 | "os/exec" 9 | ) 10 | 11 | var _ = Describe("Coverage Specs", func() { 12 | AfterEach(func() { 13 | os.RemoveAll("./_fixtures/coverage_fixture/coverage_fixture.coverprofile") 14 | }) 15 | 16 | It("runs coverage analysis in series and in parallel", func() { 17 | session := startGinkgo("./_fixtures/coverage_fixture", "-cover") 18 | Eventually(session).Should(gexec.Exit(0)) 19 | output := session.Out.Contents() 20 | Ω(output).Should(ContainSubstring("coverage: 80.0% of statements")) 21 | 22 | serialCoverProfileOutput, err := exec.Command("go", "tool", "cover", "-func=./_fixtures/coverage_fixture/coverage_fixture.coverprofile").CombinedOutput() 23 | Ω(err).ShouldNot(HaveOccurred()) 24 | 25 | os.RemoveAll("./_fixtures/coverage_fixture/coverage_fixture.coverprofile") 26 | 27 | Eventually(startGinkgo("./_fixtures/coverage_fixture", "-cover", "-nodes=4")).Should(gexec.Exit(0)) 28 | 29 | parallelCoverProfileOutput, err := exec.Command("go", "tool", "cover", "-func=./_fixtures/coverage_fixture/coverage_fixture.coverprofile").CombinedOutput() 30 | Ω(err).ShouldNot(HaveOccurred()) 31 | 32 | Ω(parallelCoverProfileOutput).Should(Equal(serialCoverProfileOutput)) 33 | }) 34 | }) 35 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/integration/fail_test.go: -------------------------------------------------------------------------------- 1 | package integration_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | "github.com/onsi/gomega/gexec" 7 | ) 8 | 9 | var _ = Describe("Failing Specs", func() { 10 | var pathToTest string 11 | 12 | BeforeEach(func() { 13 | pathToTest = tmpPath("failing") 14 | copyIn("fail_fixture", pathToTest) 15 | }) 16 | 17 | It("should fail in all the possible ways", func() { 18 | session := startGinkgo(pathToTest, "--noColor") 19 | Eventually(session).Should(gexec.Exit(1)) 20 | output := string(session.Out.Contents()) 21 | 22 | Ω(output).ShouldNot(ContainSubstring("NEVER SEE THIS")) 23 | 24 | Ω(output).Should(ContainSubstring("a top level failure on line 9")) 25 | Ω(output).Should(ContainSubstring("fail_fixture_test.go:9")) 26 | Ω(output).Should(ContainSubstring("an async top level failure on line 14")) 27 | Ω(output).Should(ContainSubstring("fail_fixture_test.go:14")) 28 | Ω(output).Should(ContainSubstring("a top level goroutine failure on line 21")) 29 | Ω(output).Should(ContainSubstring("fail_fixture_test.go:21")) 30 | 31 | Ω(output).Should(ContainSubstring("a sync failure")) 32 | Ω(output).Should(MatchRegexp(`Test Panicked\n\s+a sync panic`)) 33 | Ω(output).Should(ContainSubstring("a sync FAIL failure")) 34 | Ω(output).Should(ContainSubstring("async timeout [It]")) 35 | Ω(output).Should(ContainSubstring("Timed out")) 36 | Ω(output).Should(ContainSubstring("an async failure")) 37 | Ω(output).Should(MatchRegexp(`Test Panicked\n\s+an async panic`)) 38 | Ω(output).Should(ContainSubstring("an async FAIL failure")) 39 | Ω(output).Should(ContainSubstring("a goroutine FAIL failure")) 40 | Ω(output).Should(ContainSubstring("a goroutine failure")) 41 | Ω(output).Should(MatchRegexp(`Test Panicked\n\s+a goroutine panic`)) 42 | Ω(output).Should(ContainSubstring("a measure failure")) 43 | Ω(output).Should(ContainSubstring("a measure FAIL failure")) 44 | Ω(output).Should(MatchRegexp(`Test Panicked\n\s+a measure panic`)) 45 | 46 | Ω(output).Should(ContainSubstring("0 Passed | 16 Failed")) 47 | }) 48 | }) 49 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/integration/integration.go: -------------------------------------------------------------------------------- 1 | package integration 2 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/integration/integration_suite_test.go: -------------------------------------------------------------------------------- 1 | package integration_test 2 | 3 | import ( 4 | "io" 5 | "io/ioutil" 6 | "os" 7 | "os/exec" 8 | "path/filepath" 9 | "strings" 10 | . "github.com/onsi/ginkgo" 11 | . "github.com/onsi/gomega" 12 | "github.com/onsi/gomega/gexec" 13 | 14 | "testing" 15 | "time" 16 | ) 17 | 18 | var tmpDir string 19 | var pathToGinkgo string 20 | 21 | func TestIntegration(t *testing.T) { 22 | SetDefaultEventuallyTimeout(15 * time.Second) 23 | RegisterFailHandler(Fail) 24 | RunSpecs(t, "Integration Suite") 25 | } 26 | 27 | var _ = BeforeSuite(func() { 28 | var err error 29 | pathToGinkgo, err = gexec.Build("github.com/onsi/ginkgo/ginkgo") 30 | Ω(err).ShouldNot(HaveOccurred()) 31 | }) 32 | 33 | var _ = BeforeEach(func() { 34 | var err error 35 | tmpDir, err = ioutil.TempDir("", "ginkgo-run") 36 | Ω(err).ShouldNot(HaveOccurred()) 37 | }) 38 | 39 | var _ = AfterEach(func() { 40 | err := os.RemoveAll(tmpDir) 41 | Ω(err).ShouldNot(HaveOccurred()) 42 | }) 43 | 44 | var _ = AfterSuite(func() { 45 | gexec.CleanupBuildArtifacts() 46 | }) 47 | 48 | func tmpPath(destination string) string { 49 | return filepath.Join(tmpDir, destination) 50 | } 51 | 52 | func copyIn(fixture string, destination string) { 53 | err := os.MkdirAll(destination, 0777) 54 | Ω(err).ShouldNot(HaveOccurred()) 55 | 56 | filepath.Walk(filepath.Join("_fixtures", fixture), func(path string, info os.FileInfo, err error) error { 57 | if info.IsDir() { 58 | return nil 59 | } 60 | 61 | base := filepath.Base(path) 62 | 63 | src, err := os.Open(path) 64 | Ω(err).ShouldNot(HaveOccurred()) 65 | 66 | dst, err := os.Create(filepath.Join(destination, base)) 67 | Ω(err).ShouldNot(HaveOccurred()) 68 | 69 | _, err = io.Copy(dst, src) 70 | Ω(err).ShouldNot(HaveOccurred()) 71 | return nil 72 | }) 73 | } 74 | 75 | func ginkgoCommand(dir string, args ...string) *exec.Cmd { 76 | cmd := exec.Command(pathToGinkgo, args...) 77 | cmd.Dir = dir 78 | cmd.Env = []string{} 79 | for _, env := range os.Environ() { 80 | if !strings.Contains(env, "GINKGO_REMOTE_REPORTING_SERVER") { 81 | cmd.Env = append(cmd.Env, env) 82 | } 83 | } 84 | 85 | return cmd 86 | } 87 | 88 | func startGinkgo(dir string, args ...string) *gexec.Session { 89 | cmd := ginkgoCommand(dir, args...) 90 | session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) 91 | Ω(err).ShouldNot(HaveOccurred()) 92 | return session 93 | } 94 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/integration/tags_test.go: -------------------------------------------------------------------------------- 1 | package integration_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | "github.com/onsi/gomega/gexec" 7 | ) 8 | 9 | var _ = Describe("Tags", func() { 10 | var pathToTest string 11 | BeforeEach(func() { 12 | pathToTest = tmpPath("tags") 13 | copyIn("tags_tests", pathToTest) 14 | }) 15 | 16 | It("should honor the passed in -tags flag", func() { 17 | session := startGinkgo(pathToTest, "--noColor") 18 | Eventually(session).Should(gexec.Exit(0)) 19 | output := string(session.Out.Contents()) 20 | Ω(output).Should(ContainSubstring("Ran 1 of 1 Specs")) 21 | 22 | session = startGinkgo(pathToTest, "--noColor", "-tags=complex_tests") 23 | Eventually(session).Should(gexec.Exit(0)) 24 | output = string(session.Out.Contents()) 25 | Ω(output).Should(ContainSubstring("Ran 3 of 3 Specs")) 26 | }) 27 | }) 28 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/codelocation/code_location.go: -------------------------------------------------------------------------------- 1 | package codelocation 2 | 3 | import ( 4 | "regexp" 5 | "runtime" 6 | "runtime/debug" 7 | "strings" 8 | 9 | "github.com/onsi/ginkgo/types" 10 | ) 11 | 12 | func New(skip int) types.CodeLocation { 13 | _, file, line, _ := runtime.Caller(skip + 1) 14 | stackTrace := PruneStack(string(debug.Stack()), skip) 15 | return types.CodeLocation{FileName: file, LineNumber: line, FullStackTrace: stackTrace} 16 | } 17 | 18 | func PruneStack(fullStackTrace string, skip int) string { 19 | stack := strings.Split(fullStackTrace, "\n") 20 | if len(stack) > 2*(skip+1) { 21 | stack = stack[2*(skip+1):] 22 | } 23 | prunedStack := []string{} 24 | re := regexp.MustCompile(`\/ginkgo\/|\/pkg\/testing\/|\/pkg\/runtime\/`) 25 | for i := 0; i < len(stack)/2; i++ { 26 | if !re.Match([]byte(stack[i*2])) { 27 | prunedStack = append(prunedStack, stack[i*2]) 28 | prunedStack = append(prunedStack, stack[i*2+1]) 29 | } 30 | } 31 | return strings.Join(prunedStack, "\n") 32 | } 33 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/codelocation/code_location_suite_test.go: -------------------------------------------------------------------------------- 1 | package codelocation_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | 7 | "testing" 8 | ) 9 | 10 | func TestCodelocation(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "CodeLocation Suite") 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/containernode/container_node_suite_test.go: -------------------------------------------------------------------------------- 1 | package containernode_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | 7 | "testing" 8 | ) 9 | 10 | func TestContainernode(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "Containernode Suite") 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/failer/failer.go: -------------------------------------------------------------------------------- 1 | package failer 2 | 3 | import ( 4 | "github.com/onsi/ginkgo/types" 5 | "sync" 6 | ) 7 | 8 | type Failer struct { 9 | lock *sync.Mutex 10 | failure types.SpecFailure 11 | state types.SpecState 12 | } 13 | 14 | func New() *Failer { 15 | return &Failer{ 16 | lock: &sync.Mutex{}, 17 | state: types.SpecStatePassed, 18 | } 19 | } 20 | 21 | func (f *Failer) Panic(location types.CodeLocation, forwardedPanic interface{}) { 22 | f.lock.Lock() 23 | defer f.lock.Unlock() 24 | 25 | if f.state == types.SpecStatePassed { 26 | f.state = types.SpecStatePanicked 27 | f.failure = types.SpecFailure{ 28 | Message: "Test Panicked", 29 | Location: location, 30 | ForwardedPanic: forwardedPanic, 31 | } 32 | } 33 | } 34 | 35 | func (f *Failer) Timeout(location types.CodeLocation) { 36 | f.lock.Lock() 37 | defer f.lock.Unlock() 38 | 39 | if f.state == types.SpecStatePassed { 40 | f.state = types.SpecStateTimedOut 41 | f.failure = types.SpecFailure{ 42 | Message: "Timed out", 43 | Location: location, 44 | } 45 | } 46 | } 47 | 48 | func (f *Failer) Fail(message string, location types.CodeLocation) { 49 | f.lock.Lock() 50 | defer f.lock.Unlock() 51 | 52 | if f.state == types.SpecStatePassed { 53 | f.state = types.SpecStateFailed 54 | f.failure = types.SpecFailure{ 55 | Message: message, 56 | Location: location, 57 | } 58 | } 59 | } 60 | 61 | func (f *Failer) Drain(componentType types.SpecComponentType, componentIndex int, componentCodeLocation types.CodeLocation) (types.SpecFailure, types.SpecState) { 62 | f.lock.Lock() 63 | defer f.lock.Unlock() 64 | 65 | failure := f.failure 66 | outcome := f.state 67 | if outcome != types.SpecStatePassed { 68 | failure.ComponentType = componentType 69 | failure.ComponentIndex = componentIndex 70 | failure.ComponentCodeLocation = componentCodeLocation 71 | } 72 | 73 | f.state = types.SpecStatePassed 74 | f.failure = types.SpecFailure{} 75 | 76 | return failure, outcome 77 | } 78 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/failer/failer_suite_test.go: -------------------------------------------------------------------------------- 1 | package failer_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | 7 | "testing" 8 | ) 9 | 10 | func TestFailer(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "Failer Suite") 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/leafnodes/benchmarker.go: -------------------------------------------------------------------------------- 1 | package leafnodes 2 | 3 | import ( 4 | "github.com/onsi/ginkgo/types" 5 | "math" 6 | "time" 7 | ) 8 | 9 | type benchmarker struct { 10 | measurements map[string]*types.SpecMeasurement 11 | } 12 | 13 | func newBenchmarker() *benchmarker { 14 | return &benchmarker{ 15 | measurements: make(map[string]*types.SpecMeasurement, 0), 16 | } 17 | } 18 | 19 | func (b *benchmarker) Time(name string, body func(), info ...interface{}) (elapsedTime time.Duration) { 20 | t := time.Now() 21 | body() 22 | elapsedTime = time.Since(t) 23 | 24 | measurement := b.getMeasurement(name, "Fastest Time", "Slowest Time", "Average Time", "s", info...) 25 | measurement.Results = append(measurement.Results, elapsedTime.Seconds()) 26 | 27 | return 28 | } 29 | 30 | func (b *benchmarker) RecordValue(name string, value float64, info ...interface{}) { 31 | measurement := b.getMeasurement(name, "Smallest", " Largest", " Average", "", info...) 32 | measurement.Results = append(measurement.Results, value) 33 | } 34 | 35 | func (b *benchmarker) getMeasurement(name string, smallestLabel string, largestLabel string, averageLabel string, units string, info ...interface{}) *types.SpecMeasurement { 36 | measurement, ok := b.measurements[name] 37 | if !ok { 38 | var computedInfo interface{} 39 | computedInfo = nil 40 | if len(info) > 0 { 41 | computedInfo = info[0] 42 | } 43 | measurement = &types.SpecMeasurement{ 44 | Name: name, 45 | Info: computedInfo, 46 | SmallestLabel: smallestLabel, 47 | LargestLabel: largestLabel, 48 | AverageLabel: averageLabel, 49 | Units: units, 50 | Results: make([]float64, 0), 51 | } 52 | b.measurements[name] = measurement 53 | } 54 | 55 | return measurement 56 | } 57 | 58 | func (b *benchmarker) measurementsReport() map[string]*types.SpecMeasurement { 59 | for _, measurement := range b.measurements { 60 | measurement.Smallest = math.MaxFloat64 61 | measurement.Largest = -math.MaxFloat64 62 | sum := float64(0) 63 | sumOfSquares := float64(0) 64 | 65 | for _, result := range measurement.Results { 66 | if result > measurement.Largest { 67 | measurement.Largest = result 68 | } 69 | if result < measurement.Smallest { 70 | measurement.Smallest = result 71 | } 72 | sum += result 73 | sumOfSquares += result * result 74 | } 75 | 76 | n := float64(len(measurement.Results)) 77 | measurement.Average = sum / n 78 | measurement.StdDeviation = math.Sqrt(sumOfSquares/n - (sum/n)*(sum/n)) 79 | } 80 | 81 | return b.measurements 82 | } 83 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/leafnodes/interfaces.go: -------------------------------------------------------------------------------- 1 | package leafnodes 2 | 3 | import ( 4 | "github.com/onsi/ginkgo/types" 5 | ) 6 | 7 | type BasicNode interface { 8 | Type() types.SpecComponentType 9 | Run() (types.SpecState, types.SpecFailure) 10 | CodeLocation() types.CodeLocation 11 | } 12 | 13 | type SubjectNode interface { 14 | BasicNode 15 | 16 | Text() string 17 | Flag() types.FlagType 18 | Samples() int 19 | } 20 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/leafnodes/it_node.go: -------------------------------------------------------------------------------- 1 | package leafnodes 2 | 3 | import ( 4 | "github.com/onsi/ginkgo/internal/failer" 5 | "github.com/onsi/ginkgo/types" 6 | "time" 7 | ) 8 | 9 | type ItNode struct { 10 | runner *runner 11 | 12 | flag types.FlagType 13 | text string 14 | } 15 | 16 | func NewItNode(text string, body interface{}, flag types.FlagType, codeLocation types.CodeLocation, timeout time.Duration, failer *failer.Failer, componentIndex int) *ItNode { 17 | return &ItNode{ 18 | runner: newRunner(body, codeLocation, timeout, failer, types.SpecComponentTypeIt, componentIndex), 19 | flag: flag, 20 | text: text, 21 | } 22 | } 23 | 24 | func (node *ItNode) Run() (outcome types.SpecState, failure types.SpecFailure) { 25 | return node.runner.run() 26 | } 27 | 28 | func (node *ItNode) Type() types.SpecComponentType { 29 | return types.SpecComponentTypeIt 30 | } 31 | 32 | func (node *ItNode) Text() string { 33 | return node.text 34 | } 35 | 36 | func (node *ItNode) Flag() types.FlagType { 37 | return node.flag 38 | } 39 | 40 | func (node *ItNode) CodeLocation() types.CodeLocation { 41 | return node.runner.codeLocation 42 | } 43 | 44 | func (node *ItNode) Samples() int { 45 | return 1 46 | } 47 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/leafnodes/it_node_test.go: -------------------------------------------------------------------------------- 1 | package leafnodes_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/ginkgo/internal/leafnodes" 6 | . "github.com/onsi/gomega" 7 | 8 | "github.com/onsi/ginkgo/internal/codelocation" 9 | "github.com/onsi/ginkgo/types" 10 | ) 11 | 12 | var _ = Describe("It Nodes", func() { 13 | It("should report the correct type, text, flag, and code location", func() { 14 | codeLocation := codelocation.New(0) 15 | it := NewItNode("my it node", func() {}, types.FlagTypeFocused, codeLocation, 0, nil, 3) 16 | Ω(it.Type()).Should(Equal(types.SpecComponentTypeIt)) 17 | Ω(it.Flag()).Should(Equal(types.FlagTypeFocused)) 18 | Ω(it.Text()).Should(Equal("my it node")) 19 | Ω(it.CodeLocation()).Should(Equal(codeLocation)) 20 | Ω(it.Samples()).Should(Equal(1)) 21 | }) 22 | }) 23 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/leafnodes/leaf_node_suite_test.go: -------------------------------------------------------------------------------- 1 | package leafnodes_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | 7 | "testing" 8 | ) 9 | 10 | func TestLeafNode(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "LeafNode Suite") 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/leafnodes/measure_node.go: -------------------------------------------------------------------------------- 1 | package leafnodes 2 | 3 | import ( 4 | "github.com/onsi/ginkgo/internal/failer" 5 | "github.com/onsi/ginkgo/types" 6 | "reflect" 7 | ) 8 | 9 | type MeasureNode struct { 10 | runner *runner 11 | 12 | text string 13 | flag types.FlagType 14 | samples int 15 | benchmarker *benchmarker 16 | } 17 | 18 | func NewMeasureNode(text string, body interface{}, flag types.FlagType, codeLocation types.CodeLocation, samples int, failer *failer.Failer, componentIndex int) *MeasureNode { 19 | benchmarker := newBenchmarker() 20 | 21 | wrappedBody := func() { 22 | reflect.ValueOf(body).Call([]reflect.Value{reflect.ValueOf(benchmarker)}) 23 | } 24 | 25 | return &MeasureNode{ 26 | runner: newRunner(wrappedBody, codeLocation, 0, failer, types.SpecComponentTypeMeasure, componentIndex), 27 | 28 | text: text, 29 | flag: flag, 30 | samples: samples, 31 | benchmarker: benchmarker, 32 | } 33 | } 34 | 35 | func (node *MeasureNode) Run() (outcome types.SpecState, failure types.SpecFailure) { 36 | return node.runner.run() 37 | } 38 | 39 | func (node *MeasureNode) MeasurementsReport() map[string]*types.SpecMeasurement { 40 | return node.benchmarker.measurementsReport() 41 | } 42 | 43 | func (node *MeasureNode) Type() types.SpecComponentType { 44 | return types.SpecComponentTypeMeasure 45 | } 46 | 47 | func (node *MeasureNode) Text() string { 48 | return node.text 49 | } 50 | 51 | func (node *MeasureNode) Flag() types.FlagType { 52 | return node.flag 53 | } 54 | 55 | func (node *MeasureNode) CodeLocation() types.CodeLocation { 56 | return node.runner.codeLocation 57 | } 58 | 59 | func (node *MeasureNode) Samples() int { 60 | return node.samples 61 | } 62 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/leafnodes/setup_nodes.go: -------------------------------------------------------------------------------- 1 | package leafnodes 2 | 3 | import ( 4 | "github.com/onsi/ginkgo/internal/failer" 5 | "github.com/onsi/ginkgo/types" 6 | "time" 7 | ) 8 | 9 | type SetupNode struct { 10 | runner *runner 11 | } 12 | 13 | func (node *SetupNode) Run() (outcome types.SpecState, failure types.SpecFailure) { 14 | return node.runner.run() 15 | } 16 | 17 | func (node *SetupNode) Type() types.SpecComponentType { 18 | return node.runner.nodeType 19 | } 20 | 21 | func (node *SetupNode) CodeLocation() types.CodeLocation { 22 | return node.runner.codeLocation 23 | } 24 | 25 | func NewBeforeEachNode(body interface{}, codeLocation types.CodeLocation, timeout time.Duration, failer *failer.Failer, componentIndex int) *SetupNode { 26 | return &SetupNode{ 27 | runner: newRunner(body, codeLocation, timeout, failer, types.SpecComponentTypeBeforeEach, componentIndex), 28 | } 29 | } 30 | 31 | func NewAfterEachNode(body interface{}, codeLocation types.CodeLocation, timeout time.Duration, failer *failer.Failer, componentIndex int) *SetupNode { 32 | return &SetupNode{ 33 | runner: newRunner(body, codeLocation, timeout, failer, types.SpecComponentTypeAfterEach, componentIndex), 34 | } 35 | } 36 | 37 | func NewJustBeforeEachNode(body interface{}, codeLocation types.CodeLocation, timeout time.Duration, failer *failer.Failer, componentIndex int) *SetupNode { 38 | return &SetupNode{ 39 | runner: newRunner(body, codeLocation, timeout, failer, types.SpecComponentTypeJustBeforeEach, componentIndex), 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/leafnodes/setup_nodes_test.go: -------------------------------------------------------------------------------- 1 | package leafnodes_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | "github.com/onsi/ginkgo/types" 6 | . "github.com/onsi/gomega" 7 | 8 | . "github.com/onsi/ginkgo/internal/leafnodes" 9 | 10 | "github.com/onsi/ginkgo/internal/codelocation" 11 | ) 12 | 13 | var _ = Describe("Setup Nodes", func() { 14 | Describe("BeforeEachNodes", func() { 15 | It("should report the correct type and code location", func() { 16 | codeLocation := codelocation.New(0) 17 | beforeEach := NewBeforeEachNode(func() {}, codeLocation, 0, nil, 3) 18 | Ω(beforeEach.Type()).Should(Equal(types.SpecComponentTypeBeforeEach)) 19 | Ω(beforeEach.CodeLocation()).Should(Equal(codeLocation)) 20 | }) 21 | }) 22 | 23 | Describe("AfterEachNodes", func() { 24 | It("should report the correct type and code location", func() { 25 | codeLocation := codelocation.New(0) 26 | afterEach := NewAfterEachNode(func() {}, codeLocation, 0, nil, 3) 27 | Ω(afterEach.Type()).Should(Equal(types.SpecComponentTypeAfterEach)) 28 | Ω(afterEach.CodeLocation()).Should(Equal(codeLocation)) 29 | }) 30 | }) 31 | 32 | Describe("JustBeforeEachNodes", func() { 33 | It("should report the correct type and code location", func() { 34 | codeLocation := codelocation.New(0) 35 | justBeforeEach := NewJustBeforeEachNode(func() {}, codeLocation, 0, nil, 3) 36 | Ω(justBeforeEach.Type()).Should(Equal(types.SpecComponentTypeJustBeforeEach)) 37 | Ω(justBeforeEach.CodeLocation()).Should(Equal(codeLocation)) 38 | }) 39 | }) 40 | }) 41 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/leafnodes/suite_nodes.go: -------------------------------------------------------------------------------- 1 | package leafnodes 2 | 3 | import ( 4 | "github.com/onsi/ginkgo/internal/failer" 5 | "github.com/onsi/ginkgo/types" 6 | "time" 7 | ) 8 | 9 | type SuiteNode interface { 10 | Run(parallelNode int, parallelTotal int, syncHost string) bool 11 | Passed() bool 12 | Summary() *types.SetupSummary 13 | } 14 | 15 | type simpleSuiteNode struct { 16 | runner *runner 17 | outcome types.SpecState 18 | failure types.SpecFailure 19 | runTime time.Duration 20 | } 21 | 22 | func (node *simpleSuiteNode) Run(parallelNode int, parallelTotal int, syncHost string) bool { 23 | t := time.Now() 24 | node.outcome, node.failure = node.runner.run() 25 | node.runTime = time.Since(t) 26 | 27 | return node.outcome == types.SpecStatePassed 28 | } 29 | 30 | func (node *simpleSuiteNode) Passed() bool { 31 | return node.outcome == types.SpecStatePassed 32 | } 33 | 34 | func (node *simpleSuiteNode) Summary() *types.SetupSummary { 35 | return &types.SetupSummary{ 36 | ComponentType: node.runner.nodeType, 37 | CodeLocation: node.runner.codeLocation, 38 | State: node.outcome, 39 | RunTime: node.runTime, 40 | Failure: node.failure, 41 | } 42 | } 43 | 44 | func NewBeforeSuiteNode(body interface{}, codeLocation types.CodeLocation, timeout time.Duration, failer *failer.Failer) SuiteNode { 45 | return &simpleSuiteNode{ 46 | runner: newRunner(body, codeLocation, timeout, failer, types.SpecComponentTypeBeforeSuite, 0), 47 | } 48 | } 49 | 50 | func NewAfterSuiteNode(body interface{}, codeLocation types.CodeLocation, timeout time.Duration, failer *failer.Failer) SuiteNode { 51 | return &simpleSuiteNode{ 52 | runner: newRunner(body, codeLocation, timeout, failer, types.SpecComponentTypeAfterSuite, 0), 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/remote/fake_output_interceptor_test.go: -------------------------------------------------------------------------------- 1 | package remote_test 2 | 3 | type fakeOutputInterceptor struct { 4 | DidStartInterceptingOutput bool 5 | DidStopInterceptingOutput bool 6 | InterceptedOutput string 7 | } 8 | 9 | func (interceptor *fakeOutputInterceptor) StartInterceptingOutput() error { 10 | interceptor.DidStartInterceptingOutput = true 11 | return nil 12 | } 13 | 14 | func (interceptor *fakeOutputInterceptor) StopInterceptingAndReturnOutput() (string, error) { 15 | interceptor.DidStopInterceptingOutput = true 16 | return interceptor.InterceptedOutput, nil 17 | } 18 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/remote/fake_poster_test.go: -------------------------------------------------------------------------------- 1 | package remote_test 2 | 3 | import ( 4 | "io" 5 | "io/ioutil" 6 | "net/http" 7 | ) 8 | 9 | type post struct { 10 | url string 11 | bodyType string 12 | bodyContent []byte 13 | } 14 | 15 | type fakePoster struct { 16 | posts []post 17 | } 18 | 19 | func newFakePoster() *fakePoster { 20 | return &fakePoster{ 21 | posts: make([]post, 0), 22 | } 23 | } 24 | 25 | func (poster *fakePoster) Post(url string, bodyType string, body io.Reader) (resp *http.Response, err error) { 26 | bodyContent, _ := ioutil.ReadAll(body) 27 | poster.posts = append(poster.posts, post{ 28 | url: url, 29 | bodyType: bodyType, 30 | bodyContent: bodyContent, 31 | }) 32 | return nil, nil 33 | } 34 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/remote/output_interceptor.go: -------------------------------------------------------------------------------- 1 | package remote 2 | 3 | /* 4 | The OutputInterceptor is used by the ForwardingReporter to 5 | intercept and capture all stdin and stderr output during a test run. 6 | */ 7 | type OutputInterceptor interface { 8 | StartInterceptingOutput() error 9 | StopInterceptingAndReturnOutput() (string, error) 10 | } 11 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/remote/output_interceptor_test.go: -------------------------------------------------------------------------------- 1 | package remote_test 2 | 3 | import ( 4 | "fmt" 5 | . "github.com/onsi/ginkgo" 6 | . "github.com/onsi/ginkgo/internal/remote" 7 | . "github.com/onsi/gomega" 8 | "os" 9 | ) 10 | 11 | var _ = Describe("OutputInterceptor", func() { 12 | var interceptor OutputInterceptor 13 | 14 | BeforeEach(func() { 15 | interceptor = NewOutputInterceptor() 16 | }) 17 | 18 | It("should capture all stdout/stderr output", func() { 19 | err := interceptor.StartInterceptingOutput() 20 | Ω(err).ShouldNot(HaveOccurred()) 21 | 22 | fmt.Fprint(os.Stdout, "STDOUT") 23 | fmt.Fprint(os.Stderr, "STDERR") 24 | print("PRINT") 25 | 26 | output, err := interceptor.StopInterceptingAndReturnOutput() 27 | 28 | Ω(output).Should(Equal("STDOUTSTDERRPRINT")) 29 | Ω(err).ShouldNot(HaveOccurred()) 30 | }) 31 | 32 | It("should error if told to intercept output twice", func() { 33 | err := interceptor.StartInterceptingOutput() 34 | Ω(err).ShouldNot(HaveOccurred()) 35 | 36 | print("A") 37 | 38 | err = interceptor.StartInterceptingOutput() 39 | Ω(err).Should(HaveOccurred()) 40 | 41 | print("B") 42 | 43 | output, err := interceptor.StopInterceptingAndReturnOutput() 44 | 45 | Ω(output).Should(Equal("AB")) 46 | Ω(err).ShouldNot(HaveOccurred()) 47 | }) 48 | 49 | It("should allow multiple interception sessions", func() { 50 | err := interceptor.StartInterceptingOutput() 51 | Ω(err).ShouldNot(HaveOccurred()) 52 | print("A") 53 | output, err := interceptor.StopInterceptingAndReturnOutput() 54 | Ω(output).Should(Equal("A")) 55 | Ω(err).ShouldNot(HaveOccurred()) 56 | 57 | err = interceptor.StartInterceptingOutput() 58 | Ω(err).ShouldNot(HaveOccurred()) 59 | print("B") 60 | output, err = interceptor.StopInterceptingAndReturnOutput() 61 | Ω(output).Should(Equal("B")) 62 | Ω(err).ShouldNot(HaveOccurred()) 63 | }) 64 | }) 65 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/remote/output_interceptor_unix.go: -------------------------------------------------------------------------------- 1 | // +build freebsd openbsd netbsd darwin linux 2 | 3 | package remote 4 | 5 | import ( 6 | "errors" 7 | "io/ioutil" 8 | "os" 9 | "syscall" 10 | ) 11 | 12 | func NewOutputInterceptor() OutputInterceptor { 13 | return &outputInterceptor{} 14 | } 15 | 16 | type outputInterceptor struct { 17 | stdoutPlaceholder *os.File 18 | stderrPlaceholder *os.File 19 | redirectFile *os.File 20 | intercepting bool 21 | } 22 | 23 | func (interceptor *outputInterceptor) StartInterceptingOutput() error { 24 | if interceptor.intercepting { 25 | return errors.New("Already intercepting output!") 26 | } 27 | interceptor.intercepting = true 28 | 29 | var err error 30 | 31 | interceptor.redirectFile, err = ioutil.TempFile("", "ginkgo") 32 | if err != nil { 33 | return err 34 | } 35 | 36 | interceptor.stdoutPlaceholder, err = ioutil.TempFile("", "ginkgo") 37 | if err != nil { 38 | return err 39 | } 40 | 41 | interceptor.stderrPlaceholder, err = ioutil.TempFile("", "ginkgo") 42 | if err != nil { 43 | return err 44 | } 45 | 46 | syscall.Dup2(1, int(interceptor.stdoutPlaceholder.Fd())) 47 | syscall.Dup2(2, int(interceptor.stderrPlaceholder.Fd())) 48 | 49 | syscall.Dup2(int(interceptor.redirectFile.Fd()), 1) 50 | syscall.Dup2(int(interceptor.redirectFile.Fd()), 2) 51 | 52 | return nil 53 | } 54 | 55 | func (interceptor *outputInterceptor) StopInterceptingAndReturnOutput() (string, error) { 56 | if !interceptor.intercepting { 57 | return "", errors.New("Not intercepting output!") 58 | } 59 | 60 | syscall.Dup2(int(interceptor.stdoutPlaceholder.Fd()), 1) 61 | syscall.Dup2(int(interceptor.stderrPlaceholder.Fd()), 2) 62 | 63 | for _, f := range []*os.File{interceptor.redirectFile, interceptor.stdoutPlaceholder, interceptor.stderrPlaceholder} { 64 | f.Close() 65 | } 66 | 67 | output, err := ioutil.ReadFile(interceptor.redirectFile.Name()) 68 | 69 | for _, f := range []*os.File{interceptor.redirectFile, interceptor.stdoutPlaceholder, interceptor.stderrPlaceholder} { 70 | os.Remove(f.Name()) 71 | } 72 | 73 | interceptor.intercepting = false 74 | 75 | return string(output), err 76 | } 77 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/remote/output_interceptor_win.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package remote 4 | 5 | import ( 6 | "errors" 7 | ) 8 | 9 | func NewOutputInterceptor() OutputInterceptor { 10 | return &outputInterceptor{} 11 | } 12 | 13 | type outputInterceptor struct { 14 | intercepting bool 15 | } 16 | 17 | func (interceptor *outputInterceptor) StartInterceptingOutput() error { 18 | if interceptor.intercepting { 19 | return errors.New("Already intercepting output!") 20 | } 21 | interceptor.intercepting = true 22 | 23 | // not working on windows... 24 | 25 | return nil 26 | } 27 | 28 | func (interceptor *outputInterceptor) StopInterceptingAndReturnOutput() (string, error) { 29 | // not working on windows... 30 | interceptor.intercepting = false 31 | 32 | return "", nil 33 | } 34 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/remote/remote_suite_test.go: -------------------------------------------------------------------------------- 1 | package remote_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | 7 | "testing" 8 | ) 9 | 10 | func TestRemote(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "Remote Spec Forwarding Suite") 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/spec/index_computer.go: -------------------------------------------------------------------------------- 1 | package spec 2 | 3 | func ParallelizedIndexRange(length int, parallelTotal int, parallelNode int) (startIndex int, count int) { 4 | if length == 0 { 5 | return 0, 0 6 | } 7 | 8 | // We have more nodes than tests. Trivial case. 9 | if parallelTotal >= length { 10 | if parallelNode > length { 11 | return 0, 0 12 | } else { 13 | return parallelNode - 1, 1 14 | } 15 | } 16 | 17 | // This is the minimum amount of tests that a node will be required to run 18 | minTestsPerNode := length / parallelTotal 19 | 20 | // This is the maximum amount of tests that a node will be required to run 21 | // The algorithm guarantees that this would be equal to at least the minimum amount 22 | // and at most one more 23 | maxTestsPerNode := minTestsPerNode 24 | if length%parallelTotal != 0 { 25 | maxTestsPerNode++ 26 | } 27 | 28 | // Number of nodes that will have to run the maximum amount of tests per node 29 | numMaxLoadNodes := length % parallelTotal 30 | 31 | // Number of nodes that precede the current node and will have to run the maximum amount of tests per node 32 | var numPrecedingMaxLoadNodes int 33 | if parallelNode > numMaxLoadNodes { 34 | numPrecedingMaxLoadNodes = numMaxLoadNodes 35 | } else { 36 | numPrecedingMaxLoadNodes = parallelNode - 1 37 | } 38 | 39 | // Number of nodes that precede the current node and will have to run the minimum amount of tests per node 40 | var numPrecedingMinLoadNodes int 41 | if parallelNode <= numMaxLoadNodes { 42 | numPrecedingMinLoadNodes = 0 43 | } else { 44 | numPrecedingMinLoadNodes = parallelNode - numMaxLoadNodes - 1 45 | } 46 | 47 | // Evaluate the test start index and number of tests to run 48 | startIndex = numPrecedingMaxLoadNodes*maxTestsPerNode + numPrecedingMinLoadNodes*minTestsPerNode 49 | if parallelNode > numMaxLoadNodes { 50 | count = minTestsPerNode 51 | } else { 52 | count = maxTestsPerNode 53 | } 54 | return 55 | } 56 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/spec/spec_suite_test.go: -------------------------------------------------------------------------------- 1 | package spec_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | 7 | "testing" 8 | ) 9 | 10 | func TestSpec(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "Spec Suite") 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/specrunner/random_id.go: -------------------------------------------------------------------------------- 1 | package specrunner 2 | 3 | import ( 4 | "crypto/rand" 5 | "fmt" 6 | ) 7 | 8 | func randomID() string { 9 | b := make([]byte, 8) 10 | _, err := rand.Read(b) 11 | if err != nil { 12 | return "" 13 | } 14 | return fmt.Sprintf("%x-%x-%x-%x", b[0:2], b[2:4], b[4:6], b[6:8]) 15 | } 16 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/specrunner/spec_runner_suite_test.go: -------------------------------------------------------------------------------- 1 | package specrunner_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | 7 | "testing" 8 | ) 9 | 10 | func TestSpecRunner(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "Spec Runner Suite") 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/suite/suite_suite_test.go: -------------------------------------------------------------------------------- 1 | package suite_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | 7 | "testing" 8 | ) 9 | 10 | func Test(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "Suite") 13 | } 14 | 15 | var numBeforeSuiteRuns = 0 16 | var numAfterSuiteRuns = 0 17 | 18 | var _ = BeforeSuite(func() { 19 | numBeforeSuiteRuns++ 20 | }) 21 | 22 | var _ = AfterSuite(func() { 23 | numAfterSuiteRuns++ 24 | Ω(numBeforeSuiteRuns).Should(Equal(1)) 25 | Ω(numAfterSuiteRuns).Should(Equal(1)) 26 | }) 27 | 28 | //Fakes 29 | type fakeTestingT struct { 30 | didFail bool 31 | } 32 | 33 | func (fakeT *fakeTestingT) Fail() { 34 | fakeT.didFail = true 35 | } 36 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/testingtproxy/testing_t_proxy.go: -------------------------------------------------------------------------------- 1 | package testingtproxy 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | ) 7 | 8 | type failFunc func(message string, callerSkip ...int) 9 | 10 | func New(writer io.Writer, fail failFunc, offset int) *ginkgoTestingTProxy { 11 | return &ginkgoTestingTProxy{ 12 | fail: fail, 13 | offset: offset, 14 | writer: writer, 15 | } 16 | } 17 | 18 | type ginkgoTestingTProxy struct { 19 | fail failFunc 20 | offset int 21 | writer io.Writer 22 | } 23 | 24 | func (t *ginkgoTestingTProxy) Error(args ...interface{}) { 25 | t.fail(fmt.Sprintln(args...), t.offset) 26 | } 27 | 28 | func (t *ginkgoTestingTProxy) Errorf(format string, args ...interface{}) { 29 | t.fail(fmt.Sprintf(format, args...), t.offset) 30 | } 31 | 32 | func (t *ginkgoTestingTProxy) Fail() { 33 | t.fail("failed", t.offset) 34 | } 35 | 36 | func (t *ginkgoTestingTProxy) FailNow() { 37 | t.fail("failed", t.offset) 38 | } 39 | 40 | func (t *ginkgoTestingTProxy) Fatal(args ...interface{}) { 41 | t.fail(fmt.Sprintln(args...), t.offset) 42 | } 43 | 44 | func (t *ginkgoTestingTProxy) Fatalf(format string, args ...interface{}) { 45 | t.fail(fmt.Sprintf(format, args...), t.offset) 46 | } 47 | 48 | func (t *ginkgoTestingTProxy) Log(args ...interface{}) { 49 | fmt.Fprintln(t.writer, args...) 50 | } 51 | 52 | func (t *ginkgoTestingTProxy) Logf(format string, args ...interface{}) { 53 | fmt.Fprintf(t.writer, format, args...) 54 | } 55 | 56 | func (t *ginkgoTestingTProxy) Failed() bool { 57 | return false 58 | } 59 | 60 | func (t *ginkgoTestingTProxy) Parallel() { 61 | } 62 | 63 | func (t *ginkgoTestingTProxy) Skip(args ...interface{}) { 64 | fmt.Println(args...) 65 | } 66 | 67 | func (t *ginkgoTestingTProxy) Skipf(format string, args ...interface{}) { 68 | fmt.Printf(format, args...) 69 | } 70 | 71 | func (t *ginkgoTestingTProxy) SkipNow() { 72 | } 73 | 74 | func (t *ginkgoTestingTProxy) Skipped() bool { 75 | return false 76 | } 77 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/writer/fake_writer.go: -------------------------------------------------------------------------------- 1 | package writer 2 | 3 | type FakeGinkgoWriter struct { 4 | EventStream []string 5 | } 6 | 7 | func NewFake() *FakeGinkgoWriter { 8 | return &FakeGinkgoWriter{ 9 | EventStream: []string{}, 10 | } 11 | } 12 | 13 | func (writer *FakeGinkgoWriter) AddEvent(event string) { 14 | writer.EventStream = append(writer.EventStream, event) 15 | } 16 | 17 | func (writer *FakeGinkgoWriter) Truncate() { 18 | writer.EventStream = append(writer.EventStream, "TRUNCATE") 19 | } 20 | 21 | func (writer *FakeGinkgoWriter) DumpOut() { 22 | writer.EventStream = append(writer.EventStream, "DUMP") 23 | } 24 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/writer/writer.go: -------------------------------------------------------------------------------- 1 | package writer 2 | 3 | import ( 4 | "bytes" 5 | "io" 6 | "sync" 7 | ) 8 | 9 | type WriterInterface interface { 10 | Truncate() 11 | DumpOut() 12 | } 13 | 14 | type Writer struct { 15 | buffer *bytes.Buffer 16 | outWriter io.Writer 17 | lock *sync.Mutex 18 | stream bool 19 | } 20 | 21 | func New(outWriter io.Writer) *Writer { 22 | return &Writer{ 23 | buffer: &bytes.Buffer{}, 24 | lock: &sync.Mutex{}, 25 | outWriter: outWriter, 26 | stream: true, 27 | } 28 | } 29 | 30 | func (w *Writer) SetStream(stream bool) { 31 | w.lock.Lock() 32 | defer w.lock.Unlock() 33 | w.stream = stream 34 | } 35 | 36 | func (w *Writer) Write(b []byte) (n int, err error) { 37 | w.lock.Lock() 38 | defer w.lock.Unlock() 39 | 40 | if w.stream { 41 | return w.outWriter.Write(b) 42 | } else { 43 | return w.buffer.Write(b) 44 | } 45 | } 46 | 47 | func (w *Writer) Truncate() { 48 | w.lock.Lock() 49 | defer w.lock.Unlock() 50 | w.buffer.Reset() 51 | } 52 | 53 | func (w *Writer) DumpOut() { 54 | w.lock.Lock() 55 | defer w.lock.Unlock() 56 | if !w.stream { 57 | w.buffer.WriteTo(w.outWriter) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/writer/writer_suite_test.go: -------------------------------------------------------------------------------- 1 | package writer_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | 7 | "testing" 8 | ) 9 | 10 | func TestWriter(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "Writer Suite") 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/internal/writer/writer_test.go: -------------------------------------------------------------------------------- 1 | package writer_test 2 | 3 | import ( 4 | "bytes" 5 | 6 | . "github.com/onsi/ginkgo" 7 | . "github.com/onsi/ginkgo/internal/writer" 8 | . "github.com/onsi/gomega" 9 | ) 10 | 11 | var _ = Describe("Writer", func() { 12 | var writer *Writer 13 | var out *bytes.Buffer 14 | 15 | BeforeEach(func() { 16 | out = &bytes.Buffer{} 17 | writer = New(out) 18 | }) 19 | 20 | It("should stream directly to the outbuffer by default", func() { 21 | writer.Write([]byte("foo")) 22 | Ω(out.String()).Should(Equal("foo")) 23 | }) 24 | 25 | Context("when told not to stream", func() { 26 | BeforeEach(func() { 27 | writer.SetStream(false) 28 | }) 29 | 30 | It("should only write to the buffer when told to DumpOut", func() { 31 | writer.Write([]byte("foo")) 32 | Ω(out.String()).Should(BeEmpty()) 33 | writer.DumpOut() 34 | Ω(out.String()).Should(Equal("foo")) 35 | }) 36 | 37 | It("should truncate the internal buffer when told to truncate", func() { 38 | writer.Write([]byte("foo")) 39 | writer.Truncate() 40 | writer.DumpOut() 41 | Ω(out.String()).Should(BeEmpty()) 42 | 43 | writer.Write([]byte("foo")) 44 | writer.DumpOut() 45 | Ω(out.String()).Should(Equal("foo")) 46 | }) 47 | }) 48 | }) 49 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/reporters/fake_reporter.go: -------------------------------------------------------------------------------- 1 | package reporters 2 | 3 | import ( 4 | "github.com/onsi/ginkgo/config" 5 | "github.com/onsi/ginkgo/types" 6 | ) 7 | 8 | //FakeReporter is useful for testing purposes 9 | type FakeReporter struct { 10 | Config config.GinkgoConfigType 11 | 12 | BeginSummary *types.SuiteSummary 13 | BeforeSuiteSummary *types.SetupSummary 14 | SpecWillRunSummaries []*types.SpecSummary 15 | SpecSummaries []*types.SpecSummary 16 | AfterSuiteSummary *types.SetupSummary 17 | EndSummary *types.SuiteSummary 18 | } 19 | 20 | func NewFakeReporter() *FakeReporter { 21 | return &FakeReporter{ 22 | SpecWillRunSummaries: make([]*types.SpecSummary, 0), 23 | SpecSummaries: make([]*types.SpecSummary, 0), 24 | } 25 | } 26 | 27 | func (fakeR *FakeReporter) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) { 28 | fakeR.Config = config 29 | fakeR.BeginSummary = summary 30 | } 31 | 32 | func (fakeR *FakeReporter) BeforeSuiteDidRun(setupSummary *types.SetupSummary) { 33 | fakeR.BeforeSuiteSummary = setupSummary 34 | } 35 | 36 | func (fakeR *FakeReporter) SpecWillRun(specSummary *types.SpecSummary) { 37 | fakeR.SpecWillRunSummaries = append(fakeR.SpecWillRunSummaries, specSummary) 38 | } 39 | 40 | func (fakeR *FakeReporter) SpecDidComplete(specSummary *types.SpecSummary) { 41 | fakeR.SpecSummaries = append(fakeR.SpecSummaries, specSummary) 42 | } 43 | 44 | func (fakeR *FakeReporter) AfterSuiteDidRun(setupSummary *types.SetupSummary) { 45 | fakeR.AfterSuiteSummary = setupSummary 46 | } 47 | 48 | func (fakeR *FakeReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) { 49 | fakeR.EndSummary = summary 50 | } 51 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/reporters/reporter.go: -------------------------------------------------------------------------------- 1 | package reporters 2 | 3 | import ( 4 | "github.com/onsi/ginkgo/config" 5 | "github.com/onsi/ginkgo/types" 6 | ) 7 | 8 | type Reporter interface { 9 | SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) 10 | BeforeSuiteDidRun(setupSummary *types.SetupSummary) 11 | SpecWillRun(specSummary *types.SpecSummary) 12 | SpecDidComplete(specSummary *types.SpecSummary) 13 | AfterSuiteDidRun(setupSummary *types.SetupSummary) 14 | SpecSuiteDidEnd(summary *types.SuiteSummary) 15 | } 16 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/reporters/reporters_suite_test.go: -------------------------------------------------------------------------------- 1 | package reporters_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | 7 | "testing" 8 | ) 9 | 10 | func TestReporters(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "Reporters Suite") 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/reporters/stenographer/console_logging.go: -------------------------------------------------------------------------------- 1 | package stenographer 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | ) 7 | 8 | func (s *consoleStenographer) colorize(colorCode string, format string, args ...interface{}) string { 9 | var out string 10 | 11 | if len(args) > 0 { 12 | out = fmt.Sprintf(format, args...) 13 | } else { 14 | out = format 15 | } 16 | 17 | if s.color { 18 | return fmt.Sprintf("%s%s%s", colorCode, out, defaultStyle) 19 | } else { 20 | return out 21 | } 22 | } 23 | 24 | func (s *consoleStenographer) printBanner(text string, bannerCharacter string) { 25 | fmt.Println(text) 26 | fmt.Println(strings.Repeat(bannerCharacter, len(text))) 27 | } 28 | 29 | func (s *consoleStenographer) printNewLine() { 30 | fmt.Println("") 31 | } 32 | 33 | func (s *consoleStenographer) printDelimiter() { 34 | fmt.Println(s.colorize(grayColor, "%s", strings.Repeat("-", 30))) 35 | } 36 | 37 | func (s *consoleStenographer) print(indentation int, format string, args ...interface{}) { 38 | fmt.Print(s.indent(indentation, format, args...)) 39 | } 40 | 41 | func (s *consoleStenographer) println(indentation int, format string, args ...interface{}) { 42 | fmt.Println(s.indent(indentation, format, args...)) 43 | } 44 | 45 | func (s *consoleStenographer) indent(indentation int, format string, args ...interface{}) string { 46 | var text string 47 | 48 | if len(args) > 0 { 49 | text = fmt.Sprintf(format, args...) 50 | } else { 51 | text = format 52 | } 53 | 54 | stringArray := strings.Split(text, "\n") 55 | padding := "" 56 | if indentation >= 0 { 57 | padding = strings.Repeat(" ", indentation) 58 | } 59 | for i, s := range stringArray { 60 | stringArray[i] = fmt.Sprintf("%s%s", padding, s) 61 | } 62 | 63 | return strings.Join(stringArray, "\n") 64 | } 65 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/types/code_location.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type CodeLocation struct { 8 | FileName string 9 | LineNumber int 10 | FullStackTrace string 11 | } 12 | 13 | func (codeLocation CodeLocation) String() string { 14 | return fmt.Sprintf("%s:%d", codeLocation.FileName, codeLocation.LineNumber) 15 | } 16 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/types/synchronization.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "encoding/json" 5 | ) 6 | 7 | type RemoteBeforeSuiteState int 8 | 9 | const ( 10 | RemoteBeforeSuiteStateInvalid RemoteBeforeSuiteState = iota 11 | 12 | RemoteBeforeSuiteStatePending 13 | RemoteBeforeSuiteStatePassed 14 | RemoteBeforeSuiteStateFailed 15 | RemoteBeforeSuiteStateDisappeared 16 | ) 17 | 18 | type RemoteBeforeSuiteData struct { 19 | Data []byte 20 | State RemoteBeforeSuiteState 21 | } 22 | 23 | func (r RemoteBeforeSuiteData) ToJSON() []byte { 24 | data, _ := json.Marshal(r) 25 | return data 26 | } 27 | 28 | type RemoteAfterSuiteData struct { 29 | CanRun bool 30 | } 31 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/types/types_suite_test.go: -------------------------------------------------------------------------------- 1 | package types_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | 7 | "testing" 8 | ) 9 | 10 | func TestTypes(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "Types Suite") 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/ginkgo/types/types_test.go: -------------------------------------------------------------------------------- 1 | package types_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo/types" 5 | 6 | . "github.com/onsi/ginkgo" 7 | . "github.com/onsi/gomega" 8 | ) 9 | 10 | var specStates = []SpecState{ 11 | SpecStatePassed, 12 | SpecStateTimedOut, 13 | SpecStatePanicked, 14 | SpecStateFailed, 15 | SpecStatePending, 16 | SpecStateSkipped, 17 | } 18 | 19 | func verifySpecSummary(caller func(SpecSummary) bool, trueStates ...SpecState) { 20 | summary := SpecSummary{} 21 | trueStateLookup := map[SpecState]bool{} 22 | for _, state := range trueStates { 23 | trueStateLookup[state] = true 24 | summary.State = state 25 | Ω(caller(summary)).Should(BeTrue()) 26 | } 27 | 28 | for _, state := range specStates { 29 | if trueStateLookup[state] { 30 | continue 31 | } 32 | summary.State = state 33 | Ω(caller(summary)).Should(BeFalse()) 34 | } 35 | } 36 | 37 | var _ = Describe("Types", func() { 38 | Describe("SpecSummary", func() { 39 | It("knows when it is in a failure-like state", func() { 40 | verifySpecSummary(func(summary SpecSummary) bool { 41 | return summary.HasFailureState() 42 | }, SpecStateTimedOut, SpecStatePanicked, SpecStateFailed) 43 | }) 44 | 45 | It("knows when it passed", func() { 46 | verifySpecSummary(func(summary SpecSummary) bool { 47 | return summary.Passed() 48 | }, SpecStatePassed) 49 | }) 50 | 51 | It("knows when it has failed", func() { 52 | verifySpecSummary(func(summary SpecSummary) bool { 53 | return summary.Failed() 54 | }, SpecStateFailed) 55 | }) 56 | 57 | It("knows when it has panicked", func() { 58 | verifySpecSummary(func(summary SpecSummary) bool { 59 | return summary.Panicked() 60 | }, SpecStatePanicked) 61 | }) 62 | 63 | It("knows when it has timed out", func() { 64 | verifySpecSummary(func(summary SpecSummary) bool { 65 | return summary.TimedOut() 66 | }, SpecStateTimedOut) 67 | }) 68 | 69 | It("knows when it is pending", func() { 70 | verifySpecSummary(func(summary SpecSummary) bool { 71 | return summary.Pending() 72 | }, SpecStatePending) 73 | }) 74 | 75 | It("knows when it is skipped", func() { 76 | verifySpecSummary(func(summary SpecSummary) bool { 77 | return summary.Skipped() 78 | }, SpecStateSkipped) 79 | }) 80 | }) 81 | }) 82 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.test 3 | . 4 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.3 4 | 5 | install: 6 | - go get -v ./... 7 | - go get github.com/onsi/ginkgo 8 | - go install github.com/onsi/ginkgo/ginkgo 9 | 10 | script: $HOME/gopath/bin/ginkgo -r --randomizeAllSpecs --failOnPending --randomizeSuites --race 11 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.0.0-beta (7/8/2014) 2 | Breaking Changes: 3 | 4 | - Changed OmegaMatcher interface. Instead of having `Match` return failure messages, two new methods `FailureMessage` and `NegatedFailureMessage` are called instead. 5 | - Moved and renamed OmegaFailHandler to types.GomegaFailHandler and OmegaMatcher to types.GomegaMatcher. Any references to OmegaMatcher in any custom matchers will need to be changed to point to types.GomegaMatcher 6 | 7 | New Test-Support Features: 8 | 9 | - `ghttp`: supports testing http clients 10 | - Provides a flexible fake http server 11 | - Provides a collection of chainable http handlers that perform assertions. 12 | - `gbytes`: supports making ordered assertions against streams of data 13 | - Provides a `gbytes.Buffer` 14 | - Provides a `Say` matcher to perform ordered assertions against output data 15 | - `gexec`: supports testing external processes 16 | - Provides support for building Go binaries 17 | - Wraps and starts `exec.Cmd` commands 18 | - Makes it easy to assert against stdout and stderr 19 | - Makes it easy to send signals and wait for processes to exit 20 | - Provides an `Exit` matcher to assert against exit code. 21 | 22 | DSL Changes: 23 | 24 | - `Eventually` and `Consistently` can accept `time.Duration` interval and polling inputs. 25 | - The default timeouts for `Eventually` and `Consistently` are now configurable. 26 | 27 | New Matchers: 28 | 29 | - `ConsistOf`: order-independent assertion against the elements of an array/slice or keys of a map. 30 | - `BeTemporally`: like `BeNumerically` but for `time.Time` 31 | - `HaveKeyWithValue`: asserts a map has a given key with the given value. 32 | 33 | Updated Matchers: 34 | 35 | - `Receive` matcher can take a matcher as an argument and passes only if the channel under test receives an objet that satisfies the passed-in matcher. 36 | - Matchers that implement `MatchMayChangeInTheFuture(actual interface{}) bool` can inform `Eventually` and/or `Consistently` when a match has no chance of changing status in the future. For example, `Receive` returns `false` when a channel is closed. 37 | 38 | Misc: 39 | 40 | - Start using semantic versioning 41 | - Start maintaining changelog 42 | 43 | Major refactor: 44 | 45 | - Pull out Gomega's internal to `internal` 46 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/MIT.LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Onsi Fakhouri 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/README.md: -------------------------------------------------------------------------------- 1 | ![Gomega: Ginkgo's Preferred Matcher Library](http://onsi.github.io/gomega/images/gomega.png) 2 | 3 | [![Build Status](https://travis-ci.org/onsi/gomega.png)](https://travis-ci.org/onsi/gomega) 4 | 5 | Jump straight to the [docs](http://onsi.github.io/gomega/) to learn about Gomega, including a list of [all available matchers](http://onsi.github.io/gomega/#provided_matchers). 6 | 7 | To discuss Gomega and get updates, join the [google group](https://groups.google.com/d/forum/ginkgo-and-gomega). 8 | 9 | ## [Ginkgo](http://github.com/onsi/ginkgo): a BDD Testing Framework for Golang 10 | 11 | Learn more about Ginkgo [here](http://onsi.github.io/ginkgo/) 12 | 13 | ## License 14 | 15 | Gomega is MIT-Licensed 16 | 17 | The `ConsistOf` matcher uses [goraph](https://github.com/amitkgupta/goraph) which is embedded in the source to simplify distribution. goraph has an MIT license. 18 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/format/format_suite_test.go: -------------------------------------------------------------------------------- 1 | package format_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | 7 | "testing" 8 | ) 9 | 10 | func TestFormat(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "Format Suite") 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/gbytes/gbuffer_suite_test.go: -------------------------------------------------------------------------------- 1 | package gbytes_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | 7 | "testing" 8 | ) 9 | 10 | func TestGbytes(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "Gbytes Suite") 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/gexec/build.go: -------------------------------------------------------------------------------- 1 | package gexec 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "io/ioutil" 7 | "os" 8 | "os/exec" 9 | "path" 10 | "path/filepath" 11 | "runtime" 12 | ) 13 | 14 | var tmpDir string 15 | 16 | /* 17 | Build uses go build to compile the package at packagePath. The resulting binary is saved off in a temporary directory. 18 | A path pointing to this binary is returned. 19 | 20 | Build uses the $GOPATH set in your environment. It passes the variadic args on to `go build`. 21 | */ 22 | func Build(packagePath string, args ...string) (compiledPath string, err error) { 23 | return BuildIn(os.Getenv("GOPATH"), packagePath, args...) 24 | } 25 | 26 | /* 27 | BuildIn is identical to Build but allows you to specify a custom $GOPATH (the first argument). 28 | */ 29 | func BuildIn(gopath string, packagePath string, args ...string) (compiledPath string, err error) { 30 | tmpDir, err := temporaryDirectory() 31 | if err != nil { 32 | return "", err 33 | } 34 | 35 | if len(gopath) == 0 { 36 | return "", errors.New("$GOPATH not provided when building " + packagePath) 37 | } 38 | 39 | executable := filepath.Join(tmpDir, path.Base(packagePath)) 40 | if runtime.GOOS == "windows" { 41 | executable = executable + ".exe" 42 | } 43 | 44 | cmdArgs := append([]string{"build"}, args...) 45 | cmdArgs = append(cmdArgs, "-o", executable, packagePath) 46 | 47 | build := exec.Command("go", cmdArgs...) 48 | build.Env = append([]string{"GOPATH=" + gopath}, os.Environ()...) 49 | 50 | output, err := build.CombinedOutput() 51 | if err != nil { 52 | return "", fmt.Errorf("Failed to build %s:\n\nError:\n%s\n\nOutput:\n%s", packagePath, err, string(output)) 53 | } 54 | 55 | return executable, nil 56 | } 57 | 58 | /* 59 | You should call CleanupBuildArtifacts before your test ends to clean up any temporary artifacts generated by 60 | gexec. In Ginkgo this is typically done in an AfterSuite callback. 61 | */ 62 | func CleanupBuildArtifacts() { 63 | if tmpDir != "" { 64 | os.RemoveAll(tmpDir) 65 | } 66 | } 67 | 68 | func temporaryDirectory() (string, error) { 69 | var err error 70 | if tmpDir == "" { 71 | tmpDir, err = ioutil.TempDir("", "gexec_artifacts") 72 | if err != nil { 73 | return "", err 74 | } 75 | } 76 | 77 | return ioutil.TempDir(tmpDir, "g") 78 | } 79 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/gexec/exit_matcher.go: -------------------------------------------------------------------------------- 1 | package gexec 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/onsi/gomega/format" 7 | ) 8 | 9 | /* 10 | The Exit matcher operates on a session: 11 | 12 | Ω(session).Should(Exit()) 13 | 14 | Exit passes if the session has already exited. 15 | 16 | If no status code is provided, then Exit will succeed if the session has exited regardless of exit code. 17 | Otherwise, Exit will only succeed if the process has exited with the provided status code. 18 | 19 | Note that the process must have already exited. To wait for a process to exit, use Eventually: 20 | 21 | Eventually(session, 3).Should(Exit(0)) 22 | */ 23 | func Exit(optionalExitCode ...int) *exitMatcher { 24 | exitCode := -1 25 | if len(optionalExitCode) > 0 { 26 | exitCode = optionalExitCode[0] 27 | } 28 | 29 | return &exitMatcher{ 30 | exitCode: exitCode, 31 | } 32 | } 33 | 34 | type exitMatcher struct { 35 | exitCode int 36 | didExit bool 37 | actualExitCode int 38 | } 39 | 40 | type Exiter interface { 41 | ExitCode() int 42 | } 43 | 44 | func (m *exitMatcher) Match(actual interface{}) (success bool, err error) { 45 | exiter, ok := actual.(Exiter) 46 | if !ok { 47 | return false, fmt.Errorf("Exit must be passed a gexec.Exiter (Missing method ExitCode() int) Got:\n%s", format.Object(actual, 1)) 48 | } 49 | 50 | m.actualExitCode = exiter.ExitCode() 51 | 52 | if m.actualExitCode == -1 { 53 | return false, nil 54 | } 55 | 56 | if m.exitCode == -1 { 57 | return true, nil 58 | } 59 | return m.exitCode == m.actualExitCode, nil 60 | } 61 | 62 | func (m *exitMatcher) FailureMessage(actual interface{}) (message string) { 63 | if m.actualExitCode == -1 { 64 | return "Expected process to exit. It did not." 65 | } else { 66 | return format.Message(m.actualExitCode, "to match exit code:", m.exitCode) 67 | } 68 | } 69 | 70 | func (m *exitMatcher) NegatedFailureMessage(actual interface{}) (message string) { 71 | if m.actualExitCode == -1 { 72 | return "you really shouldn't be able to see this!" 73 | } else { 74 | if m.exitCode == -1 { 75 | return "Expected process not to exit. It did." 76 | } else { 77 | return format.Message(m.actualExitCode, "not to match exit code:", m.exitCode) 78 | } 79 | } 80 | } 81 | 82 | func (m *exitMatcher) MatchMayChangeInTheFuture(actual interface{}) bool { 83 | session, ok := actual.(*Session) 84 | if ok { 85 | return session.ExitCode() == -1 86 | } 87 | return true 88 | } 89 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/gexec/gexec_suite_test.go: -------------------------------------------------------------------------------- 1 | package gexec_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | "github.com/onsi/gomega/gexec" 7 | 8 | "testing" 9 | ) 10 | 11 | var fireflyPath string 12 | 13 | func TestGexec(t *testing.T) { 14 | BeforeSuite(func() { 15 | var err error 16 | fireflyPath, err = gexec.Build("./_fixture/firefly") 17 | Ω(err).ShouldNot(HaveOccurred()) 18 | }) 19 | 20 | AfterSuite(func() { 21 | gexec.CleanupBuildArtifacts() 22 | }) 23 | 24 | RegisterFailHandler(Fail) 25 | RunSpecs(t, "Gexec Suite") 26 | } 27 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/gexec/prefixed_writer.go: -------------------------------------------------------------------------------- 1 | package gexec 2 | 3 | import ( 4 | "bytes" 5 | "io" 6 | "sync" 7 | ) 8 | 9 | /* 10 | PrefixedWriter wraps an io.Writer, emiting the passed in prefix at the beginning of each new line. 11 | This can be useful when running multiple gexec.Sessions concurrently - you can prefix the log output of each 12 | session by passing in a PrefixedWriter: 13 | 14 | gexec.Start(cmd, NewPrefixedWriter("[my-cmd] ", GinkgoWriter), NewPrefixedWriter("[my-cmd] ", GinkgoWriter)) 15 | */ 16 | type PrefixedWriter struct { 17 | prefix []byte 18 | writer io.Writer 19 | lock *sync.Mutex 20 | isNewLine bool 21 | isFirstWrite bool 22 | } 23 | 24 | func NewPrefixedWriter(prefix string, writer io.Writer) *PrefixedWriter { 25 | return &PrefixedWriter{ 26 | prefix: []byte(prefix), 27 | writer: writer, 28 | lock: &sync.Mutex{}, 29 | isFirstWrite: true, 30 | } 31 | } 32 | 33 | func (w *PrefixedWriter) Write(b []byte) (int, error) { 34 | w.lock.Lock() 35 | defer w.lock.Unlock() 36 | 37 | newLine := []byte("\n") 38 | segments := bytes.Split(b, newLine) 39 | 40 | if len(segments) != 0 { 41 | toWrite := []byte{} 42 | if w.isFirstWrite { 43 | toWrite = append(toWrite, w.prefix...) 44 | toWrite = append(toWrite, segments[0]...) 45 | w.isFirstWrite = false 46 | } else if w.isNewLine { 47 | toWrite = append(toWrite, newLine...) 48 | toWrite = append(toWrite, w.prefix...) 49 | toWrite = append(toWrite, segments[0]...) 50 | } else { 51 | toWrite = append(toWrite, segments[0]...) 52 | } 53 | 54 | for i := 1; i < len(segments)-1; i++ { 55 | toWrite = append(toWrite, newLine...) 56 | toWrite = append(toWrite, w.prefix...) 57 | toWrite = append(toWrite, segments[i]...) 58 | } 59 | 60 | if len(segments) > 1 { 61 | lastSegment := segments[len(segments)-1] 62 | 63 | if len(lastSegment) == 0 { 64 | w.isNewLine = true 65 | } else { 66 | toWrite = append(toWrite, newLine...) 67 | toWrite = append(toWrite, w.prefix...) 68 | toWrite = append(toWrite, lastSegment...) 69 | w.isNewLine = false 70 | } 71 | } 72 | 73 | _, err := w.writer.Write(toWrite) 74 | if err != nil { 75 | return 0, err 76 | } 77 | } 78 | 79 | return len(b), nil 80 | } 81 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/gexec/prefixed_writer_test.go: -------------------------------------------------------------------------------- 1 | package gexec_test 2 | 3 | import ( 4 | "bytes" 5 | . "github.com/onsi/gomega/gexec" 6 | 7 | . "github.com/onsi/ginkgo" 8 | . "github.com/onsi/gomega" 9 | ) 10 | 11 | var _ = Describe("PrefixedWriter", func() { 12 | var buffer *bytes.Buffer 13 | var writer *PrefixedWriter 14 | BeforeEach(func() { 15 | buffer = &bytes.Buffer{} 16 | writer = NewPrefixedWriter("[p]", buffer) 17 | }) 18 | 19 | It("should emit the prefix on newlines", func() { 20 | writer.Write([]byte("abc")) 21 | writer.Write([]byte("def\n")) 22 | writer.Write([]byte("hij\n")) 23 | writer.Write([]byte("\n\n")) 24 | writer.Write([]byte("klm\n\nnop")) 25 | writer.Write([]byte("")) 26 | writer.Write([]byte("qrs")) 27 | writer.Write([]byte("\ntuv\nwx")) 28 | writer.Write([]byte("yz\n\n")) 29 | 30 | Ω(buffer.String()).Should(Equal(`[p]abcdef 31 | [p]hij 32 | [p] 33 | [p] 34 | [p]klm 35 | [p] 36 | [p]nopqrs 37 | [p]tuv 38 | [p]wxyz 39 | [p]`)) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/ghttp/test_server_suite_test.go: -------------------------------------------------------------------------------- 1 | package ghttp_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | 7 | "testing" 8 | ) 9 | 10 | func TestGHTTP(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "GHTTP Suite") 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/internal/assertion/assertion_suite_test.go: -------------------------------------------------------------------------------- 1 | package assertion_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | 7 | "testing" 8 | ) 9 | 10 | func TestAssertion(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "Assertion Suite") 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/internal/asyncassertion/async_assertion_suite_test.go: -------------------------------------------------------------------------------- 1 | package asyncassertion_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | 7 | "testing" 8 | ) 9 | 10 | func TestAsyncAssertion(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "AsyncAssertion Suite") 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/internal/fakematcher/fake_matcher.go: -------------------------------------------------------------------------------- 1 | package fakematcher 2 | 3 | import "fmt" 4 | 5 | type FakeMatcher struct { 6 | ReceivedActual interface{} 7 | MatchesToReturn bool 8 | ErrToReturn error 9 | } 10 | 11 | func (matcher *FakeMatcher) Match(actual interface{}) (bool, error) { 12 | matcher.ReceivedActual = actual 13 | 14 | return matcher.MatchesToReturn, matcher.ErrToReturn 15 | } 16 | 17 | func (matcher *FakeMatcher) FailureMessage(actual interface{}) string { 18 | return fmt.Sprintf("positive: %v", actual) 19 | } 20 | 21 | func (matcher *FakeMatcher) NegatedFailureMessage(actual interface{}) string { 22 | return fmt.Sprintf("negative: %v", actual) 23 | } 24 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/internal/testingtsupport/testing_t_support.go: -------------------------------------------------------------------------------- 1 | package testingtsupport 2 | 3 | import ( 4 | "regexp" 5 | "runtime/debug" 6 | "strings" 7 | 8 | "github.com/onsi/gomega/types" 9 | ) 10 | 11 | type gomegaTestingT interface { 12 | Errorf(format string, args ...interface{}) 13 | } 14 | 15 | func BuildTestingTGomegaFailHandler(t gomegaTestingT) types.GomegaFailHandler { 16 | return func(message string, callerSkip ...int) { 17 | skip := 1 18 | if len(callerSkip) > 0 { 19 | skip = callerSkip[0] 20 | } 21 | stackTrace := pruneStack(string(debug.Stack()), skip) 22 | t.Errorf("\n%s\n%s", stackTrace, message) 23 | } 24 | } 25 | 26 | func pruneStack(fullStackTrace string, skip int) string { 27 | stack := strings.Split(fullStackTrace, "\n") 28 | if len(stack) > 2*(skip+1) { 29 | stack = stack[2*(skip+1):] 30 | } 31 | prunedStack := []string{} 32 | re := regexp.MustCompile(`\/ginkgo\/|\/pkg\/testing\/|\/pkg\/runtime\/`) 33 | for i := 0; i < len(stack)/2; i++ { 34 | if !re.Match([]byte(stack[i*2])) { 35 | prunedStack = append(prunedStack, stack[i*2]) 36 | prunedStack = append(prunedStack, stack[i*2+1]) 37 | } 38 | } 39 | return strings.Join(prunedStack, "\n") 40 | } 41 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/internal/testingtsupport/testing_t_support_test.go: -------------------------------------------------------------------------------- 1 | package testingtsupport_test 2 | 3 | import ( 4 | . "github.com/onsi/gomega" 5 | 6 | "testing" 7 | ) 8 | 9 | func TestTestingT(t *testing.T) { 10 | RegisterTestingT(t) 11 | Ω(true).Should(BeTrue()) 12 | } 13 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/assignable_to_type_of_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "fmt" 5 | "github.com/onsi/gomega/format" 6 | "reflect" 7 | ) 8 | 9 | type AssignableToTypeOfMatcher struct { 10 | Expected interface{} 11 | } 12 | 13 | func (matcher *AssignableToTypeOfMatcher) Match(actual interface{}) (success bool, err error) { 14 | if actual == nil || matcher.Expected == nil { 15 | return false, fmt.Errorf("Refusing to compare to .") 16 | } 17 | 18 | actualType := reflect.TypeOf(actual) 19 | expectedType := reflect.TypeOf(matcher.Expected) 20 | 21 | return actualType.AssignableTo(expectedType), nil 22 | } 23 | 24 | func (matcher *AssignableToTypeOfMatcher) FailureMessage(actual interface{}) string { 25 | return format.Message(actual, fmt.Sprintf("to be assignable to the type: %T", matcher.Expected)) 26 | } 27 | 28 | func (matcher *AssignableToTypeOfMatcher) NegatedFailureMessage(actual interface{}) string { 29 | return format.Message(actual, fmt.Sprintf("not to be assignable to the type: %T", matcher.Expected)) 30 | } 31 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/assignable_to_type_of_matcher_test.go: -------------------------------------------------------------------------------- 1 | package matchers_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | . "github.com/onsi/gomega/matchers" 7 | ) 8 | 9 | var _ = Describe("AssignableToTypeOf", func() { 10 | Context("When asserting assignability between types", func() { 11 | It("should do the right thing", func() { 12 | Ω(0).Should(BeAssignableToTypeOf(0)) 13 | Ω(5).Should(BeAssignableToTypeOf(-1)) 14 | Ω("foo").Should(BeAssignableToTypeOf("bar")) 15 | Ω(struct{ Foo string }{}).Should(BeAssignableToTypeOf(struct{ Foo string }{})) 16 | 17 | Ω(0).ShouldNot(BeAssignableToTypeOf("bar")) 18 | Ω(5).ShouldNot(BeAssignableToTypeOf(struct{ Foo string }{})) 19 | Ω("foo").ShouldNot(BeAssignableToTypeOf(42)) 20 | }) 21 | }) 22 | 23 | Context("When asserting nil values", func() { 24 | It("should error", func() { 25 | success, err := (&AssignableToTypeOfMatcher{Expected: nil}).Match(nil) 26 | Ω(success).Should(BeFalse()) 27 | Ω(err).Should(HaveOccurred()) 28 | }) 29 | }) 30 | }) 31 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/be_closed_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "fmt" 5 | "github.com/onsi/gomega/format" 6 | "reflect" 7 | ) 8 | 9 | type BeClosedMatcher struct { 10 | } 11 | 12 | func (matcher *BeClosedMatcher) Match(actual interface{}) (success bool, err error) { 13 | if !isChan(actual) { 14 | return false, fmt.Errorf("BeClosed matcher expects a channel. Got:\n%s", format.Object(actual, 1)) 15 | } 16 | 17 | channelType := reflect.TypeOf(actual) 18 | channelValue := reflect.ValueOf(actual) 19 | 20 | if channelType.ChanDir() == reflect.SendDir { 21 | return false, fmt.Errorf("BeClosed matcher cannot determine if a send-only channel is closed or open. Got:\n%s", format.Object(actual, 1)) 22 | } 23 | 24 | winnerIndex, _, open := reflect.Select([]reflect.SelectCase{ 25 | reflect.SelectCase{Dir: reflect.SelectRecv, Chan: channelValue}, 26 | reflect.SelectCase{Dir: reflect.SelectDefault}, 27 | }) 28 | 29 | var closed bool 30 | if winnerIndex == 0 { 31 | closed = !open 32 | } else if winnerIndex == 1 { 33 | closed = false 34 | } 35 | 36 | return closed, nil 37 | } 38 | 39 | func (matcher *BeClosedMatcher) FailureMessage(actual interface{}) (message string) { 40 | return format.Message(actual, "to be closed") 41 | } 42 | 43 | func (matcher *BeClosedMatcher) NegatedFailureMessage(actual interface{}) (message string) { 44 | return format.Message(actual, "to be open") 45 | } 46 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/be_closed_matcher_test.go: -------------------------------------------------------------------------------- 1 | package matchers_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | . "github.com/onsi/gomega/matchers" 7 | ) 8 | 9 | var _ = Describe("BeClosedMatcher", func() { 10 | Context("when passed a channel", func() { 11 | It("should do the right thing", func() { 12 | openChannel := make(chan bool) 13 | Ω(openChannel).ShouldNot(BeClosed()) 14 | 15 | var openReaderChannel <-chan bool 16 | openReaderChannel = openChannel 17 | Ω(openReaderChannel).ShouldNot(BeClosed()) 18 | 19 | closedChannel := make(chan bool) 20 | close(closedChannel) 21 | 22 | Ω(closedChannel).Should(BeClosed()) 23 | 24 | var closedReaderChannel <-chan bool 25 | closedReaderChannel = closedChannel 26 | Ω(closedReaderChannel).Should(BeClosed()) 27 | }) 28 | }) 29 | 30 | Context("when passed a send-only channel", func() { 31 | It("should error", func() { 32 | openChannel := make(chan bool) 33 | var openWriterChannel chan<- bool 34 | openWriterChannel = openChannel 35 | 36 | success, err := (&BeClosedMatcher{}).Match(openWriterChannel) 37 | Ω(success).Should(BeFalse()) 38 | Ω(err).Should(HaveOccurred()) 39 | 40 | closedChannel := make(chan bool) 41 | close(closedChannel) 42 | 43 | var closedWriterChannel chan<- bool 44 | closedWriterChannel = closedChannel 45 | 46 | success, err = (&BeClosedMatcher{}).Match(closedWriterChannel) 47 | Ω(success).Should(BeFalse()) 48 | Ω(err).Should(HaveOccurred()) 49 | 50 | }) 51 | }) 52 | 53 | Context("when passed something else", func() { 54 | It("should error", func() { 55 | var nilChannel chan bool 56 | 57 | success, err := (&BeClosedMatcher{}).Match(nilChannel) 58 | Ω(success).Should(BeFalse()) 59 | Ω(err).Should(HaveOccurred()) 60 | 61 | success, err = (&BeClosedMatcher{}).Match(nil) 62 | Ω(success).Should(BeFalse()) 63 | Ω(err).Should(HaveOccurred()) 64 | 65 | success, err = (&BeClosedMatcher{}).Match(7) 66 | Ω(success).Should(BeFalse()) 67 | Ω(err).Should(HaveOccurred()) 68 | }) 69 | }) 70 | }) 71 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/be_empty_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "fmt" 5 | "github.com/onsi/gomega/format" 6 | ) 7 | 8 | type BeEmptyMatcher struct { 9 | } 10 | 11 | func (matcher *BeEmptyMatcher) Match(actual interface{}) (success bool, err error) { 12 | length, ok := lengthOf(actual) 13 | if !ok { 14 | return false, fmt.Errorf("BeEmpty matcher expects a string/array/map/channel/slice. Got:\n%s", format.Object(actual, 1)) 15 | } 16 | 17 | return length == 0, nil 18 | } 19 | 20 | func (matcher *BeEmptyMatcher) FailureMessage(actual interface{}) (message string) { 21 | return format.Message(actual, "to be empty") 22 | } 23 | 24 | func (matcher *BeEmptyMatcher) NegatedFailureMessage(actual interface{}) (message string) { 25 | return format.Message(actual, "not to be empty") 26 | } 27 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/be_empty_matcher_test.go: -------------------------------------------------------------------------------- 1 | package matchers_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | . "github.com/onsi/gomega/matchers" 7 | ) 8 | 9 | var _ = Describe("BeEmpty", func() { 10 | Context("when passed a supported type", func() { 11 | It("should do the right thing", func() { 12 | Ω("").Should(BeEmpty()) 13 | Ω(" ").ShouldNot(BeEmpty()) 14 | 15 | Ω([0]int{}).Should(BeEmpty()) 16 | Ω([1]int{1}).ShouldNot(BeEmpty()) 17 | 18 | Ω([]int{}).Should(BeEmpty()) 19 | Ω([]int{1}).ShouldNot(BeEmpty()) 20 | 21 | Ω(map[string]int{}).Should(BeEmpty()) 22 | Ω(map[string]int{"a": 1}).ShouldNot(BeEmpty()) 23 | 24 | c := make(chan bool, 1) 25 | Ω(c).Should(BeEmpty()) 26 | c <- true 27 | Ω(c).ShouldNot(BeEmpty()) 28 | }) 29 | }) 30 | 31 | Context("when passed a correctly typed nil", func() { 32 | It("should be true", func() { 33 | var nilSlice []int 34 | Ω(nilSlice).Should(BeEmpty()) 35 | 36 | var nilMap map[int]string 37 | Ω(nilMap).Should(BeEmpty()) 38 | }) 39 | }) 40 | 41 | Context("when passed an unsupported type", func() { 42 | It("should error", func() { 43 | success, err := (&BeEmptyMatcher{}).Match(0) 44 | Ω(success).Should(BeFalse()) 45 | Ω(err).Should(HaveOccurred()) 46 | 47 | success, err = (&BeEmptyMatcher{}).Match(nil) 48 | Ω(success).Should(BeFalse()) 49 | Ω(err).Should(HaveOccurred()) 50 | }) 51 | }) 52 | }) 53 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/be_equivalent_to_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "fmt" 5 | "github.com/onsi/gomega/format" 6 | "reflect" 7 | ) 8 | 9 | type BeEquivalentToMatcher struct { 10 | Expected interface{} 11 | } 12 | 13 | func (matcher *BeEquivalentToMatcher) Match(actual interface{}) (success bool, err error) { 14 | if actual == nil && matcher.Expected == nil { 15 | return false, fmt.Errorf("Both actual and expected must not be nil.") 16 | } 17 | 18 | convertedActual := actual 19 | 20 | if actual != nil && matcher.Expected != nil && reflect.TypeOf(actual).ConvertibleTo(reflect.TypeOf(matcher.Expected)) { 21 | convertedActual = reflect.ValueOf(actual).Convert(reflect.TypeOf(matcher.Expected)).Interface() 22 | } 23 | 24 | return reflect.DeepEqual(convertedActual, matcher.Expected), nil 25 | } 26 | 27 | func (matcher *BeEquivalentToMatcher) FailureMessage(actual interface{}) (message string) { 28 | return format.Message(actual, "to be equivalent to", matcher.Expected) 29 | } 30 | 31 | func (matcher *BeEquivalentToMatcher) NegatedFailureMessage(actual interface{}) (message string) { 32 | return format.Message(actual, "not to be equivalent to", matcher.Expected) 33 | } 34 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/be_equivalent_to_matcher_test.go: -------------------------------------------------------------------------------- 1 | package matchers_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | . "github.com/onsi/gomega/matchers" 7 | ) 8 | 9 | var _ = Describe("BeEquivalentTo", func() { 10 | Context("when asserting that nil is equivalent to nil", func() { 11 | It("should error", func() { 12 | success, err := (&BeEquivalentToMatcher{Expected: nil}).Match(nil) 13 | 14 | Ω(success).Should(BeFalse()) 15 | Ω(err).Should(HaveOccurred()) 16 | }) 17 | }) 18 | 19 | Context("When asserting on nil", func() { 20 | It("should do the right thing", func() { 21 | Ω("foo").ShouldNot(BeEquivalentTo(nil)) 22 | Ω(nil).ShouldNot(BeEquivalentTo(3)) 23 | Ω([]int{1, 2}).ShouldNot(BeEquivalentTo(nil)) 24 | }) 25 | }) 26 | 27 | Context("When asserting on type aliases", func() { 28 | It("should the right thing", func() { 29 | Ω(StringAlias("foo")).Should(BeEquivalentTo("foo")) 30 | Ω("foo").Should(BeEquivalentTo(StringAlias("foo"))) 31 | Ω(StringAlias("foo")).ShouldNot(BeEquivalentTo("bar")) 32 | Ω("foo").ShouldNot(BeEquivalentTo(StringAlias("bar"))) 33 | }) 34 | }) 35 | 36 | Context("When asserting on numbers", func() { 37 | It("should convert actual to expected and do the right thing", func() { 38 | Ω(5).Should(BeEquivalentTo(5)) 39 | Ω(5.0).Should(BeEquivalentTo(5.0)) 40 | Ω(5).Should(BeEquivalentTo(5.0)) 41 | 42 | Ω(5).ShouldNot(BeEquivalentTo("5")) 43 | Ω(5).ShouldNot(BeEquivalentTo(3)) 44 | 45 | //Here be dragons! 46 | Ω(5.1).Should(BeEquivalentTo(5)) 47 | Ω(5).ShouldNot(BeEquivalentTo(5.1)) 48 | }) 49 | }) 50 | }) 51 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/be_false_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "fmt" 5 | "github.com/onsi/gomega/format" 6 | ) 7 | 8 | type BeFalseMatcher struct { 9 | } 10 | 11 | func (matcher *BeFalseMatcher) Match(actual interface{}) (success bool, err error) { 12 | if !isBool(actual) { 13 | return false, fmt.Errorf("Expected a boolean. Got:\n%s", format.Object(actual, 1)) 14 | } 15 | 16 | return actual == false, nil 17 | } 18 | 19 | func (matcher *BeFalseMatcher) FailureMessage(actual interface{}) (message string) { 20 | return format.Message(actual, "to be false") 21 | } 22 | 23 | func (matcher *BeFalseMatcher) NegatedFailureMessage(actual interface{}) (message string) { 24 | return format.Message(actual, "not to be false") 25 | } 26 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/be_false_matcher_test.go: -------------------------------------------------------------------------------- 1 | package matchers_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | . "github.com/onsi/gomega/matchers" 7 | ) 8 | 9 | var _ = Describe("BeFalse", func() { 10 | It("should handle true and false correctly", func() { 11 | Ω(true).ShouldNot(BeFalse()) 12 | Ω(false).Should(BeFalse()) 13 | }) 14 | 15 | It("should only support booleans", func() { 16 | success, err := (&BeFalseMatcher{}).Match("foo") 17 | Ω(success).Should(BeFalse()) 18 | Ω(err).Should(HaveOccurred()) 19 | }) 20 | }) 21 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/be_nil_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import "github.com/onsi/gomega/format" 4 | 5 | type BeNilMatcher struct { 6 | } 7 | 8 | func (matcher *BeNilMatcher) Match(actual interface{}) (success bool, err error) { 9 | return isNil(actual), nil 10 | } 11 | 12 | func (matcher *BeNilMatcher) FailureMessage(actual interface{}) (message string) { 13 | return format.Message(actual, "to be nil") 14 | } 15 | 16 | func (matcher *BeNilMatcher) NegatedFailureMessage(actual interface{}) (message string) { 17 | return format.Message(actual, "not to be nil") 18 | } 19 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/be_nil_matcher_test.go: -------------------------------------------------------------------------------- 1 | package matchers_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | ) 7 | 8 | var _ = Describe("BeNil", func() { 9 | It("should succeed when passed nil", func() { 10 | Ω(nil).Should(BeNil()) 11 | }) 12 | 13 | It("should succeed when passed a typed nil", func() { 14 | var a []int 15 | Ω(a).Should(BeNil()) 16 | }) 17 | 18 | It("should succeed when passing nil pointer", func() { 19 | var f *struct{} 20 | Ω(f).Should(BeNil()) 21 | }) 22 | 23 | It("should not succeed when not passed nil", func() { 24 | Ω(0).ShouldNot(BeNil()) 25 | Ω(false).ShouldNot(BeNil()) 26 | Ω("").ShouldNot(BeNil()) 27 | }) 28 | }) 29 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/be_sent_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | 7 | "github.com/onsi/gomega/format" 8 | ) 9 | 10 | type BeSentMatcher struct { 11 | Arg interface{} 12 | channelClosed bool 13 | } 14 | 15 | func (matcher *BeSentMatcher) Match(actual interface{}) (success bool, err error) { 16 | if !isChan(actual) { 17 | return false, fmt.Errorf("BeSent expects a channel. Got:\n%s", format.Object(actual, 1)) 18 | } 19 | 20 | channelType := reflect.TypeOf(actual) 21 | channelValue := reflect.ValueOf(actual) 22 | 23 | if channelType.ChanDir() == reflect.RecvDir { 24 | return false, fmt.Errorf("BeSent matcher cannot be passed a receive-only channel. Got:\n%s", format.Object(actual, 1)) 25 | } 26 | 27 | argType := reflect.TypeOf(matcher.Arg) 28 | assignable := argType.AssignableTo(channelType.Elem()) 29 | 30 | if !assignable { 31 | return false, fmt.Errorf("Cannot pass:\n%s to the channel:\n%s\nThe types don't match.", format.Object(matcher.Arg, 1), format.Object(actual, 1)) 32 | } 33 | 34 | argValue := reflect.ValueOf(matcher.Arg) 35 | 36 | defer func() { 37 | if e := recover(); e != nil { 38 | success = false 39 | err = fmt.Errorf("Cannot send to a closed channel") 40 | matcher.channelClosed = true 41 | } 42 | }() 43 | 44 | winnerIndex, _, _ := reflect.Select([]reflect.SelectCase{ 45 | reflect.SelectCase{Dir: reflect.SelectSend, Chan: channelValue, Send: argValue}, 46 | reflect.SelectCase{Dir: reflect.SelectDefault}, 47 | }) 48 | 49 | var didSend bool 50 | if winnerIndex == 0 { 51 | didSend = true 52 | } 53 | 54 | return didSend, nil 55 | } 56 | 57 | func (matcher *BeSentMatcher) FailureMessage(actual interface{}) (message string) { 58 | return format.Message(actual, "to send:", matcher.Arg) 59 | } 60 | 61 | func (matcher *BeSentMatcher) NegatedFailureMessage(actual interface{}) (message string) { 62 | return format.Message(actual, "not to send:", matcher.Arg) 63 | } 64 | 65 | func (matcher *BeSentMatcher) MatchMayChangeInTheFuture(actual interface{}) bool { 66 | if !isChan(actual) { 67 | return false 68 | } 69 | 70 | return !matcher.channelClosed 71 | } 72 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/be_temporally_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "fmt" 5 | "github.com/onsi/gomega/format" 6 | "time" 7 | ) 8 | 9 | type BeTemporallyMatcher struct { 10 | Comparator string 11 | CompareTo time.Time 12 | Threshold []time.Duration 13 | } 14 | 15 | func (matcher *BeTemporallyMatcher) FailureMessage(actual interface{}) (message string) { 16 | return format.Message(actual, fmt.Sprintf("to be %s", matcher.Comparator), matcher.CompareTo) 17 | } 18 | 19 | func (matcher *BeTemporallyMatcher) NegatedFailureMessage(actual interface{}) (message string) { 20 | return format.Message(actual, fmt.Sprintf("not to be %s", matcher.Comparator), matcher.CompareTo) 21 | } 22 | 23 | func (matcher *BeTemporallyMatcher) Match(actual interface{}) (bool, error) { 24 | // predicate to test for time.Time type 25 | isTime := func(t interface{}) bool { 26 | _, ok := t.(time.Time) 27 | return ok 28 | } 29 | 30 | if !isTime(actual) { 31 | return false, fmt.Errorf("Expected a time.Time. Got:\n%s", format.Object(actual, 1)) 32 | } 33 | 34 | switch matcher.Comparator { 35 | case "==", "~", ">", ">=", "<", "<=": 36 | default: 37 | return false, fmt.Errorf("Unknown comparator: %s", matcher.Comparator) 38 | } 39 | 40 | var threshold = time.Millisecond 41 | if len(matcher.Threshold) == 1 { 42 | threshold = matcher.Threshold[0] 43 | } 44 | 45 | return matcher.matchTimes(actual.(time.Time), matcher.CompareTo, threshold), nil 46 | } 47 | 48 | func (matcher *BeTemporallyMatcher) matchTimes(actual, compareTo time.Time, threshold time.Duration) (success bool) { 49 | switch matcher.Comparator { 50 | case "==": 51 | return actual.Equal(compareTo) 52 | case "~": 53 | diff := actual.Sub(compareTo) 54 | return -threshold <= diff && diff <= threshold 55 | case ">": 56 | return actual.After(compareTo) 57 | case ">=": 58 | return !actual.Before(compareTo) 59 | case "<": 60 | return actual.Before(compareTo) 61 | case "<=": 62 | return !actual.After(compareTo) 63 | } 64 | return false 65 | } 66 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/be_true_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "fmt" 5 | "github.com/onsi/gomega/format" 6 | ) 7 | 8 | type BeTrueMatcher struct { 9 | } 10 | 11 | func (matcher *BeTrueMatcher) Match(actual interface{}) (success bool, err error) { 12 | if !isBool(actual) { 13 | return false, fmt.Errorf("Expected a boolean. Got:\n%s", format.Object(actual, 1)) 14 | } 15 | 16 | return actual.(bool), nil 17 | } 18 | 19 | func (matcher *BeTrueMatcher) FailureMessage(actual interface{}) (message string) { 20 | return format.Message(actual, "to be true") 21 | } 22 | 23 | func (matcher *BeTrueMatcher) NegatedFailureMessage(actual interface{}) (message string) { 24 | return format.Message(actual, "not to be true") 25 | } 26 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/be_true_matcher_test.go: -------------------------------------------------------------------------------- 1 | package matchers_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | . "github.com/onsi/gomega/matchers" 7 | ) 8 | 9 | var _ = Describe("BeTrue", func() { 10 | It("should handle true and false correctly", func() { 11 | Ω(true).Should(BeTrue()) 12 | Ω(false).ShouldNot(BeTrue()) 13 | }) 14 | 15 | It("should only support booleans", func() { 16 | success, err := (&BeTrueMatcher{}).Match("foo") 17 | Ω(success).Should(BeFalse()) 18 | Ω(err).Should(HaveOccurred()) 19 | }) 20 | }) 21 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/be_zero_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "github.com/onsi/gomega/format" 5 | "reflect" 6 | ) 7 | 8 | type BeZeroMatcher struct { 9 | } 10 | 11 | func (matcher *BeZeroMatcher) Match(actual interface{}) (success bool, err error) { 12 | if actual == nil { 13 | return true, nil 14 | } 15 | zeroValue := reflect.Zero(reflect.TypeOf(actual)).Interface() 16 | 17 | return reflect.DeepEqual(zeroValue, actual), nil 18 | 19 | } 20 | 21 | func (matcher *BeZeroMatcher) FailureMessage(actual interface{}) (message string) { 22 | return format.Message(actual, "to be zero-valued") 23 | } 24 | 25 | func (matcher *BeZeroMatcher) NegatedFailureMessage(actual interface{}) (message string) { 26 | return format.Message(actual, "not to be zero-valued") 27 | } 28 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/be_zero_matcher_test.go: -------------------------------------------------------------------------------- 1 | package matchers_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | ) 7 | 8 | var _ = Describe("BeZero", func() { 9 | It("should succeed if the passed in object is the zero value for its type", func() { 10 | Ω(nil).Should(BeZero()) 11 | 12 | Ω("").Should(BeZero()) 13 | Ω(" ").ShouldNot(BeZero()) 14 | 15 | Ω(0).Should(BeZero()) 16 | Ω(1).ShouldNot(BeZero()) 17 | 18 | Ω(0.0).Should(BeZero()) 19 | Ω(0.1).ShouldNot(BeZero()) 20 | 21 | // Ω([]int{}).Should(BeZero()) 22 | Ω([]int{1}).ShouldNot(BeZero()) 23 | 24 | // Ω(map[string]int{}).Should(BeZero()) 25 | Ω(map[string]int{"a": 1}).ShouldNot(BeZero()) 26 | 27 | Ω(myCustomType{}).Should(BeZero()) 28 | Ω(myCustomType{s: "a"}).ShouldNot(BeZero()) 29 | }) 30 | }) 31 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/consist_of.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | 7 | "github.com/onsi/gomega/format" 8 | "github.com/onsi/gomega/matchers/support/goraph/bipartitegraph" 9 | ) 10 | 11 | type ConsistOfMatcher struct { 12 | Elements []interface{} 13 | } 14 | 15 | func (matcher *ConsistOfMatcher) Match(actual interface{}) (success bool, err error) { 16 | if !isArrayOrSlice(actual) && !isMap(actual) { 17 | return false, fmt.Errorf("ConsistOf matcher expects an array/slice/map. Got:\n%s", format.Object(actual, 1)) 18 | } 19 | 20 | elements := matcher.Elements 21 | if len(matcher.Elements) == 1 && isArrayOrSlice(matcher.Elements[0]) { 22 | elements = []interface{}{} 23 | value := reflect.ValueOf(matcher.Elements[0]) 24 | for i := 0; i < value.Len(); i++ { 25 | elements = append(elements, value.Index(i).Interface()) 26 | } 27 | } 28 | 29 | matchers := []interface{}{} 30 | for _, element := range elements { 31 | matcher, isMatcher := element.(omegaMatcher) 32 | if !isMatcher { 33 | matcher = &EqualMatcher{Expected: element} 34 | } 35 | matchers = append(matchers, matcher) 36 | } 37 | 38 | values := matcher.valuesOf(actual) 39 | 40 | if len(values) != len(matchers) { 41 | return false, nil 42 | } 43 | 44 | neighbours := func(v, m interface{}) (bool, error) { 45 | match, err := m.(omegaMatcher).Match(v) 46 | return match && err == nil, nil 47 | } 48 | 49 | bipartiteGraph, err := bipartitegraph.NewBipartiteGraph(values, matchers, neighbours) 50 | if err != nil { 51 | return false, err 52 | } 53 | 54 | return len(bipartiteGraph.LargestMatching()) == len(values), nil 55 | } 56 | 57 | func (matcher *ConsistOfMatcher) valuesOf(actual interface{}) []interface{} { 58 | value := reflect.ValueOf(actual) 59 | values := []interface{}{} 60 | if isMap(actual) { 61 | keys := value.MapKeys() 62 | for i := 0; i < value.Len(); i++ { 63 | values = append(values, value.MapIndex(keys[i]).Interface()) 64 | } 65 | } else { 66 | for i := 0; i < value.Len(); i++ { 67 | values = append(values, value.Index(i).Interface()) 68 | } 69 | } 70 | 71 | return values 72 | } 73 | 74 | func (matcher *ConsistOfMatcher) FailureMessage(actual interface{}) (message string) { 75 | return format.Message(actual, "to consist of", matcher.Elements) 76 | } 77 | 78 | func (matcher *ConsistOfMatcher) NegatedFailureMessage(actual interface{}) (message string) { 79 | return format.Message(actual, "not to consist of", matcher.Elements) 80 | } 81 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/contain_element_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "fmt" 5 | "github.com/onsi/gomega/format" 6 | "reflect" 7 | ) 8 | 9 | type ContainElementMatcher struct { 10 | Element interface{} 11 | } 12 | 13 | func (matcher *ContainElementMatcher) Match(actual interface{}) (success bool, err error) { 14 | if !isArrayOrSlice(actual) && !isMap(actual) { 15 | return false, fmt.Errorf("ContainElement matcher expects an array/slice/map. Got:\n%s", format.Object(actual, 1)) 16 | } 17 | 18 | elemMatcher, elementIsMatcher := matcher.Element.(omegaMatcher) 19 | if !elementIsMatcher { 20 | elemMatcher = &EqualMatcher{Expected: matcher.Element} 21 | } 22 | 23 | value := reflect.ValueOf(actual) 24 | var keys []reflect.Value 25 | if isMap(actual) { 26 | keys = value.MapKeys() 27 | } 28 | for i := 0; i < value.Len(); i++ { 29 | var success bool 30 | var err error 31 | if isMap(actual) { 32 | success, err = elemMatcher.Match(value.MapIndex(keys[i]).Interface()) 33 | } else { 34 | success, err = elemMatcher.Match(value.Index(i).Interface()) 35 | } 36 | if err != nil { 37 | return false, fmt.Errorf("ContainElement's element matcher failed with:\n\t%s", err.Error()) 38 | } 39 | if success { 40 | return true, nil 41 | } 42 | } 43 | 44 | return false, nil 45 | } 46 | 47 | func (matcher *ContainElementMatcher) FailureMessage(actual interface{}) (message string) { 48 | return format.Message(actual, "to contain element matching", matcher.Element) 49 | } 50 | 51 | func (matcher *ContainElementMatcher) NegatedFailureMessage(actual interface{}) (message string) { 52 | return format.Message(actual, "not to contain element matching", matcher.Element) 53 | } 54 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/contain_substring_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "fmt" 5 | "github.com/onsi/gomega/format" 6 | "strings" 7 | ) 8 | 9 | type ContainSubstringMatcher struct { 10 | Substr string 11 | Args []interface{} 12 | } 13 | 14 | func (matcher *ContainSubstringMatcher) Match(actual interface{}) (success bool, err error) { 15 | actualString, ok := toString(actual) 16 | if !ok { 17 | return false, fmt.Errorf("ContainSubstring matcher requires a string or stringer. Got:\n%s", format.Object(actual, 1)) 18 | } 19 | 20 | return strings.Contains(actualString, matcher.stringToMatch()), nil 21 | } 22 | 23 | func (matcher *ContainSubstringMatcher) stringToMatch() string { 24 | stringToMatch := matcher.Substr 25 | if len(matcher.Args) > 0 { 26 | stringToMatch = fmt.Sprintf(matcher.Substr, matcher.Args...) 27 | } 28 | return stringToMatch 29 | } 30 | 31 | func (matcher *ContainSubstringMatcher) FailureMessage(actual interface{}) (message string) { 32 | return format.Message(actual, "to contain substring", matcher.stringToMatch()) 33 | } 34 | 35 | func (matcher *ContainSubstringMatcher) NegatedFailureMessage(actual interface{}) (message string) { 36 | return format.Message(actual, "not to contain substring", matcher.stringToMatch()) 37 | } 38 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/contain_substring_matcher_test.go: -------------------------------------------------------------------------------- 1 | package matchers_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | . "github.com/onsi/gomega/matchers" 7 | ) 8 | 9 | var _ = Describe("ContainSubstringMatcher", func() { 10 | Context("when actual is a string", func() { 11 | It("should match against the string", func() { 12 | Ω("Marvelous").Should(ContainSubstring("rve")) 13 | Ω("Marvelous").ShouldNot(ContainSubstring("boo")) 14 | }) 15 | }) 16 | 17 | Context("when the matcher is called with multiple arguments", func() { 18 | It("should pass the string and arguments to sprintf", func() { 19 | Ω("Marvelous3").Should(ContainSubstring("velous%d", 3)) 20 | }) 21 | }) 22 | 23 | Context("when actual is a stringer", func() { 24 | It("should call the stringer and match agains the returned string", func() { 25 | Ω(&myStringer{a: "Abc3"}).Should(ContainSubstring("bc3")) 26 | }) 27 | }) 28 | 29 | Context("when actual is neither a string nor a stringer", func() { 30 | It("should error", func() { 31 | success, err := (&ContainSubstringMatcher{Substr: "2"}).Match(2) 32 | Ω(success).Should(BeFalse()) 33 | Ω(err).Should(HaveOccurred()) 34 | }) 35 | }) 36 | }) 37 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/equal_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "fmt" 5 | "github.com/onsi/gomega/format" 6 | "reflect" 7 | ) 8 | 9 | type EqualMatcher struct { 10 | Expected interface{} 11 | } 12 | 13 | func (matcher *EqualMatcher) Match(actual interface{}) (success bool, err error) { 14 | if actual == nil && matcher.Expected == nil { 15 | return false, fmt.Errorf("Refusing to compare to .") 16 | } 17 | return reflect.DeepEqual(actual, matcher.Expected), nil 18 | } 19 | 20 | func (matcher *EqualMatcher) FailureMessage(actual interface{}) (message string) { 21 | return format.Message(actual, "to equal", matcher.Expected) 22 | } 23 | 24 | func (matcher *EqualMatcher) NegatedFailureMessage(actual interface{}) (message string) { 25 | return format.Message(actual, "not to equal", matcher.Expected) 26 | } 27 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/equal_matcher_test.go: -------------------------------------------------------------------------------- 1 | package matchers_test 2 | 3 | import ( 4 | "errors" 5 | . "github.com/onsi/ginkgo" 6 | . "github.com/onsi/gomega" 7 | . "github.com/onsi/gomega/matchers" 8 | ) 9 | 10 | var _ = Describe("Equal", func() { 11 | Context("when asserting that nil equals nil", func() { 12 | It("should error", func() { 13 | success, err := (&EqualMatcher{Expected: nil}).Match(nil) 14 | 15 | Ω(success).Should(BeFalse()) 16 | Ω(err).Should(HaveOccurred()) 17 | }) 18 | }) 19 | 20 | Context("When asserting equality between objects", func() { 21 | It("should do the right thing", func() { 22 | Ω(5).Should(Equal(5)) 23 | Ω(5.0).Should(Equal(5.0)) 24 | 25 | Ω(5).ShouldNot(Equal("5")) 26 | Ω(5).ShouldNot(Equal(5.0)) 27 | Ω(5).ShouldNot(Equal(3)) 28 | 29 | Ω("5").Should(Equal("5")) 30 | Ω([]int{1, 2}).Should(Equal([]int{1, 2})) 31 | Ω([]int{1, 2}).ShouldNot(Equal([]int{2, 1})) 32 | Ω(map[string]string{"a": "b", "c": "d"}).Should(Equal(map[string]string{"a": "b", "c": "d"})) 33 | Ω(map[string]string{"a": "b", "c": "d"}).ShouldNot(Equal(map[string]string{"a": "b", "c": "e"})) 34 | Ω(errors.New("foo")).Should(Equal(errors.New("foo"))) 35 | Ω(errors.New("foo")).ShouldNot(Equal(errors.New("bar"))) 36 | 37 | Ω(myCustomType{s: "foo", n: 3, f: 2.0, arr: []string{"a", "b"}}).Should(Equal(myCustomType{s: "foo", n: 3, f: 2.0, arr: []string{"a", "b"}})) 38 | Ω(myCustomType{s: "foo", n: 3, f: 2.0, arr: []string{"a", "b"}}).ShouldNot(Equal(myCustomType{s: "bar", n: 3, f: 2.0, arr: []string{"a", "b"}})) 39 | Ω(myCustomType{s: "foo", n: 3, f: 2.0, arr: []string{"a", "b"}}).ShouldNot(Equal(myCustomType{s: "foo", n: 2, f: 2.0, arr: []string{"a", "b"}})) 40 | Ω(myCustomType{s: "foo", n: 3, f: 2.0, arr: []string{"a", "b"}}).ShouldNot(Equal(myCustomType{s: "foo", n: 3, f: 3.0, arr: []string{"a", "b"}})) 41 | Ω(myCustomType{s: "foo", n: 3, f: 2.0, arr: []string{"a", "b"}}).ShouldNot(Equal(myCustomType{s: "foo", n: 3, f: 2.0, arr: []string{"a", "b", "c"}})) 42 | }) 43 | }) 44 | }) 45 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/have_key_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "fmt" 5 | "github.com/onsi/gomega/format" 6 | "reflect" 7 | ) 8 | 9 | type HaveKeyMatcher struct { 10 | Key interface{} 11 | } 12 | 13 | func (matcher *HaveKeyMatcher) Match(actual interface{}) (success bool, err error) { 14 | if !isMap(actual) { 15 | return false, fmt.Errorf("HaveKey matcher expects a map. Got:%s", format.Object(actual, 1)) 16 | } 17 | 18 | keyMatcher, keyIsMatcher := matcher.Key.(omegaMatcher) 19 | if !keyIsMatcher { 20 | keyMatcher = &EqualMatcher{Expected: matcher.Key} 21 | } 22 | 23 | keys := reflect.ValueOf(actual).MapKeys() 24 | for i := 0; i < len(keys); i++ { 25 | success, err := keyMatcher.Match(keys[i].Interface()) 26 | if err != nil { 27 | return false, fmt.Errorf("HaveKey's key matcher failed with:\n%s%s", format.Indent, err.Error()) 28 | } 29 | if success { 30 | return true, nil 31 | } 32 | } 33 | 34 | return false, nil 35 | } 36 | 37 | func (matcher *HaveKeyMatcher) FailureMessage(actual interface{}) (message string) { 38 | switch matcher.Key.(type) { 39 | case omegaMatcher: 40 | return format.Message(actual, "to have key matching", matcher.Key) 41 | default: 42 | return format.Message(actual, "to have key", matcher.Key) 43 | } 44 | } 45 | 46 | func (matcher *HaveKeyMatcher) NegatedFailureMessage(actual interface{}) (message string) { 47 | switch matcher.Key.(type) { 48 | case omegaMatcher: 49 | return format.Message(actual, "not to have key matching", matcher.Key) 50 | default: 51 | return format.Message(actual, "not to have key", matcher.Key) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/have_key_matcher_test.go: -------------------------------------------------------------------------------- 1 | package matchers_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | . "github.com/onsi/gomega/matchers" 7 | ) 8 | 9 | var _ = Describe("HaveKey", func() { 10 | var ( 11 | stringKeys map[string]int 12 | intKeys map[int]string 13 | objKeys map[*myCustomType]string 14 | 15 | customA *myCustomType 16 | customB *myCustomType 17 | ) 18 | BeforeEach(func() { 19 | stringKeys = map[string]int{"foo": 2, "bar": 3} 20 | intKeys = map[int]string{2: "foo", 3: "bar"} 21 | 22 | customA = &myCustomType{s: "a", n: 2, f: 2.3, arr: []string{"ice", "cream"}} 23 | customB = &myCustomType{s: "b", n: 4, f: 3.1, arr: []string{"cake"}} 24 | objKeys = map[*myCustomType]string{customA: "aardvark", customB: "kangaroo"} 25 | }) 26 | 27 | Context("when passed a map", func() { 28 | It("should do the right thing", func() { 29 | Ω(stringKeys).Should(HaveKey("foo")) 30 | Ω(stringKeys).ShouldNot(HaveKey("baz")) 31 | 32 | Ω(intKeys).Should(HaveKey(2)) 33 | Ω(intKeys).ShouldNot(HaveKey(4)) 34 | 35 | Ω(objKeys).Should(HaveKey(customA)) 36 | Ω(objKeys).Should(HaveKey(&myCustomType{s: "b", n: 4, f: 3.1, arr: []string{"cake"}})) 37 | Ω(objKeys).ShouldNot(HaveKey(&myCustomType{s: "b", n: 4, f: 3.1, arr: []string{"apple", "pie"}})) 38 | }) 39 | }) 40 | 41 | Context("when passed a correctly typed nil", func() { 42 | It("should operate succesfully on the passed in value", func() { 43 | var nilMap map[int]string 44 | Ω(nilMap).ShouldNot(HaveKey("foo")) 45 | }) 46 | }) 47 | 48 | Context("when the passed in key is actually a matcher", func() { 49 | It("should pass each element through the matcher", func() { 50 | Ω(stringKeys).Should(HaveKey(ContainSubstring("oo"))) 51 | Ω(stringKeys).ShouldNot(HaveKey(ContainSubstring("foobar"))) 52 | }) 53 | 54 | It("should fail if the matcher ever fails", func() { 55 | actual := map[int]string{1: "a", 3: "b", 2: "c"} 56 | success, err := (&HaveKeyMatcher{Key: ContainSubstring("ar")}).Match(actual) 57 | Ω(success).Should(BeFalse()) 58 | Ω(err).Should(HaveOccurred()) 59 | }) 60 | }) 61 | 62 | Context("when passed something that is not a map", func() { 63 | It("should error", func() { 64 | success, err := (&HaveKeyMatcher{Key: "foo"}).Match([]string{"foo"}) 65 | Ω(success).Should(BeFalse()) 66 | Ω(err).Should(HaveOccurred()) 67 | 68 | success, err = (&HaveKeyMatcher{Key: "foo"}).Match(nil) 69 | Ω(success).Should(BeFalse()) 70 | Ω(err).Should(HaveOccurred()) 71 | }) 72 | }) 73 | }) 74 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/have_key_with_value_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "fmt" 5 | "github.com/onsi/gomega/format" 6 | "reflect" 7 | ) 8 | 9 | type HaveKeyWithValueMatcher struct { 10 | Key interface{} 11 | Value interface{} 12 | } 13 | 14 | func (matcher *HaveKeyWithValueMatcher) Match(actual interface{}) (success bool, err error) { 15 | if !isMap(actual) { 16 | return false, fmt.Errorf("HaveKeyWithValue matcher expects a map. Got:%s", format.Object(actual, 1)) 17 | } 18 | 19 | keyMatcher, keyIsMatcher := matcher.Key.(omegaMatcher) 20 | if !keyIsMatcher { 21 | keyMatcher = &EqualMatcher{Expected: matcher.Key} 22 | } 23 | 24 | valueMatcher, valueIsMatcher := matcher.Value.(omegaMatcher) 25 | if !valueIsMatcher { 26 | valueMatcher = &EqualMatcher{Expected: matcher.Value} 27 | } 28 | 29 | keys := reflect.ValueOf(actual).MapKeys() 30 | for i := 0; i < len(keys); i++ { 31 | success, err := keyMatcher.Match(keys[i].Interface()) 32 | if err != nil { 33 | return false, fmt.Errorf("HaveKeyWithValue's key matcher failed with:\n%s%s", format.Indent, err.Error()) 34 | } 35 | if success { 36 | actualValue := reflect.ValueOf(actual).MapIndex(keys[i]) 37 | success, err := valueMatcher.Match(actualValue.Interface()) 38 | if err != nil { 39 | return false, fmt.Errorf("HaveKeyWithValue's value matcher failed with:\n%s%s", format.Indent, err.Error()) 40 | } 41 | return success, nil 42 | } 43 | } 44 | 45 | return false, nil 46 | } 47 | 48 | func (matcher *HaveKeyWithValueMatcher) FailureMessage(actual interface{}) (message string) { 49 | str := "to have {key: value}" 50 | if _, ok := matcher.Key.(omegaMatcher); ok { 51 | str += " matching" 52 | } else if _, ok := matcher.Value.(omegaMatcher); ok { 53 | str += " matching" 54 | } 55 | 56 | expect := make(map[interface{}]interface{}, 1) 57 | expect[matcher.Key] = matcher.Value 58 | return format.Message(actual, str, expect) 59 | } 60 | 61 | func (matcher *HaveKeyWithValueMatcher) NegatedFailureMessage(actual interface{}) (message string) { 62 | kStr := "not to have key" 63 | if _, ok := matcher.Key.(omegaMatcher); ok { 64 | kStr = "not to have key matching" 65 | } 66 | 67 | vStr := "or that key's value not be" 68 | if _, ok := matcher.Value.(omegaMatcher); ok { 69 | vStr = "or to have that key's value not matching" 70 | } 71 | 72 | return format.Message(actual, kStr, matcher.Key, vStr, matcher.Value) 73 | } 74 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/have_len_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "fmt" 5 | "github.com/onsi/gomega/format" 6 | ) 7 | 8 | type HaveLenMatcher struct { 9 | Count int 10 | } 11 | 12 | func (matcher *HaveLenMatcher) Match(actual interface{}) (success bool, err error) { 13 | length, ok := lengthOf(actual) 14 | if !ok { 15 | return false, fmt.Errorf("HaveLen matcher expects a string/array/map/channel/slice. Got:\n%s", format.Object(actual, 1)) 16 | } 17 | 18 | return length == matcher.Count, nil 19 | } 20 | 21 | func (matcher *HaveLenMatcher) FailureMessage(actual interface{}) (message string) { 22 | return fmt.Sprintf("Expected\n%s\nto have length %d", format.Object(actual, 1), matcher.Count) 23 | } 24 | 25 | func (matcher *HaveLenMatcher) NegatedFailureMessage(actual interface{}) (message string) { 26 | return fmt.Sprintf("Expected\n%s\nnot to have length %d", format.Object(actual, 1), matcher.Count) 27 | } 28 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/have_len_matcher_test.go: -------------------------------------------------------------------------------- 1 | package matchers_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | . "github.com/onsi/gomega/matchers" 7 | ) 8 | 9 | var _ = Describe("HaveLen", func() { 10 | Context("when passed a supported type", func() { 11 | It("should do the right thing", func() { 12 | Ω("").Should(HaveLen(0)) 13 | Ω("AA").Should(HaveLen(2)) 14 | 15 | Ω([0]int{}).Should(HaveLen(0)) 16 | Ω([2]int{1, 2}).Should(HaveLen(2)) 17 | 18 | Ω([]int{}).Should(HaveLen(0)) 19 | Ω([]int{1, 2, 3}).Should(HaveLen(3)) 20 | 21 | Ω(map[string]int{}).Should(HaveLen(0)) 22 | Ω(map[string]int{"a": 1, "b": 2, "c": 3, "d": 4}).Should(HaveLen(4)) 23 | 24 | c := make(chan bool, 3) 25 | Ω(c).Should(HaveLen(0)) 26 | c <- true 27 | c <- true 28 | Ω(c).Should(HaveLen(2)) 29 | }) 30 | }) 31 | 32 | Context("when passed a correctly typed nil", func() { 33 | It("should operate succesfully on the passed in value", func() { 34 | var nilSlice []int 35 | Ω(nilSlice).Should(HaveLen(0)) 36 | 37 | var nilMap map[int]string 38 | Ω(nilMap).Should(HaveLen(0)) 39 | }) 40 | }) 41 | 42 | Context("when passed an unsupported type", func() { 43 | It("should error", func() { 44 | success, err := (&HaveLenMatcher{Count: 0}).Match(0) 45 | Ω(success).Should(BeFalse()) 46 | Ω(err).Should(HaveOccurred()) 47 | 48 | success, err = (&HaveLenMatcher{Count: 0}).Match(nil) 49 | Ω(success).Should(BeFalse()) 50 | Ω(err).Should(HaveOccurred()) 51 | }) 52 | }) 53 | }) 54 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/have_occurred_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "fmt" 5 | "github.com/onsi/gomega/format" 6 | ) 7 | 8 | type HaveOccurredMatcher struct { 9 | } 10 | 11 | func (matcher *HaveOccurredMatcher) Match(actual interface{}) (success bool, err error) { 12 | if actual == nil { 13 | return false, nil 14 | } 15 | 16 | if isError(actual) { 17 | return true, nil 18 | } 19 | 20 | return false, fmt.Errorf("Expected an error. Got:\n%s", format.Object(actual, 1)) 21 | } 22 | 23 | func (matcher *HaveOccurredMatcher) FailureMessage(actual interface{}) (message string) { 24 | return fmt.Sprintf("Expected an error to have occured. Got:\n%s", format.Object(actual, 1)) 25 | } 26 | 27 | func (matcher *HaveOccurredMatcher) NegatedFailureMessage(actual interface{}) (message string) { 28 | return fmt.Sprintf("Expected error:\n%s\n%s\n%s", format.Object(actual, 1), format.IndentString(actual.(error).Error(), 1), "not to have occurred") 29 | } 30 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/have_occurred_matcher_test.go: -------------------------------------------------------------------------------- 1 | package matchers_test 2 | 3 | import ( 4 | "errors" 5 | . "github.com/onsi/ginkgo" 6 | . "github.com/onsi/gomega" 7 | . "github.com/onsi/gomega/matchers" 8 | ) 9 | 10 | var _ = Describe("HaveOccurred", func() { 11 | It("should succeed if matching an error", func() { 12 | Ω(errors.New("Foo")).Should(HaveOccurred()) 13 | }) 14 | 15 | It("should not succeed with nil", func() { 16 | Ω(nil).ShouldNot(HaveOccurred()) 17 | }) 18 | 19 | It("should only support errors and nil", func() { 20 | success, err := (&HaveOccurredMatcher{}).Match("foo") 21 | Ω(success).Should(BeFalse()) 22 | Ω(err).Should(HaveOccurred()) 23 | 24 | success, err = (&HaveOccurredMatcher{}).Match("") 25 | Ω(success).Should(BeFalse()) 26 | Ω(err).Should(HaveOccurred()) 27 | }) 28 | }) 29 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/match_error_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "fmt" 5 | "github.com/onsi/gomega/format" 6 | "reflect" 7 | ) 8 | 9 | type MatchErrorMatcher struct { 10 | Expected interface{} 11 | } 12 | 13 | func (matcher *MatchErrorMatcher) Match(actual interface{}) (success bool, err error) { 14 | if isNil(actual) { 15 | return false, fmt.Errorf("Expected an error, got nil") 16 | } 17 | 18 | if !isError(actual) { 19 | return false, fmt.Errorf("Expected an error. Got:\n%s", format.Object(actual, 1)) 20 | } 21 | 22 | actualErr := actual.(error) 23 | 24 | if isString(matcher.Expected) { 25 | return reflect.DeepEqual(actualErr.Error(), matcher.Expected), nil 26 | } 27 | 28 | if isError(matcher.Expected) { 29 | return reflect.DeepEqual(actualErr, matcher.Expected), nil 30 | } 31 | 32 | return false, fmt.Errorf("MatchError must be passed an error or string. Got:\n%s", format.Object(matcher.Expected, 1)) 33 | } 34 | 35 | func (matcher *MatchErrorMatcher) FailureMessage(actual interface{}) (message string) { 36 | return format.Message(actual, "to match error", matcher.Expected) 37 | } 38 | 39 | func (matcher *MatchErrorMatcher) NegatedFailureMessage(actual interface{}) (message string) { 40 | return format.Message(actual, "not to match error", matcher.Expected) 41 | } 42 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/match_error_matcher_test.go: -------------------------------------------------------------------------------- 1 | package matchers_test 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | . "github.com/onsi/ginkgo" 7 | . "github.com/onsi/gomega" 8 | . "github.com/onsi/gomega/matchers" 9 | ) 10 | 11 | type CustomError struct { 12 | } 13 | 14 | func (c CustomError) Error() string { 15 | return "an error" 16 | } 17 | 18 | var _ = Describe("MatchErrorMatcher", func() { 19 | Context("When asserting against an error", func() { 20 | It("should succeed when matching with an error", func() { 21 | err := errors.New("an error") 22 | fmtErr := fmt.Errorf("an error") 23 | customErr := CustomError{} 24 | 25 | Ω(err).Should(MatchError(errors.New("an error"))) 26 | Ω(err).ShouldNot(MatchError(errors.New("another error"))) 27 | 28 | Ω(fmtErr).Should(MatchError(errors.New("an error"))) 29 | Ω(customErr).Should(MatchError(CustomError{})) 30 | }) 31 | 32 | It("should succeed when matching with a string", func() { 33 | err := errors.New("an error") 34 | fmtErr := fmt.Errorf("an error") 35 | customErr := CustomError{} 36 | 37 | Ω(err).Should(MatchError("an error")) 38 | Ω(err).ShouldNot(MatchError("another error")) 39 | 40 | Ω(fmtErr).Should(MatchError("an error")) 41 | Ω(customErr).Should(MatchError("an error")) 42 | }) 43 | 44 | It("should fail when passed anything else", func() { 45 | actualErr := errors.New("an error") 46 | _, err := (&MatchErrorMatcher{ 47 | Expected: []byte("an error"), 48 | }).Match(actualErr) 49 | Ω(err).Should(HaveOccurred()) 50 | 51 | _, err = (&MatchErrorMatcher{ 52 | Expected: 3, 53 | }).Match(actualErr) 54 | Ω(err).Should(HaveOccurred()) 55 | }) 56 | }) 57 | 58 | Context("when passed nil", func() { 59 | It("should fail", func() { 60 | _, err := (&MatchErrorMatcher{ 61 | Expected: "an error", 62 | }).Match(nil) 63 | Ω(err).Should(HaveOccurred()) 64 | }) 65 | }) 66 | 67 | Context("when passed a non-error", func() { 68 | It("should fail", func() { 69 | _, err := (&MatchErrorMatcher{ 70 | Expected: "an error", 71 | }).Match("an error") 72 | Ω(err).Should(HaveOccurred()) 73 | 74 | _, err = (&MatchErrorMatcher{ 75 | Expected: "an error", 76 | }).Match(3) 77 | Ω(err).Should(HaveOccurred()) 78 | }) 79 | }) 80 | }) 81 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/match_json_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "fmt" 7 | "github.com/onsi/gomega/format" 8 | "reflect" 9 | ) 10 | 11 | type MatchJSONMatcher struct { 12 | JSONToMatch interface{} 13 | } 14 | 15 | func (matcher *MatchJSONMatcher) Match(actual interface{}) (success bool, err error) { 16 | actualString, expectedString, err := matcher.prettyPrint(actual) 17 | if err != nil { 18 | return false, err 19 | } 20 | 21 | var aval interface{} 22 | var eval interface{} 23 | 24 | // this is guarded by prettyPrint 25 | json.Unmarshal([]byte(actualString), &aval) 26 | json.Unmarshal([]byte(expectedString), &eval) 27 | 28 | return reflect.DeepEqual(aval, eval), nil 29 | } 30 | 31 | func (matcher *MatchJSONMatcher) FailureMessage(actual interface{}) (message string) { 32 | actualString, expectedString, _ := matcher.prettyPrint(actual) 33 | return format.Message(actualString, "to match JSON of", expectedString) 34 | } 35 | 36 | func (matcher *MatchJSONMatcher) NegatedFailureMessage(actual interface{}) (message string) { 37 | actualString, expectedString, _ := matcher.prettyPrint(actual) 38 | return format.Message(actualString, "not to match JSON of", expectedString) 39 | } 40 | 41 | func (matcher *MatchJSONMatcher) prettyPrint(actual interface{}) (actualFormatted, expectedFormatted string, err error) { 42 | actualString, aok := toString(actual) 43 | expectedString, eok := toString(matcher.JSONToMatch) 44 | 45 | if !(aok && eok) { 46 | return "", "", fmt.Errorf("MatchJSONMatcher matcher requires a string or stringer. Got:\n%s", format.Object(actual, 1)) 47 | } 48 | 49 | abuf := new(bytes.Buffer) 50 | ebuf := new(bytes.Buffer) 51 | 52 | if err := json.Indent(abuf, []byte(actualString), "", " "); err != nil { 53 | return "", "", err 54 | } 55 | 56 | if err := json.Indent(ebuf, []byte(expectedString), "", " "); err != nil { 57 | return "", "", err 58 | } 59 | 60 | return actualString, expectedString, nil 61 | } 62 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/match_json_matcher_test.go: -------------------------------------------------------------------------------- 1 | package matchers_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | . "github.com/onsi/gomega/matchers" 7 | ) 8 | 9 | var _ = Describe("MatchJSONMatcher", func() { 10 | Context("When passed stringifiables", func() { 11 | It("should succeed if the JSON matches", func() { 12 | Ω("{}").Should(MatchJSON("{}")) 13 | Ω(`{"a":1}`).Should(MatchJSON(`{"a":1}`)) 14 | Ω(`{ 15 | "a":1 16 | }`).Should(MatchJSON(`{"a":1}`)) 17 | Ω(`{"a":1, "b":2}`).Should(MatchJSON(`{"b":2, "a":1}`)) 18 | Ω(`{"a":1}`).ShouldNot(MatchJSON(`{"b":2, "a":1}`)) 19 | }) 20 | 21 | It("should work with byte arrays", func() { 22 | Ω([]byte("{}")).Should(MatchJSON([]byte("{}"))) 23 | Ω("{}").Should(MatchJSON([]byte("{}"))) 24 | Ω([]byte("{}")).Should(MatchJSON("{}")) 25 | }) 26 | }) 27 | 28 | Context("when either side is not valid JSON", func() { 29 | It("should error", func() { 30 | success, err := (&MatchJSONMatcher{JSONToMatch: `oops`}).Match(`{}`) 31 | Ω(success).Should(BeFalse()) 32 | Ω(err).Should(HaveOccurred()) 33 | 34 | success, err = (&MatchJSONMatcher{JSONToMatch: `{}`}).Match(`oops`) 35 | Ω(success).Should(BeFalse()) 36 | Ω(err).Should(HaveOccurred()) 37 | }) 38 | }) 39 | 40 | Context("when either side is neither a string nor a stringer", func() { 41 | It("should error", func() { 42 | success, err := (&MatchJSONMatcher{JSONToMatch: "{}"}).Match(2) 43 | Ω(success).Should(BeFalse()) 44 | Ω(err).Should(HaveOccurred()) 45 | 46 | success, err = (&MatchJSONMatcher{JSONToMatch: 2}).Match("{}") 47 | Ω(success).Should(BeFalse()) 48 | Ω(err).Should(HaveOccurred()) 49 | 50 | success, err = (&MatchJSONMatcher{JSONToMatch: nil}).Match("{}") 51 | Ω(success).Should(BeFalse()) 52 | Ω(err).Should(HaveOccurred()) 53 | 54 | success, err = (&MatchJSONMatcher{JSONToMatch: 2}).Match(nil) 55 | Ω(success).Should(BeFalse()) 56 | Ω(err).Should(HaveOccurred()) 57 | }) 58 | }) 59 | }) 60 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/match_regexp_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "fmt" 5 | "github.com/onsi/gomega/format" 6 | "regexp" 7 | ) 8 | 9 | type MatchRegexpMatcher struct { 10 | Regexp string 11 | Args []interface{} 12 | } 13 | 14 | func (matcher *MatchRegexpMatcher) Match(actual interface{}) (success bool, err error) { 15 | actualString, ok := toString(actual) 16 | if !ok { 17 | return false, fmt.Errorf("RegExp matcher requires a string or stringer.\nGot:%s", format.Object(actual, 1)) 18 | } 19 | 20 | match, err := regexp.Match(matcher.regexp(), []byte(actualString)) 21 | if err != nil { 22 | return false, fmt.Errorf("RegExp match failed to compile with error:\n\t%s", err.Error()) 23 | } 24 | 25 | return match, nil 26 | } 27 | 28 | func (matcher *MatchRegexpMatcher) FailureMessage(actual interface{}) (message string) { 29 | return format.Message(actual, "to match regular expression", matcher.regexp()) 30 | } 31 | 32 | func (matcher *MatchRegexpMatcher) NegatedFailureMessage(actual interface{}) (message string) { 33 | return format.Message(actual, "not to match regular expression", matcher.regexp()) 34 | } 35 | 36 | func (matcher *MatchRegexpMatcher) regexp() string { 37 | re := matcher.Regexp 38 | if len(matcher.Args) > 0 { 39 | re = fmt.Sprintf(matcher.Regexp, matcher.Args...) 40 | } 41 | return re 42 | } 43 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/match_regexp_matcher_test.go: -------------------------------------------------------------------------------- 1 | package matchers_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | . "github.com/onsi/gomega/matchers" 7 | ) 8 | 9 | var _ = Describe("MatchRegexp", func() { 10 | Context("when actual is a string", func() { 11 | It("should match against the string", func() { 12 | Ω(" a2!bla").Should(MatchRegexp(`\d!`)) 13 | Ω(" a2!bla").ShouldNot(MatchRegexp(`[A-Z]`)) 14 | }) 15 | }) 16 | 17 | Context("when actual is a stringer", func() { 18 | It("should call the stringer and match agains the returned string", func() { 19 | Ω(&myStringer{a: "Abc3"}).Should(MatchRegexp(`[A-Z][a-z]+\d`)) 20 | }) 21 | }) 22 | 23 | Context("when the matcher is called with multiple arguments", func() { 24 | It("should pass the string and arguments to sprintf", func() { 25 | Ω(" a23!bla").Should(MatchRegexp(`\d%d!`, 3)) 26 | }) 27 | }) 28 | 29 | Context("when actual is neither a string nor a stringer", func() { 30 | It("should error", func() { 31 | success, err := (&MatchRegexpMatcher{Regexp: `\d`}).Match(2) 32 | Ω(success).Should(BeFalse()) 33 | Ω(err).Should(HaveOccurred()) 34 | }) 35 | }) 36 | 37 | Context("when the passed in regexp fails to compile", func() { 38 | It("should error", func() { 39 | success, err := (&MatchRegexpMatcher{Regexp: "("}).Match("Foo") 40 | Ω(success).Should(BeFalse()) 41 | Ω(err).Should(HaveOccurred()) 42 | }) 43 | }) 44 | }) 45 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/matcher_tests_suite_test.go: -------------------------------------------------------------------------------- 1 | package matchers_test 2 | 3 | import ( 4 | "testing" 5 | . "github.com/onsi/ginkgo" 6 | . "github.com/onsi/gomega" 7 | ) 8 | 9 | type myStringer struct { 10 | a string 11 | } 12 | 13 | func (s *myStringer) String() string { 14 | return s.a 15 | } 16 | 17 | type StringAlias string 18 | 19 | type myCustomType struct { 20 | s string 21 | n int 22 | f float32 23 | arr []string 24 | } 25 | 26 | func Test(t *testing.T) { 27 | RegisterFailHandler(Fail) 28 | RunSpecs(t, "Gomega") 29 | } 30 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/panic_matcher.go: -------------------------------------------------------------------------------- 1 | package matchers 2 | 3 | import ( 4 | "fmt" 5 | "github.com/onsi/gomega/format" 6 | "reflect" 7 | ) 8 | 9 | type PanicMatcher struct{} 10 | 11 | func (matcher *PanicMatcher) Match(actual interface{}) (success bool, err error) { 12 | if actual == nil { 13 | return false, fmt.Errorf("PanicMatcher expects a non-nil actual.") 14 | } 15 | 16 | actualType := reflect.TypeOf(actual) 17 | if actualType.Kind() != reflect.Func { 18 | return false, fmt.Errorf("PanicMatcher expects a function. Got:\n%s", format.Object(actual, 1)) 19 | } 20 | if !(actualType.NumIn() == 0 && actualType.NumOut() == 0) { 21 | return false, fmt.Errorf("PanicMatcher expects a function with no arguments and no return value. Got:\n%s", format.Object(actual, 1)) 22 | } 23 | 24 | success = false 25 | defer func() { 26 | if e := recover(); e != nil { 27 | success = true 28 | } 29 | }() 30 | 31 | reflect.ValueOf(actual).Call([]reflect.Value{}) 32 | 33 | return 34 | } 35 | 36 | func (matcher *PanicMatcher) FailureMessage(actual interface{}) (message string) { 37 | return format.Message(actual, "to panic") 38 | } 39 | 40 | func (matcher *PanicMatcher) NegatedFailureMessage(actual interface{}) (message string) { 41 | return format.Message(actual, "not to panic") 42 | } 43 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/panic_matcher_test.go: -------------------------------------------------------------------------------- 1 | package matchers_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | . "github.com/onsi/gomega/matchers" 7 | ) 8 | 9 | var _ = Describe("Panic", func() { 10 | Context("when passed something that's not a function that takes zero arguments and returns nothing", func() { 11 | It("should error", func() { 12 | success, err := (&PanicMatcher{}).Match("foo") 13 | Ω(success).Should(BeFalse()) 14 | Ω(err).Should(HaveOccurred()) 15 | 16 | success, err = (&PanicMatcher{}).Match(nil) 17 | Ω(success).Should(BeFalse()) 18 | Ω(err).Should(HaveOccurred()) 19 | 20 | success, err = (&PanicMatcher{}).Match(func(foo string) {}) 21 | Ω(success).Should(BeFalse()) 22 | Ω(err).Should(HaveOccurred()) 23 | 24 | success, err = (&PanicMatcher{}).Match(func() string { return "bar" }) 25 | Ω(success).Should(BeFalse()) 26 | Ω(err).Should(HaveOccurred()) 27 | }) 28 | }) 29 | 30 | Context("when passed a function of the correct type", func() { 31 | It("should call the function and pass if the function panics", func() { 32 | Ω(func() { panic("ack!") }).Should(Panic()) 33 | Ω(func() {}).ShouldNot(Panic()) 34 | }) 35 | }) 36 | }) 37 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/support/goraph/MIT.LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Amit Kumar Gupta 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/support/goraph/bipartitegraph/bipartitegraph.go: -------------------------------------------------------------------------------- 1 | package bipartitegraph 2 | 3 | import "errors" 4 | import "fmt" 5 | 6 | import . "github.com/onsi/gomega/matchers/support/goraph/node" 7 | import . "github.com/onsi/gomega/matchers/support/goraph/edge" 8 | 9 | type BipartiteGraph struct { 10 | Left NodeOrderedSet 11 | Right NodeOrderedSet 12 | Edges EdgeSet 13 | } 14 | 15 | func NewBipartiteGraph(leftValues, rightValues []interface{}, neighbours func(interface{}, interface{}) (bool, error)) (*BipartiteGraph, error) { 16 | left := NodeOrderedSet{} 17 | for i, _ := range leftValues { 18 | left = append(left, Node{i}) 19 | } 20 | 21 | right := NodeOrderedSet{} 22 | for j, _ := range rightValues { 23 | right = append(right, Node{j + len(left)}) 24 | } 25 | 26 | edges := EdgeSet{} 27 | for i, leftValue := range leftValues { 28 | for j, rightValue := range rightValues { 29 | neighbours, err := neighbours(leftValue, rightValue) 30 | if err != nil { 31 | return nil, errors.New(fmt.Sprintf("error determining adjacency for %v and %v: %s", leftValue, rightValue, err.Error())) 32 | } 33 | 34 | if neighbours { 35 | edges = append(edges, Edge{left[i], right[j]}) 36 | } 37 | } 38 | } 39 | 40 | return &BipartiteGraph{left, right, edges}, nil 41 | } 42 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/support/goraph/edge/edge.go: -------------------------------------------------------------------------------- 1 | package edge 2 | 3 | import . "github.com/onsi/gomega/matchers/support/goraph/node" 4 | 5 | type Edge struct { 6 | Node1 Node 7 | Node2 Node 8 | } 9 | 10 | type EdgeSet []Edge 11 | 12 | func (ec EdgeSet) Free(node Node) bool { 13 | for _, e := range ec { 14 | if e.Node1 == node || e.Node2 == node { 15 | return false 16 | } 17 | } 18 | 19 | return true 20 | } 21 | 22 | func (ec EdgeSet) Contains(edge Edge) bool { 23 | for _, e := range ec { 24 | if e == edge { 25 | return true 26 | } 27 | } 28 | 29 | return false 30 | } 31 | 32 | func (ec EdgeSet) FindByNodes(node1, node2 Node) (Edge, bool) { 33 | for _, e := range ec { 34 | if (e.Node1 == node1 && e.Node2 == node2) || (e.Node1 == node2 && e.Node2 == node1) { 35 | return e, true 36 | } 37 | } 38 | 39 | return Edge{}, false 40 | } 41 | 42 | func (ec EdgeSet) SymmetricDifference(ec2 EdgeSet) EdgeSet { 43 | edgesToInclude := make(map[Edge]bool) 44 | 45 | for _, e := range ec { 46 | edgesToInclude[e] = true 47 | } 48 | 49 | for _, e := range ec2 { 50 | edgesToInclude[e] = !edgesToInclude[e] 51 | } 52 | 53 | result := EdgeSet{} 54 | for e, include := range edgesToInclude { 55 | if include { 56 | result = append(result, e) 57 | } 58 | } 59 | 60 | return result 61 | } 62 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/support/goraph/node/node.go: -------------------------------------------------------------------------------- 1 | package node 2 | 3 | type Node struct { 4 | Id int 5 | } 6 | 7 | type NodeOrderedSet []Node 8 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/matchers/support/goraph/util/util.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import "math" 4 | 5 | func Odd(n int) bool { 6 | return math.Mod(float64(n), 2.0) == 1.0 7 | } 8 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/onsi/gomega/types/types.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | type GomegaFailHandler func(message string, callerSkip ...int) 4 | 5 | //A simple *testing.T interface wrapper 6 | type GomegaTestingT interface { 7 | Errorf(format string, args ...interface{}) 8 | } 9 | 10 | //All Gomega matchers must implement the GomegaMatcher interface 11 | // 12 | //For details on writing custom matchers, check out: http://onsi.github.io/gomega/#adding_your_own_matchers 13 | type GomegaMatcher interface { 14 | Match(actual interface{}) (success bool, err error) 15 | FailureMessage(actual interface{}) (message string) 16 | NegatedFailureMessage(actual interface{}) (message string) 17 | } 18 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.swp 24 | *.swo 25 | *.DS_Store 26 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/Godeps/Godeps.json: -------------------------------------------------------------------------------- 1 | { 2 | "ImportPath": "github.com/xchapter7x/goutil", 3 | "GoVersion": "go1.3", 4 | "Packages": [ 5 | "./..." 6 | ], 7 | "Deps": [ 8 | { 9 | "ImportPath": "github.com/onsi/ginkgo", 10 | "Comment": "v1.1.0-20-g75d0cd9", 11 | "Rev": "75d0cd9c7ee52e99b13e6ccfd9e58b4f92b7795e" 12 | }, 13 | { 14 | "ImportPath": "github.com/onsi/gomega", 15 | "Comment": "v1.0-19-g835b5e4", 16 | "Rev": "835b5e4242c715976b98ed6bc6ece1d9c7879f66" 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/Godeps/Readme: -------------------------------------------------------------------------------- 1 | This directory tree is generated automatically by godep. 2 | 3 | Please do not edit. 4 | 5 | See https://github.com/tools/godep for more information. 6 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/README.md: -------------------------------------------------------------------------------- 1 | goutil -> itertools 2 | 3 | [![wercker status](https://app.wercker.com/status/092b6dbc492403c29b16676d5c5d5861/m/ "wercker status")](https://app.wercker.com/project/bykey/092b6dbc492403c29b16676d5c5d5861) 4 | ====== 5 | 6 | Iterate - function which turns all typically 7 | iterable objects into object accepted by the range function 8 | 9 | Range - function to create a generator 10 | similar to the xrange python function. 11 | 12 | Pair - a type, which is 13 | in line with the c++ Pair object 14 | 15 | Map - function which allows us to iterate over Slice, Array, chan and Map types 16 | and execute a function on each of the elements in those 17 | structures. 18 | 19 | CMap - version of the Map function 20 | which will loop and run the function concurrently 21 | using go routines. 22 | 23 | Filter - function which acts as a generator filtering the passed in iterable object of 24 | values which do equate to true according to the passed in 25 | evaluation function 26 | 27 | CFilter - concurrent version of Filter using go routines 28 | 29 | FilterFalse - function which acts as a generator filtering the passed in iterable object of 30 | values which do not equate to true according to the passed in evaluation function 31 | ( this function has the exact opposite effect as Filter ) 32 | 33 | CFilterFalse - concurrent cersion of FilterFalse using go routines 34 | 35 | ZipLongest - Make an iterator that aggregates elements from each of the iterables. If the iterables are of uneven length, missing values are filled-in with fillvalue. Iteration continues until the longest iterable is exhausted 36 | 37 | 38 | Zip - Make an iterator that aggregates elements from each of the iterables. If the iterables are of uneven length, indexes with missing values are dropped. 39 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/callchain.go: -------------------------------------------------------------------------------- 1 | package goutil 2 | 3 | import "reflect" 4 | 5 | func createReflectValueArgsArray(iargs []interface{}) (args []reflect.Value) { 6 | for _, arg := range iargs { 7 | args = append(args, reflect.ValueOf(arg)) 8 | } 9 | return 10 | } 11 | 12 | func createInterfaceArrayFromValuesArray(responseValuesArray []reflect.Value) (responseInterfaceArray []interface{}) { 13 | for _, ri := range responseValuesArray { 14 | responseInterfaceArray = append(responseInterfaceArray, ri.Interface()) 15 | } 16 | return 17 | } 18 | 19 | func findErrorValue(responseInterfaceArray []interface{}) (err error) { 20 | for _, res := range responseInterfaceArray { 21 | if e, ok := res.(error); ok { 22 | err = e 23 | } 24 | } 25 | return 26 | } 27 | 28 | func CallChain(preverr error, functor interface{}, iargs ...interface{}) (responseInterfaceArray []interface{}, err error) { 29 | if err = preverr; err == nil { 30 | args := createReflectValueArgsArray(iargs) 31 | responseValuesArray := reflect.ValueOf(functor).Call(args) 32 | responseInterfaceArray = createInterfaceArrayFromValuesArray(responseValuesArray) 33 | err = findErrorValue(responseInterfaceArray) 34 | } 35 | return 36 | } 37 | 38 | func CallChainP(preverr error, responseInterfaceArray []interface{}, functor interface{}, iargs ...interface{}) (err error) { 39 | res, err := CallChain(preverr, functor, iargs...) 40 | _, err = CallChain(err, UnpackArray, res, responseInterfaceArray) 41 | _, err = CallChain(err, findErrorValue, responseInterfaceArray) 42 | return 43 | } 44 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/goutil_suite_test.go: -------------------------------------------------------------------------------- 1 | package goutil_test 2 | 3 | import ( 4 | "testing" 5 | 6 | . "github.com/onsi/ginkgo" 7 | . "github.com/onsi/gomega" 8 | ) 9 | 10 | func TestApp(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "App Suite") 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/itertools/each.go: -------------------------------------------------------------------------------- 1 | package itertools 2 | 3 | import ( 4 | "reflect" 5 | "sync" 6 | ) 7 | 8 | func CEach(iter, f interface{}) { 9 | var wg sync.WaitGroup 10 | 11 | for p := range Iterate(iter) { 12 | wg.Add(1) 13 | 14 | go func(pp Pair) { 15 | defer wg.Done() 16 | args := []reflect.Value{reflect.ValueOf(pp.First), reflect.ValueOf(pp.Second)} 17 | reflect.ValueOf(f).Call(args) 18 | }(p) 19 | } 20 | wg.Wait() 21 | } 22 | 23 | func Each(iter, f interface{}) { 24 | for p := range Iterate(iter) { 25 | args := []reflect.Value{reflect.ValueOf(p.First), reflect.ValueOf(p.Second)} 26 | reflect.ValueOf(f).Call(args) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/itertools/each_test.go: -------------------------------------------------------------------------------- 1 | package itertools 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | var ( 8 | f_called_each int 9 | s_each []string 10 | m_each map[string]string 11 | ) 12 | 13 | func SetupEach() { 14 | f_called_each = 0 15 | s_each = []string{"asdf", "asdfasdf", "geeeg", "gggggggg"} 16 | m_each = map[string]string{"a": "asdf", "b": "asdfasdf", "c": "geeeg", "d": "gggggggg"} 17 | } 18 | 19 | func TearDownEach() { 20 | SetupEach() 21 | } 22 | 23 | func Test_EachSliceArray(t *testing.T) { 24 | SetupEach() 25 | defer TearDownEach() 26 | 27 | Each(s, func(i int, v string) string { 28 | f_called += 1 29 | return v 30 | }) 31 | 32 | if f_called != len(s) { 33 | t.Errorf("func f was not called %d times", len(s)) 34 | } 35 | } 36 | 37 | func Test_EachEach(t *testing.T) { 38 | SetupEach() 39 | defer TearDownEach() 40 | 41 | Each(m, func(i, v string) string { 42 | f_called += 1 43 | return v 44 | }) 45 | 46 | if f_called != len(m) { 47 | t.Errorf("func mf was not called %d times", len(m)) 48 | } 49 | } 50 | 51 | func Test_CEachSliceArray(t *testing.T) { 52 | SetupEach() 53 | defer TearDownEach() 54 | 55 | CEach(s, func(i int, v string) string { 56 | f_called += 1 57 | return v 58 | }) 59 | 60 | if f_called != len(s) { 61 | t.Errorf("func f was not called %d times", len(s)) 62 | } 63 | } 64 | 65 | func Test_CEachEach(t *testing.T) { 66 | SetupEach() 67 | defer TearDownEach() 68 | 69 | CEach(m, func(i, v string) string { 70 | f_called += 1 71 | return v 72 | }) 73 | 74 | if f_called != len(m) { 75 | t.Errorf("func mf was not called %d times", len(m)) 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/itertools/filter.go: -------------------------------------------------------------------------------- 1 | package itertools 2 | 3 | import ( 4 | "reflect" 5 | "sync" 6 | ) 7 | 8 | func Filter(iter interface{}, f func(first, second interface{}) bool) (out chan Pair) { 9 | out = filter(passThrough, iter, f) 10 | return 11 | } 12 | 13 | func CFilter(iter interface{}, f func(first, second interface{}) bool) (out chan Pair) { 14 | out = cFilter(passThrough, iter, f) 15 | return 16 | } 17 | 18 | func FilterFalse(iter interface{}, f func(first, second interface{}) bool) (out chan Pair) { 19 | out = filter(falsify, iter, f) 20 | return 21 | } 22 | 23 | func CFilterFalse(iter interface{}, f func(first, second interface{}) bool) (out chan Pair) { 24 | out = cFilter(falsify, iter, f) 25 | return 26 | } 27 | 28 | func falsify(in bool) bool { 29 | return !in 30 | } 31 | 32 | func passThrough(in bool) bool { 33 | return in 34 | } 35 | 36 | func pipeToFilterChannel(p Pair, out chan Pair, f interface{}, functor func(bool) bool) { 37 | args := []reflect.Value{reflect.ValueOf(p.First), reflect.ValueOf(p.Second)} 38 | 39 | if functor(reflect.ValueOf(f).Call(args)[0].Bool()) { 40 | out <- p 41 | } 42 | } 43 | 44 | func filter(functor func(bool) bool, iter interface{}, f func(first, second interface{}) bool) (out chan Pair) { 45 | var wg sync.WaitGroup 46 | out = make(chan Pair, GetIterBuffer()) 47 | wg.Add(1) 48 | 49 | go func() { 50 | defer close(out) 51 | defer wg.Done() 52 | 53 | for p := range Iterate(iter) { 54 | pipeToFilterChannel(p, out, f, functor) 55 | } 56 | }() 57 | wg.Wait() 58 | return 59 | } 60 | 61 | func cFilter(functor func(bool) bool, iter interface{}, f func(first, second interface{}) bool) (out chan Pair) { 62 | var wg1 sync.WaitGroup 63 | out = make(chan Pair, GetIterBuffer()) 64 | wg1.Add(1) 65 | 66 | go func() { 67 | defer close(out) 68 | defer wg1.Done() 69 | var wg2 sync.WaitGroup 70 | 71 | for p := range Iterate(iter) { 72 | wg2.Add(1) 73 | 74 | go func(pp Pair) { 75 | defer wg2.Done() 76 | pipeToFilterChannel(pp, out, f, functor) 77 | }(p) 78 | } 79 | wg2.Wait() 80 | }() 81 | wg1.Wait() 82 | return 83 | } 84 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/itertools/filter_test.go: -------------------------------------------------------------------------------- 1 | package itertools 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | var filterTestData []string 8 | var filterWhiteList []string 9 | 10 | func SetupFilter() { 11 | filterTestData = []string{"asdf", "asdfasdf", "geeeg", "gggggggg"} 12 | filterWhiteList = []string{"asdfasdf", "geeeg"} 13 | } 14 | 15 | func TearDownFilter() { 16 | filterTestData = []string{} 17 | filterWhiteList = []string{} 18 | } 19 | 20 | func Test_CFilter(t *testing.T) { 21 | SetupFilter() 22 | defer TearDownFilter() 23 | 24 | f := CFilter(filterTestData, func(i, v interface{}) bool { 25 | return findInStringArray(v.(string), filterWhiteList) 26 | }) 27 | 28 | for r := range f { 29 | 30 | if !findInStringArray(r.Second.(string), filterWhiteList) { 31 | t.Errorf("Error: %s should have been filtered, but it was not ", r) 32 | } 33 | } 34 | } 35 | 36 | func Test_Filter(t *testing.T) { 37 | SetupFilter() 38 | defer TearDownFilter() 39 | 40 | f := Filter(filterTestData, func(i, v interface{}) bool { 41 | return findInStringArray(v.(string), filterWhiteList) 42 | }) 43 | 44 | for r := range f { 45 | 46 | if !findInStringArray(r.Second.(string), filterWhiteList) { 47 | t.Errorf("Error: %s should have been filtered, but it was not ", r) 48 | } 49 | } 50 | } 51 | 52 | func Test_CFilterFalse(t *testing.T) { 53 | SetupFilter() 54 | defer TearDownFilter() 55 | 56 | f := CFilterFalse(filterTestData, func(i, v interface{}) bool { 57 | return findInStringArray(v.(string), filterWhiteList) 58 | }) 59 | 60 | for r := range f { 61 | 62 | if findInStringArray(r.Second.(string), filterWhiteList) { 63 | t.Errorf("Error: %s should have been filtered, but it was not ", r) 64 | } 65 | } 66 | } 67 | 68 | func Test_FilterFalse(t *testing.T) { 69 | SetupFilter() 70 | defer TearDownFilter() 71 | 72 | f := FilterFalse(filterTestData, func(i, v interface{}) bool { 73 | return findInStringArray(v.(string), filterWhiteList) 74 | }) 75 | 76 | for r := range f { 77 | 78 | if findInStringArray(r.Second.(string), filterWhiteList) { 79 | t.Errorf("Error: %s should have been filtered, but it was not ", r) 80 | } 81 | } 82 | } 83 | 84 | func findInStringArray(v string, a []string) (r bool) { 85 | r = false 86 | 87 | for _, i := range a { 88 | 89 | if v == i { 90 | r = true 91 | } 92 | } 93 | return 94 | } 95 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/itertools/iterConfig.go: -------------------------------------------------------------------------------- 1 | package itertools 2 | 3 | var ( 4 | iterBuffer int = 10 5 | ) 6 | 7 | func SetIterBuffer(buff int) { 8 | iterBuffer = buff 9 | } 10 | 11 | func GetIterBuffer() int { 12 | return iterBuffer 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/itertools/itertools_suite_test.go: -------------------------------------------------------------------------------- 1 | package itertools_test 2 | 3 | import ( 4 | "testing" 5 | 6 | . "github.com/onsi/ginkgo" 7 | . "github.com/onsi/gomega" 8 | ) 9 | 10 | func TestItertools(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "itertools Suite") 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/itertools/map.go: -------------------------------------------------------------------------------- 1 | package itertools 2 | 3 | import ( 4 | "reflect" 5 | "sync" 6 | ) 7 | 8 | func CMap(iter, f interface{}) (out chan Pair){ 9 | var wg sync.WaitGroup 10 | iterationCounter := 0 11 | out = make(chan Pair, GetIterBuffer()) 12 | defer close(out) 13 | 14 | for p := range Iterate(iter) { 15 | wg.Add(1) 16 | 17 | go func(pp Pair) { 18 | defer wg.Done() 19 | args := []reflect.Value{reflect.ValueOf(pp.First), reflect.ValueOf(pp.Second)} 20 | functorResponseValue := reflect.ValueOf(f).Call(args) 21 | out <- Pair{iterationCounter, functorResponseValue} 22 | iterationCounter+=1 23 | }(p) 24 | } 25 | wg.Wait() 26 | return 27 | } 28 | 29 | func Map(iter, f interface{}) (out chan Pair){ 30 | iterationCounter := 0 31 | out = make(chan Pair, GetIterBuffer()) 32 | defer close(out) 33 | 34 | for p := range Iterate(iter) { 35 | args := []reflect.Value{reflect.ValueOf(p.First), reflect.ValueOf(p.Second)} 36 | functorResponseValue := reflect.ValueOf(f).Call(args) 37 | out <- Pair{iterationCounter, functorResponseValue} 38 | iterationCounter+=1 39 | } 40 | return 41 | } 42 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/itertools/map_test.go: -------------------------------------------------------------------------------- 1 | package itertools 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | var ( 8 | f_called int 9 | s []string 10 | m map[string]string 11 | ) 12 | 13 | func Setup() { 14 | f_called = 0 15 | s = []string{"asdf", "asdfasdf", "geeeg", "gggggggg"} 16 | m = map[string]string{"a": "asdf", "b": "asdfasdf", "c": "geeeg", "d": "gggggggg"} 17 | } 18 | 19 | func TearDown() { 20 | Setup() 21 | } 22 | 23 | func Test_MapSliceArray(t *testing.T) { 24 | Setup() 25 | defer TearDown() 26 | 27 | rChan := Map(s, func(i int, v string) string { 28 | f_called += 1 29 | return v 30 | }) 31 | 32 | if f_called != len(s) { 33 | t.Errorf("func f was not called %d times", len(s)) 34 | } 35 | 36 | if len(rChan) != len(s) { 37 | t.Errorf("map response should be a channel with len of %d, it is %", len(s), len(rChan)) 38 | } 39 | } 40 | 41 | func Test_MapMap(t *testing.T) { 42 | Setup() 43 | defer TearDown() 44 | 45 | rChan := Map(m, func(i, v string) string { 46 | f_called += 1 47 | return v 48 | }) 49 | 50 | if f_called != len(m) { 51 | t.Errorf("func mf was not called %d times", len(m)) 52 | } 53 | 54 | if len(rChan) != len(s) { 55 | t.Errorf("map response should be a channel with len of %d, it is %", len(s), len(rChan)) 56 | } 57 | } 58 | 59 | func Test_CMapSliceArray(t *testing.T) { 60 | Setup() 61 | defer TearDown() 62 | 63 | rChan := CMap(s, func(i int, v string) string { 64 | f_called += 1 65 | return v 66 | }) 67 | 68 | if f_called != len(s) { 69 | t.Errorf("func f was not called %d times", len(s)) 70 | } 71 | 72 | if len(rChan) != len(s) { 73 | t.Errorf("map response should be a channel with len of %d, it is %", len(s), len(rChan)) 74 | } 75 | } 76 | 77 | func Test_CMapMap(t *testing.T) { 78 | Setup() 79 | defer TearDown() 80 | 81 | rChan := CMap(m, func(i, v string) string { 82 | f_called += 1 83 | return v 84 | }) 85 | 86 | if f_called != len(m) { 87 | t.Errorf("func mf was not called %d times", len(m)) 88 | } 89 | 90 | if len(rChan) != len(s) { 91 | t.Errorf("map response should be a channel with len of %d, it is %", len(s), len(rChan)) 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/itertools/pair.go: -------------------------------------------------------------------------------- 1 | package itertools 2 | 3 | import ( 4 | "reflect" 5 | ) 6 | 7 | type Pair struct { 8 | First interface{} 9 | Second interface{} 10 | } 11 | 12 | func unpack(pairVal, ptr interface{}) { 13 | ptrVal := reflect.ValueOf(ptr) 14 | ptrElem := ptrVal.Elem() 15 | ptrElem.Set(reflect.ValueOf(pairVal)) 16 | ptr = ptrElem.Interface() 17 | } 18 | 19 | func PairUnPack(pair Pair, first, second interface{}) { 20 | unpack(pair.First, first) 21 | unpack(pair.Second, second) 22 | } 23 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/itertools/pair_test.go: -------------------------------------------------------------------------------- 1 | package itertools 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | var ( 8 | firstPairTest int 9 | secondPairTest int 10 | controlFirst int 11 | controlSecond int 12 | controlPairTest Pair 13 | ) 14 | 15 | func SetupPair() { 16 | firstPairTest = 0 17 | secondPairTest = 0 18 | controlFirst = 5 19 | controlSecond = 2 20 | controlPairTest = Pair{controlFirst, controlSecond} 21 | } 22 | 23 | func TearDownPair() { 24 | SetupPair() 25 | } 26 | 27 | func Test_PairUnPack(t *testing.T) { 28 | SetupPair() 29 | defer TearDownPair() 30 | 31 | PairUnPack(controlPairTest, &firstPairTest, &secondPairTest) 32 | 33 | if firstPairTest != controlFirst { 34 | t.Errorf("%d should is not equal to %d", controlFirst, firstPairTest) 35 | } 36 | 37 | if secondPairTest != controlSecond { 38 | t.Errorf("%d should is not equal to %d", controlSecond, secondPairTest) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/itertools/range.go: -------------------------------------------------------------------------------- 1 | package itertools 2 | 3 | func Range(low, high int) (out chan int) { 4 | out = make(chan int, GetIterBuffer()) 5 | 6 | go func() { 7 | defer close(out) 8 | 9 | for i := low; i <= high; i++ { 10 | out <- i 11 | } 12 | }() 13 | return 14 | } 15 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/itertools/range_test.go: -------------------------------------------------------------------------------- 1 | package itertools 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | var ( 8 | controlRangeCount int 9 | ) 10 | 11 | func SetupRange() { 12 | controlRangeCount = 5 13 | } 14 | 15 | func TearDownRange() { 16 | SetupRange() 17 | } 18 | 19 | func Test_Range(t *testing.T) { 20 | SetupRange() 21 | defer TearDownRange() 22 | 23 | testCount := 0 24 | for i := range Range(1, controlRangeCount) { 25 | testCount++ 26 | 27 | if testCount != i { 28 | t.Errorf("Range returned %d but was expecting %d", i, testCount) 29 | } 30 | } 31 | 32 | if testCount != controlRangeCount { 33 | t.Errorf("Range was not called %d times. it was called %d", controlRangeCount, testCount) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/itertools/zip.go: -------------------------------------------------------------------------------- 1 | package itertools 2 | 3 | func ZipLongest(fillValue string, args ...interface{}) (out chan []interface{}) { 4 | out = make(chan []interface{}, GetIterBuffer()) 5 | 6 | go func() { 7 | defer close(out) 8 | var argsSlice [][]interface{} 9 | maxSliceLength := 0 10 | 11 | for _, arg := range args { 12 | var argSlice []interface{} 13 | 14 | for p := range Iterate(arg) { 15 | 16 | if currentIndexGreaterThanMaxLength(p, maxSliceLength) { 17 | maxSliceLength++ 18 | } 19 | argSlice = append(argSlice, p.Second) 20 | } 21 | argsSlice = append(argsSlice, argSlice) 22 | } 23 | 24 | for i := 0; i < maxSliceLength; i++ { 25 | var row []interface{} 26 | 27 | for _, a := range argsSlice { 28 | 29 | if balancedSliceLength(a, i) { 30 | row = append(row, a[i]) 31 | 32 | } else { 33 | row = append(row, fillValue) 34 | } 35 | } 36 | out <- row 37 | } 38 | }() 39 | return 40 | } 41 | 42 | func Zip(fillValue string, args ...interface{}) (out chan []interface{}) { 43 | out = make(chan []interface{}, GetIterBuffer()) 44 | 45 | go func() { 46 | defer close(out) 47 | var argsSlice [][]interface{} 48 | maxSliceLength := 0 49 | 50 | for _, arg := range args { 51 | var argSlice []interface{} 52 | 53 | for p := range Iterate(arg) { 54 | 55 | if currentIndexGreaterThanMaxLength(p, maxSliceLength) { 56 | maxSliceLength++ 57 | } 58 | argSlice = append(argSlice, p.Second) 59 | } 60 | argsSlice = append(argsSlice, argSlice) 61 | } 62 | 63 | for i := 0; i < maxSliceLength; i++ { 64 | var row []interface{} 65 | unevenSlices := false 66 | 67 | for _, a := range argsSlice { 68 | 69 | if balancedSliceLength(a, i) { 70 | row = append(row, a[i]) 71 | 72 | } else { 73 | unevenSlices = true 74 | break 75 | } 76 | } 77 | 78 | if unevenSlices { 79 | break 80 | } else { 81 | out <- row 82 | } 83 | } 84 | }() 85 | return 86 | } 87 | 88 | func balancedSliceLength(a []interface{}, i int) bool { 89 | return len(a)-1 >= i 90 | } 91 | 92 | func currentIndexGreaterThanMaxLength(p Pair, maxSliceLength int) bool { 93 | return (p.First.(int) + 1) > maxSliceLength 94 | } 95 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/itertools/zip_test.go: -------------------------------------------------------------------------------- 1 | package itertools 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | var ( 8 | controlFill string 9 | controlSample1 string 10 | controlSample2 string 11 | controlSample3 string 12 | controlZipped [][]string 13 | ) 14 | 15 | func SetupZip() { 16 | controlFill = "-" 17 | controlSample1 = "abcdefghijk" 18 | controlSample2 = "ABCde" 19 | controlSample3 = "aBCDefg" 20 | controlZipped = [][]string{ 21 | []string{"a", "A", "a"}, 22 | []string{"b", "B", "B"}, 23 | []string{"c", "C", "C"}, 24 | []string{"d", "d", "D"}, 25 | []string{"e", "e", "e"}, 26 | []string{"f", "-", "f"}, 27 | []string{"g", "-", "g"}, 28 | []string{"h", "-", "-"}, 29 | []string{"i", "-", "-"}, 30 | []string{"j", "-", "-"}, 31 | []string{"k", "-", "-"}} 32 | } 33 | 34 | func TearDownZip() { 35 | controlFill = "" 36 | controlSample1 = "" 37 | controlSample2 = "" 38 | controlSample3 = "" 39 | } 40 | 41 | func Test_ZipLogest(t *testing.T) { 42 | SetupZip() 43 | defer TearDownZip() 44 | count := 0 45 | 46 | for z := range ZipLongest(controlFill, controlSample1, controlSample2, controlSample3) { 47 | 48 | for i := range controlZipped[count] { 49 | 50 | if controlZipped[count][i] != z[i].(string) { 51 | t.Errorf("Error: %s should match the control zipped dataset string w/ %s ", z[i].(string), controlZipped[count][i]) 52 | } 53 | } 54 | count++ 55 | } 56 | 57 | if count != len(controlSample1) { 58 | t.Errorf("Error: %d should match the longest dataset w/ %d ", count, len(controlSample1)) 59 | } 60 | } 61 | 62 | func Test_Zip(t *testing.T) { 63 | SetupZip() 64 | defer TearDownZip() 65 | count := 0 66 | 67 | for z := range Zip(controlFill, controlSample1, controlSample2, controlSample3) { 68 | 69 | for i := range controlZipped[count] { 70 | 71 | if controlZipped[count][i] != z[i].(string) { 72 | t.Errorf("Error: %s should match the control zipped dataset string w/ %s ", z[i].(string), controlZipped[count][i]) 73 | } 74 | } 75 | count++ 76 | } 77 | 78 | if count != len(controlSample2) { 79 | t.Errorf("Error: %d should match the shortest dataset w/ %d ", count, len(controlSample1)) 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/samples/example.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "container/list" 5 | "container/ring" 6 | "fmt" 7 | "github.com/xchapter7x/goutil/itertools" 8 | ) 9 | 10 | func f(i int, v string) string { 11 | fmt.Println(i, v) 12 | return v 13 | } 14 | 15 | func mf(i, v string) string { 16 | fmt.Println(i, v) 17 | return v 18 | } 19 | 20 | func t(i interface{}) { 21 | for x := range itertools.Iterate(i) { 22 | fmt.Println(x) 23 | } 24 | } 25 | 26 | func main() { 27 | s := []string{"asdf", "asdfasdf", "geeeg", "gggggggg"} 28 | m := map[string]string{"a": "asdf", "b": "asdfasdf", "c": "geeeg", "d": "gggggggg"} 29 | itertools.Each(&s, f) 30 | itertools.Each(&m, mf) 31 | fmt.Println("\n\nbegin concurrent map\n\n") 32 | itertools.CEach(s, f) 33 | itertools.CEach(m, mf) 34 | 35 | fmt.Println("\n\nFilter Sample\n\n") 36 | 37 | f := itertools.Filter(s, func(i, v interface{}) bool { 38 | il := map[int]int{1: 1, 2: 2} 39 | _, ok := il[i.(int)] 40 | return ok 41 | }) 42 | 43 | for i := range f { 44 | fmt.Println(i) 45 | } 46 | 47 | fmt.Println("\n\nConcurrent Filter Sample\n\n") 48 | 49 | fC := itertools.CFilter(s, func(i, v interface{}) bool { 50 | il := map[int]int{1: 1, 2: 2} 51 | _, ok := il[i.(int)] 52 | return ok 53 | }) 54 | 55 | for i := range fC { 56 | fmt.Println(i) 57 | } 58 | 59 | fmt.Println("\n\nlets iterate a string") 60 | 61 | t("this is a test") 62 | 63 | fmt.Println("\n\nlets iterate a list") 64 | 65 | l := list.New() 66 | l.PushFront(1) 67 | l.PushFront(2) 68 | l.PushFront(3) 69 | l.PushFront(4) 70 | l.PushFront(5) 71 | l.PushFront(6) 72 | t(l) 73 | 74 | fmt.Println("\n\nlets iterate a ring") 75 | 76 | r := ring.New(10) 77 | z := 100 78 | r.Value = z 79 | for p := r.Next(); p != r; p = p.Next() { 80 | z -= 10 81 | p.Value = z 82 | } 83 | t(r) 84 | 85 | fmt.Println("test the ziplong") 86 | for z := range itertools.ZipLongest("-", "abcdefghijk", "ABCde", "aBCDefg") { 87 | fmt.Println(z) 88 | } 89 | 90 | fmt.Println("test the zip") 91 | for z := range itertools.Zip("-", "abcdefghijk", "ABCde", "aBCDefg") { 92 | fmt.Println(z) 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/testCoverage: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | EXITCODE=0; 3 | WATERMARK=$2; 4 | COVEROUTPUT=`godep go test -cover $1`; 5 | echo ${COVEROUTPUT}; 6 | 7 | COVERLEVELS=`echo ${COVEROUTPUT} | grep -oh "[0-9]\{1,3\}\.[0-9]\{1,3\}\%"` 8 | for COVERLEVEL in ${COVERLEVELS};do 9 | echo ${COVERLEVEL} | tr "%" " "; 10 | COVERLEVEL=${COVERLEVEL/.*}; 11 | echo "Coverage - ${COVERLEVEL}%"; 12 | echo "Watermark- ${WATERMARK}%"; 13 | if (( $COVERLEVEL < $WATERMARK )); then echo "failed"; (exit 1); fi 14 | done 15 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/unpack.go: -------------------------------------------------------------------------------- 1 | package goutil 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | ) 7 | 8 | func Unpack(packedValues []interface{}, unpackedPointers ...interface{}) (err error) { 9 | return UnpackArray(packedValues, unpackedPointers) 10 | } 11 | 12 | func UnpackArray(packedValues []interface{}, unpackedPointers []interface{}) (err error) { 13 | packedValuesLen := len(packedValues) 14 | unpackedPointersLen := len(unpackedPointers) 15 | 16 | if packedValuesLen == unpackedPointersLen { 17 | err = mapPackedValuesToUnpackedPointers(packedValues, unpackedPointers) 18 | 19 | } else { 20 | err = fmt.Errorf("Incorrect argument count: pointers dont match response element count %s != %s", packedValuesLen, unpackedPointersLen) 21 | } 22 | return 23 | } 24 | 25 | func mapPackedValuesToUnpackedPointers(packedValues []interface{}, unpackedPointers []interface{}) (err error) { 26 | for i, packedValue := range packedValues { 27 | ptrVal := reflect.ValueOf((unpackedPointers)[i]) 28 | ptrElem := ptrVal.Elem() 29 | ptrElemKind := ptrElem.Kind() 30 | packedValueReflectValue := reflect.ValueOf(packedValue) 31 | packedValueReflectValueKind := packedValueReflectValue.Kind() 32 | 33 | if ptrElemKind == packedValueReflectValueKind { 34 | ptrElem.Set(packedValueReflectValue) 35 | (unpackedPointers)[i] = ptrElem.Interface() 36 | 37 | } else if packedValueReflectValue.IsValid() { 38 | err = fmt.Errorf("Incorrect pointer type %s != %s", ptrElemKind, packedValueReflectValueKind) 39 | 40 | } 41 | } 42 | return 43 | } 44 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/unpack_test.go: -------------------------------------------------------------------------------- 1 | package goutil_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | . "github.com/xchapter7x/goutil" 7 | ) 8 | 9 | var _ = Describe("unpack package", func() { 10 | controlANew := "hi" 11 | controlAOld := "good" 12 | controlBNew := "there" 13 | controlBOld := "bye" 14 | 15 | Describe("unpack args function", func() { 16 | It("Should assign the value in the array to the associated pointer given", func() { 17 | internalA := controlAOld 18 | internalB := controlBOld 19 | arr := []interface{}{controlANew, controlBNew} 20 | err := Unpack(arr, &internalA, &internalB) 21 | Ω(err).Should(BeNil()) 22 | Expect(internalA).NotTo(Equal(controlAOld)) 23 | Expect(internalA).To(Equal(controlANew)) 24 | Expect(internalB).NotTo(Equal(controlBOld)) 25 | Expect(internalB).To(Equal(controlBNew)) 26 | }) 27 | 28 | It("Should return error if there the argument lengths dont match", func() { 29 | internalA := controlAOld 30 | arr := []interface{}{controlANew, controlBNew} 31 | err := Unpack(arr, &internalA) 32 | Ω(err).ShouldNot(BeNil()) 33 | }) 34 | 35 | It("Should return error if there the arguments of non matching types", func() { 36 | internalA := []string{"hi there"} 37 | arr := []interface{}{controlANew} 38 | err := Unpack(arr, &internalA) 39 | Ω(err).ShouldNot(BeNil()) 40 | }) 41 | 42 | It("Should not panic if called with incorrect arg count", func() { 43 | internalA := controlAOld 44 | arr := []interface{}{controlANew, controlBNew} 45 | Ω(func() { Unpack(arr, &internalA) }).ShouldNot(Panic()) 46 | }) 47 | 48 | It("Should not panic if called with invalid arg types", func() { 49 | internalA := []string{"hi there"} 50 | arr := []interface{}{controlANew} 51 | Ω(func() { Unpack(arr, &internalA) }).ShouldNot(Panic()) 52 | }) 53 | 54 | }) 55 | }) 56 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/xchapter7x/goutil/wercker.yml: -------------------------------------------------------------------------------- 1 | box: wercker/golang 2 | build: 3 | # The steps that will be executed on build 4 | steps: 5 | # Sets the go workspace and places you package 6 | # at the right place in the workspace tree 7 | - setup-go-workspace 8 | 9 | # Gets the dependencies 10 | - script: 11 | name: go get 12 | code: | 13 | cd $WERCKER_SOURCE_DIR 14 | go version 15 | go get github.com/tools/godep 16 | 17 | # Test the project 18 | - script: 19 | name: go test 20 | code: | 21 | godep go test ./itertools 22 | godep go test ./unpack 23 | 24 | # Test coverage for the project 25 | - script: 26 | name: go test cover 27 | code: | 28 | ./testCoverage ./itertools 90 29 | ./testCoverage ./unpack 90 30 | -------------------------------------------------------------------------------- /coverage: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Generate test coverage statistics for Go packages. 3 | # 4 | # Works around the fact that `go test -coverprofile` currently does not work 5 | # with multiple packages, see https://code.google.com/p/go/issues/detail?id=6909 6 | # 7 | # Usage: script/coverage [--html|--coveralls] 8 | # 9 | # --html Additionally create HTML report and open it in browser 10 | # --coveralls Push coverage statistics to coveralls.io 11 | # 12 | 13 | set -e 14 | 15 | workdir=.cover 16 | profile="$workdir/cover.out" 17 | mode=count 18 | 19 | generate_cover_data() { 20 | rm -rf "$workdir" 21 | mkdir "$workdir" 22 | 23 | for pkg in "$@"; do 24 | f="$workdir/$(echo $pkg | tr / -).cover" 25 | godep go test -covermode="$mode" -coverprofile="$f" "$pkg" 26 | done 27 | 28 | echo "mode: $mode" >"$profile" 29 | grep -h -v "^mode:" "$workdir"/*.cover >>"$profile" 30 | } 31 | 32 | show_cover_report() { 33 | godep go tool cover -${1}="$profile" 34 | } 35 | 36 | push_to_coveralls() { 37 | echo "Pushing coverage statistics to coveralls.io" 38 | goveralls -coverprofile="$profile" --service="wercker" -repotoken $COVERALLS_TOKEN 39 | } 40 | 41 | generate_cover_data $(go list ./...) 42 | show_cover_report func 43 | case "$1" in 44 | "") 45 | ;; 46 | --html) 47 | show_cover_report html ;; 48 | --coveralls) 49 | push_to_coveralls ;; 50 | *) 51 | echo >&2 "error: invalid option: $1"; exit 1 ;; 52 | esac 53 | -------------------------------------------------------------------------------- /engines/localengine/local_engine.go: -------------------------------------------------------------------------------- 1 | package localengine 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/xchapter7x/toggle/engines/storageinterface" 8 | ) 9 | 10 | func NewLocalEngine() (engine storageinterface.StorageEngine) { 11 | engine = &LocalEngine{ 12 | Getenv: os.Getenv, 13 | } 14 | return 15 | } 16 | 17 | type LocalEngine struct { 18 | Getenv func(string) string 19 | } 20 | 21 | func (s *LocalEngine) GetFeatureStatusValue(featureSignature string) (status string, err error) { 22 | status = s.Getenv(featureSignature) 23 | 24 | if status == "" { 25 | err = fmt.Errorf("toggle value not set") 26 | } 27 | return 28 | } 29 | 30 | func (s *LocalEngine) Close() (err error) { 31 | return 32 | } 33 | -------------------------------------------------------------------------------- /engines/localengine/local_engine_suite_test.go: -------------------------------------------------------------------------------- 1 | package localengine_test 2 | 3 | import ( 4 | "testing" 5 | 6 | . "github.com/onsi/ginkgo" 7 | . "github.com/onsi/gomega" 8 | ) 9 | 10 | func TestApp(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "App Suite") 13 | } 14 | -------------------------------------------------------------------------------- /engines/localengine/local_engine_test.go: -------------------------------------------------------------------------------- 1 | package localengine_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | "github.com/xchapter7x/toggle/engines/localengine" 7 | ) 8 | 9 | var controlSuccessStatus string = "true" 10 | 11 | func successGetenvMock(fs string) (status string) { 12 | status = controlSuccessStatus 13 | return 14 | } 15 | 16 | func failureGetenvMock(fs string) (status string) { 17 | status = "" 18 | return 19 | } 20 | 21 | var _ = Describe("localengine package", func() { 22 | Describe("LocalEngine struct", func() { 23 | Describe("GetFeatureStatusValue function", func() { 24 | It("Should return the result of getenv and have nil error on success", func() { 25 | engine := &localengine.LocalEngine{ 26 | Getenv: successGetenvMock, 27 | } 28 | res, err := engine.GetFeatureStatusValue("") 29 | Expect(res).To(Equal(controlSuccessStatus)) 30 | Ω(err).Should(BeNil()) 31 | }) 32 | 33 | It("Should return non nil err on failed call", func() { 34 | engine := &localengine.LocalEngine{ 35 | Getenv: failureGetenvMock, 36 | } 37 | _, err := engine.GetFeatureStatusValue("") 38 | Ω(err).ShouldNot(BeNil()) 39 | }) 40 | }) 41 | }) 42 | }) 43 | -------------------------------------------------------------------------------- /engines/localpubsub/local_pubsub_engine.go: -------------------------------------------------------------------------------- 1 | package localpubsub 2 | 3 | import ( 4 | "os" 5 | 6 | "github.com/xchapter7x/toggle" 7 | "github.com/xchapter7x/toggle/engines/localengine" 8 | "github.com/xchapter7x/toggle/engines/storageinterface" 9 | ) 10 | 11 | func NewLocalPubSubEngine(pubsub pubsubInterface, toggleList map[string]*toggle.Feature) storageinterface.StorageEngine { 12 | le := &localengine.LocalEngine{ 13 | Getenv: os.Getenv, 14 | } 15 | engine := &LocalPubSubEngine{ 16 | LocalEngine: le, 17 | PubSub: pubsub, 18 | } 19 | engine.StartSubscriptionListener(toggleList) 20 | return engine 21 | } 22 | 23 | type LocalPubSubEngine struct { 24 | LocalEngine *localengine.LocalEngine 25 | PubSub pubsubInterface 26 | quit chan bool 27 | } 28 | 29 | func (s *LocalPubSubEngine) Close() (err error) { 30 | s.PubSub.Unsubscribe() 31 | s.quit <- true 32 | return 33 | } 34 | 35 | func (s *LocalPubSubEngine) StartSubscriptionListener(toggleList map[string]*toggle.Feature) { 36 | if s.quit == nil { 37 | s.quit = make(chan bool) 38 | 39 | go func() { 40 | for { 41 | select { 42 | case <-s.quit: 43 | return 44 | 45 | default: 46 | PubSubReceiver(s.PubSub, toggleList) 47 | } 48 | } 49 | }() 50 | } 51 | } 52 | 53 | func (s *LocalPubSubEngine) GetFeatureStatusValue(featureSignature string) (status string, err error) { 54 | s.PubSub.Subscribe(featureSignature) 55 | status, err = s.LocalEngine.GetFeatureStatusValue(featureSignature) 56 | return 57 | } 58 | -------------------------------------------------------------------------------- /engines/localpubsub/local_pubsub_engine_suite_test.go: -------------------------------------------------------------------------------- 1 | package localpubsub_test 2 | 3 | import ( 4 | "testing" 5 | 6 | . "github.com/onsi/ginkgo" 7 | . "github.com/onsi/gomega" 8 | ) 9 | 10 | func TestApp(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "App Suite") 13 | } 14 | -------------------------------------------------------------------------------- /engines/localpubsub/pubsub_interface.go: -------------------------------------------------------------------------------- 1 | package localpubsub 2 | 3 | type pubsubInterface interface { 4 | Close() error 5 | Subscribe(channel ...interface{}) error 6 | PSubscribe(channel ...interface{}) error 7 | Unsubscribe(channel ...interface{}) error 8 | PUnsubscribe(channel ...interface{}) error 9 | Receive() interface{} 10 | } 11 | -------------------------------------------------------------------------------- /engines/localpubsub/pubsub_receiver.go: -------------------------------------------------------------------------------- 1 | package localpubsub 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/garyburd/redigo/redis" 7 | "github.com/xchapter7x/toggle" 8 | ) 9 | 10 | type ReceiverInterface interface { 11 | Receive() interface{} 12 | } 13 | 14 | type PSReceiver func(s ReceiverInterface, toggleList map[string]*toggle.Feature) 15 | 16 | var PubSubReceiver PSReceiver = func(s ReceiverInterface, toggleList map[string]*toggle.Feature) { 17 | switch n := s.Receive().(type) { 18 | case redis.Message: 19 | toggleList[n.Channel].UpdateStatus(string(n.Data[:])) 20 | 21 | case error: 22 | fmt.Printf("error: %v\n", n) 23 | return 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /engines/localpubsub/pubsub_receiver_test.go: -------------------------------------------------------------------------------- 1 | package localpubsub_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | 7 | "github.com/garyburd/redigo/redis" 8 | "github.com/xchapter7x/toggle" 9 | "github.com/xchapter7x/toggle/engines/localpubsub" 10 | ) 11 | 12 | type PubSubErrorMock struct { 13 | Channel string 14 | Data []byte 15 | } 16 | 17 | func (s *PubSubErrorMock) Receive() (rMsg interface{}) { 18 | rMsg = "failure not a redis message" 19 | return 20 | } 21 | 22 | type PubSubMock struct { 23 | Channel string 24 | Data []byte 25 | } 26 | 27 | func (s *PubSubMock) Receive() (rMsg interface{}) { 28 | rMsg = redis.Message{ 29 | Channel: s.Channel, 30 | Data: s.Data, 31 | } 32 | return 33 | } 34 | 35 | var _ = Describe("localpubsub package", func() { 36 | Describe("PubSubReceiver function", func() { 37 | channel := "test" 38 | data := []byte("string") 39 | var psMock *PubSubMock 40 | var psErrorMock *PubSubErrorMock 41 | 42 | BeforeEach(func() { 43 | psMock = &PubSubMock{ 44 | Channel: channel, 45 | Data: data, 46 | } 47 | psErrorMock = &PubSubErrorMock{ 48 | Channel: channel, 49 | Data: data, 50 | } 51 | 52 | }) 53 | 54 | AfterEach(func() { 55 | psMock = nil 56 | psErrorMock = nil 57 | }) 58 | 59 | It("Should update the status of the proper feature object", func() { 60 | controlStatus := "controlString" 61 | togglelist := make(map[string]*toggle.Feature) 62 | togglelist[channel] = &toggle.Feature{ 63 | Status: controlStatus, 64 | } 65 | localpubsub.PubSubReceiver(psMock, togglelist) 66 | Expect(togglelist[channel].Status).NotTo(Equal(controlStatus)) 67 | Expect(togglelist[channel].Status).To(Equal(string(data[:]))) 68 | }) 69 | 70 | It("Should on error leave existing values in place", func() { 71 | controlStatus := "controlString" 72 | togglelist := make(map[string]*toggle.Feature) 73 | togglelist[channel] = &toggle.Feature{ 74 | Status: controlStatus, 75 | } 76 | localpubsub.PubSubReceiver(psErrorMock, togglelist) 77 | Expect(togglelist[channel].Status).To(Equal(controlStatus)) 78 | }) 79 | }) 80 | }) 81 | -------------------------------------------------------------------------------- /engines/storageinterface/storage_engine_interface.go: -------------------------------------------------------------------------------- 1 | package storageinterface 2 | 3 | type StorageEngine interface { 4 | GetFeatureStatusValue(featureSignature string) (status string, err error) 5 | Close() (err error) 6 | } 7 | -------------------------------------------------------------------------------- /flipper.go: -------------------------------------------------------------------------------- 1 | package toggle 2 | 3 | import "github.com/xchapter7x/goutil" 4 | 5 | func NewTgl() *Tgl { 6 | return new(Tgl) 7 | } 8 | 9 | type Tgl struct { 10 | flagName string 11 | onFeature interface{} 12 | offFeature interface{} 13 | args []interface{} 14 | returnValues []interface{} 15 | } 16 | 17 | func (s *Tgl) Flag(name string) *Tgl { 18 | s.flagName = name 19 | return s 20 | } 21 | 22 | func (s *Tgl) Off(feature interface{}) *Tgl { 23 | s.offFeature = feature 24 | return s 25 | } 26 | 27 | func (s *Tgl) On(feature interface{}) *Tgl { 28 | s.onFeature = feature 29 | return s 30 | } 31 | 32 | func (s *Tgl) Args(args ...interface{}) *Tgl { 33 | s.args = args 34 | return s 35 | } 36 | 37 | func (s *Tgl) Returns(vals ...interface{}) *Tgl { 38 | s.returnValues = vals 39 | return s 40 | } 41 | 42 | func (s *Tgl) Run() (res []interface{}, err error) { 43 | res = Flip(s.flagName, 44 | s.offFeature, 45 | s.onFeature, 46 | s.args...) 47 | err = goutil.UnpackArray(res, s.returnValues) 48 | return 49 | } 50 | -------------------------------------------------------------------------------- /flipper_test.go: -------------------------------------------------------------------------------- 1 | package toggle_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | . "github.com/xchapter7x/toggle" 7 | ) 8 | 9 | func randomA(a, b int) int { 10 | return a * b 11 | } 12 | func randomB(a, b int) int { 13 | return a + b 14 | } 15 | 16 | var _ = Describe("Tgl", func() { 17 | Context("calling the full chain", func() { 18 | var ( 19 | tgl *Tgl 20 | control int 21 | argA int 22 | argB int 23 | rval int 24 | ) 25 | 26 | BeforeEach(func() { 27 | tgl = NewTgl() 28 | control = 0 29 | argA = 5 30 | argB = 2 31 | rval = control 32 | 33 | Ω(func() { 34 | _, err := tgl.Flag("randomFeature"). 35 | On(randomA). 36 | Off(randomB). 37 | Args(argA, argB). 38 | Returns(&rval). 39 | Run() 40 | Ω(err).Should(BeNil()) 41 | }).ShouldNot(Panic()) 42 | }) 43 | 44 | It("should return the proper value to the return variable pointer given", func() { 45 | controlRes := randomB(argA, argB) 46 | Ω(rval).ShouldNot(Equal(control)) 47 | Ω(rval).Should(Equal(controlRes)) 48 | }) 49 | }) 50 | }) 51 | -------------------------------------------------------------------------------- /sample/local/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/xchapter7x/goutil" 7 | "github.com/xchapter7x/toggle" 8 | "github.com/xchapter7x/toggle/engines/localengine" 9 | ) 10 | 11 | func TestA(s string) (r string) { 12 | r = fmt.Sprintln("testa", s) 13 | fmt.Println(r) 14 | return 15 | } 16 | 17 | func TestB(s string) (r string) { 18 | r = fmt.Sprintln("testb", s) 19 | fmt.Println(r) 20 | return 21 | } 22 | 23 | func main() { 24 | toggle.Init("NS", localengine.NewLocalEngine()) 25 | toggle.RegisterFeature("test") 26 | f := toggle.Flip("test", TestA, TestB, "argstring") 27 | var output string 28 | goutil.Unpack(f, &output) 29 | fmt.Println(output) 30 | 31 | } 32 | -------------------------------------------------------------------------------- /sample/localpubsub/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | "github.com/garyburd/redigo/redis" 8 | "github.com/xchapter7x/goutil" 9 | "github.com/xchapter7x/toggle" 10 | "github.com/xchapter7x/toggle/engines/localpubsub" 11 | ) 12 | 13 | func TestA(s string) (r string) { 14 | r = fmt.Sprintln("testa", s) 15 | fmt.Println(r) 16 | return 17 | } 18 | 19 | func TestB(s string) (r string) { 20 | r = fmt.Sprintln("testb", s) 21 | fmt.Println(r) 22 | return 23 | } 24 | 25 | func main() { 26 | c, _ := redis.Dial("tcp", "localhost:6379") 27 | defer c.Close() 28 | c2, _ := redis.Dial("tcp", "localhost:6379") 29 | defer c2.Close() 30 | 31 | psc := redis.PubSubConn{Conn: c} 32 | lps := localpubsub.NewLocalPubSubEngine(psc, toggle.ShowFeatures()) 33 | defer lps.Close() 34 | 35 | toggle.Init("NS", lps) 36 | toggle.RegisterFeature("test") 37 | f := toggle.Flip("test", TestA, TestB, "argstring") 38 | var output string 39 | goutil.Unpack(f, &output) 40 | fmt.Println(output) 41 | fmt.Println("publish state change") 42 | c2.Do("PUBLISH", "NS_test", "true") 43 | time.Sleep(1000 * time.Millisecond) 44 | f = toggle.Flip("test", TestA, TestB, "argstring") 45 | goutil.Unpack(f, &output) 46 | fmt.Println(output) 47 | } 48 | -------------------------------------------------------------------------------- /testCoverage: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | EXITCODE=0; 4 | WATERMARK=$2; 5 | TESTDIR=$1 6 | godep go test -cover ${TESTDIR} | { 7 | while read -r COVEROUTPUT;do 8 | echo ${COVEROUTPUT}; 9 | 10 | COVERLEVELS=`echo ${COVEROUTPUT} | grep -oh "[0-9]\{1,3\}\.[0-9]\{1,3\}\%"` 11 | for COVERLEVEL in ${COVERLEVELS};do 12 | echo ${COVERLEVEL} | tr "%" " "; 13 | COVERLEVEL=${COVERLEVEL/.*}; 14 | echo "Coverage - ${COVERLEVEL}%"; 15 | echo "Watermark- ${WATERMARK}%"; 16 | if [[ $COVERLEVEL -lt $WATERMARK ]]; then echo "!!!! FAIL !!!!"; EXITCODE=1;fi 17 | done 18 | EXITCODE=$EXITCODE 19 | done 20 | exit ${EXITCODE} 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /toggle_suite_test.go: -------------------------------------------------------------------------------- 1 | package toggle_test 2 | 3 | import ( 4 | "testing" 5 | 6 | . "github.com/onsi/ginkgo" 7 | . "github.com/onsi/gomega" 8 | ) 9 | 10 | func TestApp(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "App Suite") 13 | } 14 | -------------------------------------------------------------------------------- /wercker.yml: -------------------------------------------------------------------------------- 1 | box: wercker/golang 2 | build: 3 | # The steps that will be executed on build 4 | steps: 5 | # Sets the go workspace and places you package 6 | # at the right place in the workspace tree 7 | - setup-go-workspace 8 | 9 | # Gets the dependencies 10 | - script: 11 | name: go get 12 | code: | 13 | cd $WERCKER_SOURCE_DIR 14 | go version 15 | go get github.com/tools/godep 16 | export PATH=$WERCKER_SOURCE_DIR/bin:$PATH 17 | 18 | # Test the project 19 | - script: 20 | name: go test 21 | code: | 22 | godep go test ./... 23 | 24 | # Test coverage for the project 25 | - script: 26 | name: go test cover 27 | code: | 28 | ./testCoverage ./... 50 29 | 30 | - script: 31 | name: coveralls upload 32 | code: | 33 | go get github.com/axw/gocov/gocov 34 | go get github.com/mattn/goveralls 35 | GIT_BRANCH=$WERCKER_GIT_BRANCH 36 | ./coverage --coveralls 37 | 38 | # Test if the project builds 39 | - script: 40 | name: go build 41 | code: | 42 | godep go build ./... 43 | 44 | --------------------------------------------------------------------------------