-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from rebuy-de/initial-pr
Initial PR
- Loading branch information
Showing
7 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
language: go | ||
|
||
go: | ||
- 1.9 | ||
- master | ||
|
||
go_import_path: github.com/rebuy-de/rebuy-go-sdk | ||
|
||
before_install: | ||
- GOFILES=$(find . -iname '*.go' -type f | grep -v /vendor/) | ||
- GOPKGS=$(go list ./...) | ||
- curl -L -s https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 -o $GOPATH/bin/dep | ||
- chmod +x $GOPATH/bin/dep | ||
- go get github.com/golang/lint/golint | ||
|
||
install: | ||
- dep ensure | ||
|
||
script: | ||
- gofmt -l $GOFILES | ||
- go build $GOPKGS | ||
- go test -v $GOPKGS | ||
- golint -set_exit_status $GOPKGS |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[[constraint]] | ||
branch = "v2" | ||
name = "gopkg.in/yaml.v2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
# rebuy-go-sdk | ||
|
||
[![GoDoc](https://godoc.org/github.com/rebuy-de/rebuy-go-sdk?status.svg)](https://godoc.org/github.com/rebuy-de/rebuy-go-sdk) | ||
|
||
Library for our Golang projects | ||
|
||
> **Development Status** *rebuy-go-sdk* is designed for internal use. Since it | ||
> uses [Semantic Versioning](https://semver.org/) it is safe to use, but expect | ||
> big changes between major version updates. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cmdutil | ||
|
||
import "os" | ||
|
||
type exitCode struct { | ||
code int | ||
} | ||
|
||
// Exit causes the current program to exit with the given status code. On the | ||
// contrary to os.Exit, it respects defer statements. It requires the | ||
// HandleExit function to be deferred in top of the main function. | ||
// | ||
// Internally this is done by throwing a panic with the ExitCode type, which | ||
// gets recovered in the HandleExit function. | ||
func Exit(code int) { | ||
panic(exitCode{code: code}) | ||
} | ||
|
||
// HandleExit recovers from Exit calls and terminates the current program with | ||
// a proper exit code. It should get deferred at the beginning of the main | ||
// function. | ||
// | ||
// func main() { | ||
// defer cmdutil.HandleExit() | ||
// run() // this function might call Exit anytime | ||
// } | ||
func HandleExit() { | ||
if e := recover(); e != nil { | ||
if exit, ok := e.(exitCode); ok == true { | ||
os.Exit(exit.code) | ||
} | ||
panic(e) // not an Exit, bubble up | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package testutil | ||
|
||
import ( | ||
"encoding/json" | ||
"flag" | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
|
||
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
var ( | ||
updateGolden = flag.Bool("update-golden", false, | ||
"update the golden file instead of comparing it") | ||
) | ||
|
||
// AssertGolden tests, if the content of filename matches given data. On | ||
// missmatch the test fails. When setting the `-update-golden` flag to the | ||
// test, if will update the file which can be compared via a VCS diff. | ||
func AssertGolden(t *testing.T, filename string, data []byte) { | ||
if *updateGolden { | ||
err := ioutil.WriteFile(filename, data, os.FileMode(0644)) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
} | ||
|
||
golden, err := ioutil.ReadFile(filename) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
|
||
if string(golden) != string(data) { | ||
t.Errorf("Generated file '%s' doesn't match golden file. Update with '-update-golden'.", filename) | ||
} | ||
} | ||
|
||
// AssertGoldenYAML works like AssertGolden, but converts the data to YAML file. | ||
func AssertGoldenYAML(t *testing.T, filename string, data interface{}) { | ||
generated, err := yaml.Marshal(data) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
|
||
generated = append(generated, '\n') | ||
|
||
AssertGolden(t, filename, generated) | ||
} | ||
|
||
// AssertGoldenJSON works like AssertGolden, but converts the data to JSON file. | ||
func AssertGoldenJSON(t *testing.T, filename string, data interface{}) { | ||
generated, err := json.MarshalIndent(data, "", " ") | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
|
||
generated = append(generated, '\n') | ||
|
||
AssertGolden(t, filename, generated) | ||
} |