Last active
June 30, 2016 22:11
-
-
Save cep21/3690c7a1fae874a778d69ad803f4516b to your computer and use it in GitHub Desktop.
Example integration test of a client
This file contains hidden or 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
| // +build integration | |
| package smiteclient | |
| // Create a file named info.json and put it at the root of your project. That file should have your | |
| // devId and authKey. The file should be inside .gitignore and not checked into git. Then, | |
| // run `go test -v --tags=integration .` to start integration tests using your auth key. | |
| type devInfo struct { | |
| AuthKey string | |
| } | |
| func TestPing(t *testing.T) { | |
| Convey("With a client", t, func() { | |
| // Load the developer specific information for the integration test | |
| var di devInfo | |
| if f, err := os.Open(".client-testing.json"); err == nil { | |
| So(json.NewDecoder(f).Decode(&di), ShouldBeNil) | |
| So(f.Close(), ShouldBeNil) | |
| } else { | |
| t.Fatal("Could not find .client-testing.json") | |
| } | |
| c := &Client { | |
| AuthKey: di.AuthKey | |
| } | |
| ctx, canCtx := context.WithTimeout(context.Background(), time.Second*3) | |
| // Now we can run tests with a real client | |
| Convey("Ping should work", t, func() { | |
| So(client.AuthPing(ctx), ShouldBeNil) | |
| }) | |
| // Good practice to close your contexts when done | |
| Reset(func() { | |
| canCtx() | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment