func TestJSONPollingStatus(t *testing.T) { // Prepare test data. url := "http://my.json.endpoint" obj := map[string]string{ "a": "1", "b": "2", } v := map[string]string{} bytes, err := json.Marshal(obj) assert.Nil(t, err) // Mock out the HTTP client. httpClient := mockhttpclient.New(map[string][]byte{url: bytes}) // Create a PollingStatus and verify that it obtains the expected result. ps, err := NewJSONPollingStatus(&v, url, time.Second, httpClient) assert.Nil(t, err) assert.True(t, reflect.DeepEqual(obj, v)) ps.Stop() }
// More build data. venue464 = testutils.MustReadFile("venue464.json") venue465 = testutils.MustReadFile("venue465.json") venue466 = testutils.MustReadFile("venue466.json") housekeeper1035 = testutils.MustReadFile("housekeeper1035.json") testHttpClient = mockhttpclient.New(map[string][]byte{ "http://build.chromium.org/p/client.skia/json/builders": []byte(buildersSkia), "http://build.chromium.org/p/client.skia.android/json/builders": []byte(buildersAndroid), "http://build.chromium.org/p/client.skia.compile/json/builders": []byte(buildersCompile), "http://build.chromium.org/p/client.skia.fyi/json/builders": []byte(buildersFYI), "http://build.chromium.org/p/client.skia/json/builders/Test-Ubuntu12-ShuttleA-GTX660-x86-Release/builds/0": []byte(ubuntu0), "http://build.chromium.org/p/client.skia/json/builders/Test-Ubuntu12-ShuttleA-GTX660-x86-Release/builds/1": []byte(ubuntu1), "http://build.chromium.org/p/client.skia/json/builders/Test-Ubuntu12-ShuttleA-GTX660-x86-Release/builds/2": []byte(ubuntu2), "http://build.chromium.org/p/client.skia/json/builders/Test-Ubuntu12-ShuttleA-GTX660-x86-Release/builds/3": []byte(ubuntu3), "http://build.chromium.org/p/client.skia/json/builders/Test-Ubuntu12-ShuttleA-GTX660-x86-Release/builds/4": []byte(ubuntu4), "http://build.chromium.org/p/client.skia/json/builders/Test-Ubuntu12-ShuttleA-GTX660-x86-Release/builds/5": []byte(ubuntu5), "http://build.chromium.org/p/client.skia/json/builders/Test-Ubuntu12-ShuttleA-GTX660-x86-Release/builds/6": []byte(ubuntu6), "http://build.chromium.org/p/client.skia/json/builders/Test-Ubuntu12-ShuttleA-GTX660-x86-Release/builds/721": []byte(testJsonInput), "http://build.chromium.org/p/client.skia/json/builders/Test-Ubuntu12-ShuttleA-GTX550Ti-x86_64-Release-Valgrind/builds/152": []byte(testIncompleteBuild), "http://build.chromium.org/p/client.skia.android/json/builders/Perf-Android-Venue8-PowerVR-x86-Release/builds/464": []byte(venue464), "http://build.chromium.org/p/client.skia.android/json/builders/Perf-Android-Venue8-PowerVR-x86-Release/builds/465": []byte(venue465), "http://build.chromium.org/p/client.skia.android/json/builders/Perf-Android-Venue8-PowerVR-x86-Release/builds/466": []byte(venue466), "http://build.chromium.org/p/client.skia.fyi/json/builders/Housekeeper-PerCommit/builds/1035": []byte(housekeeper1035), }) ) // clearDB initializes the database, upgrading it if needed, and removes all // data to ensure that the test begins with a clean slate. Returns a MySQLTestDatabase // which must be closed after the test finishes. func clearDB(t *testing.T) *testutil.MySQLTestDatabase {