Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #218 from suzuki-shunsuke/test/move-testdata
Browse files Browse the repository at this point in the history
test: move testdata
  • Loading branch information
suzuki-shunsuke committed Jan 12, 2020
2 parents dc0d9d3 + 265c93d commit 7af7d24
Show file tree
Hide file tree
Showing 64 changed files with 279 additions and 549 deletions.
12 changes: 4 additions & 8 deletions client/alarm_callback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestClient_GetAlarmCallbacks(t *testing.T) {
cl, err := client.NewClient("http://example.com/api", "admin", "admin")
require.Nil(t, err)

buf, err := ioutil.ReadFile("../testdata/alarm_callbacks.json")
buf, err := ioutil.ReadFile("../testdata/alarm_callback/alarm_callbacks.json")
require.Nil(t, err)
bodyStr := string(buf)

Expand All @@ -31,13 +31,9 @@ func TestClient_GetAlarmCallbacks(t *testing.T) {
Routes: []flute.Route{
{
Tester: &flute.Tester{
Method: "GET",
Path: "/api/alerts/callbacks",
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
Method: "GET",
Path: "/api/alerts/callbacks",
PartOfHeader: getTestHeader(),
},
Response: &flute.Response{
Base: http.Response{
Expand Down
12 changes: 4 additions & 8 deletions client/alert_condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestClient_GetAlertConditions(t *testing.T) {
cl, err := client.NewClient("http://example.com/api", "admin", "admin")
require.Nil(t, err)

buf, err := ioutil.ReadFile("../testdata/index_sets.json")
buf, err := ioutil.ReadFile("../testdata/alert_condition/alert_conditions.json")
require.Nil(t, err)

cl.SetHTTPClient(&http.Client{
Expand All @@ -30,13 +30,9 @@ func TestClient_GetAlertConditions(t *testing.T) {
Routes: []flute.Route{
{
Tester: &flute.Tester{
Method: "GET",
Path: "/api/alerts/conditions",
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
Method: "GET",
Path: "/api/alerts/conditions",
PartOfHeader: getTestHeader(),
},
Response: &flute.Response{
Base: http.Response{
Expand Down
24 changes: 8 additions & 16 deletions client/alert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestClient_GetAlerts(t *testing.T) {
cl, err := client.NewClient("http://example.com/api", "admin", "admin")
require.Nil(t, err)

buf, err := ioutil.ReadFile("../testdata/alerts.json")
buf, err := ioutil.ReadFile("../testdata/alert/alerts.json")
require.Nil(t, err)

cl.SetHTTPClient(&http.Client{
Expand All @@ -30,13 +30,9 @@ func TestClient_GetAlerts(t *testing.T) {
Routes: []flute.Route{
{
Tester: &flute.Tester{
Method: "GET",
Path: "/api/streams/alerts",
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
Method: "GET",
Path: "/api/streams/alerts",
PartOfHeader: getTestHeader(),
},
Response: &flute.Response{
Base: http.Response{
Expand All @@ -63,7 +59,7 @@ func TestClient_GetAlert(t *testing.T) {
cl, err := client.NewClient("http://example.com/api", "admin", "admin")
require.Nil(t, err)

buf, err := ioutil.ReadFile("../testdata/alert.json")
buf, err := ioutil.ReadFile("../testdata/alert/alert.json")
require.Nil(t, err)

id := "5d84c1a92ab79c000d35d6c7"
Expand All @@ -77,13 +73,9 @@ func TestClient_GetAlert(t *testing.T) {
Routes: []flute.Route{
{
Tester: &flute.Tester{
Method: "GET",
Path: "/api/streams/alerts/" + id,
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
Method: "GET",
Path: "/api/streams/alerts/" + id,
PartOfHeader: getTestHeader(),
},
Response: &flute.Response{
Base: http.Response{
Expand Down
44 changes: 12 additions & 32 deletions client/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ func TestClient_CreateDashboard(t *testing.T) {
Path: "/api/dashboards",
},
Tester: &flute.Tester{
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
PartOfHeader: getTestHeader(),
BodyJSONString: `{
"title": "dashboard title",
"description": "dashboard description"
Expand Down Expand Up @@ -93,11 +89,7 @@ func TestClient_DeleteDashboard(t *testing.T) {
Path: "/api/dashboards/" + id,
},
Tester: &flute.Tester{
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
PartOfHeader: getTestHeader(),
},
Response: &flute.Response{
Base: http.Response{
Expand Down Expand Up @@ -130,7 +122,7 @@ func TestClient_GetDashboard(t *testing.T) {
cl, err := client.NewClient("http://example.com/api", "admin", "admin")
require.Nil(t, err)

buf, err := ioutil.ReadFile("../testdata/dashboard.json")
buf, err := ioutil.ReadFile("../testdata/dashboard/dashboard.json")
require.Nil(t, err)

cl.SetHTTPClient(&http.Client{
Expand All @@ -142,13 +134,9 @@ func TestClient_GetDashboard(t *testing.T) {
Routes: []flute.Route{
{
Tester: &flute.Tester{
Method: "GET",
Path: "/api/dashboards/" + testdata.Dashboard().ID,
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
Method: "GET",
Path: "/api/dashboards/" + testdata.Dashboard().ID,
PartOfHeader: getTestHeader(),
},
Response: &flute.Response{
Base: http.Response{
Expand Down Expand Up @@ -178,7 +166,7 @@ func TestClient_GetDashboards(t *testing.T) {
cl, err := client.NewClient("http://example.com/api", "admin", "admin")
require.Nil(t, err)

buf, err := ioutil.ReadFile("../testdata/dashboards.json")
buf, err := ioutil.ReadFile("../testdata/dashboard/dashboards.json")
require.Nil(t, err)

cl.SetHTTPClient(&http.Client{
Expand All @@ -190,13 +178,9 @@ func TestClient_GetDashboards(t *testing.T) {
Routes: []flute.Route{
{
Tester: &flute.Tester{
Method: "GET",
Path: "/api/dashboards",
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
Method: "GET",
Path: "/api/dashboards",
PartOfHeader: getTestHeader(),
},
Response: &flute.Response{
Base: http.Response{
Expand Down Expand Up @@ -226,7 +210,7 @@ func TestClient_UpdateDashboard(t *testing.T) {
_, err = cl.UpdateDashboard(ctx, nil)
require.NotNil(t, err, "dashboard should not be nil")

buf, err := ioutil.ReadFile("../testdata/create_dashboard.json")
buf, err := ioutil.ReadFile("../testdata/dashboard/create_dashboard.json")
require.Nil(t, err)

ds := testdata.Dashboard()
Expand All @@ -244,11 +228,7 @@ func TestClient_UpdateDashboard(t *testing.T) {
Path: "/api/dashboards/" + ds.ID,
},
Tester: &flute.Tester{
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
PartOfHeader: getTestHeader(),
BodyJSONString: string(buf),
},
Response: &flute.Response{
Expand Down
30 changes: 5 additions & 25 deletions client/event_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ func TestClient_CreateEventDefinition(t *testing.T) {
Path: "/api/events/definitions",
},
Tester: &flute.Tester{
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
PartOfHeader: getTestHeader(),
BodyJSONString: reqStr,
},
Response: &flute.Response{
Expand Down Expand Up @@ -92,11 +88,7 @@ func TestClient_DeleteEventDefinition(t *testing.T) {
Path: "/api/events/definitions/" + get.Response().ID,
},
Tester: &flute.Tester{
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
PartOfHeader: getTestHeader(),
},
Response: &flute.Response{
Base: http.Response{
Expand Down Expand Up @@ -148,11 +140,7 @@ func TestClient_GetEventDefinition(t *testing.T) {
Path: "/api/events/definitions/" + get.Response().ID,
},
Tester: &flute.Tester{
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
PartOfHeader: getTestHeader(),
},
Response: &flute.Response{
Base: http.Response{
Expand Down Expand Up @@ -197,11 +185,7 @@ func TestClient_GetEventDefinitions(t *testing.T) {
Path: "/api/events/definitions",
},
Tester: &flute.Tester{
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
PartOfHeader: getTestHeader(),
},
Response: &flute.Response{
Base: http.Response{
Expand Down Expand Up @@ -253,11 +237,7 @@ func TestClient_UpdateEventDefinition(t *testing.T) {
Path: "/api/events/definitions/" + update.Request().ID,
},
Tester: &flute.Tester{
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
PartOfHeader: getTestHeader(),
BodyJSONString: reqStr,
},
Response: &flute.Response{
Expand Down
40 changes: 10 additions & 30 deletions client/event_notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ func TestClient_CreateEventNotification(t *testing.T) {
cl, err := client.NewClient("http://example.com/api", "admin", "admin")
require.Nil(t, err)

reqBuf, err := ioutil.ReadFile("../testdata/request_create_event_notification.json")
reqBuf, err := ioutil.ReadFile("../testdata/event_notification/request_create_event_notification.json")
require.Nil(t, err)
reqBody := string(reqBuf)

respBuf, err := ioutil.ReadFile("../testdata/response_create_event_notification.json")
respBuf, err := ioutil.ReadFile("../testdata/event_notification/response_create_event_notification.json")
require.Nil(t, err)
respBody := string(respBuf)

Expand All @@ -44,11 +44,7 @@ func TestClient_CreateEventNotification(t *testing.T) {
Path: "/api/events/notifications",
},
Tester: &flute.Tester{
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
PartOfHeader: getTestHeader(),
BodyJSONString: reqBody,
},
Response: &flute.Response{
Expand Down Expand Up @@ -98,11 +94,7 @@ func TestClient_DeleteEventNotification(t *testing.T) {
Path: "/api/events/notifications/" + testdata.EventNotification().ID,
},
Tester: &flute.Tester{
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
PartOfHeader: getTestHeader(),
},
Response: &flute.Response{
Base: http.Response{
Expand Down Expand Up @@ -134,7 +126,7 @@ func TestClient_GetEventNotification(t *testing.T) {
cl, err := client.NewClient("http://example.com/api", "admin", "admin")
require.Nil(t, err)

buf, err := ioutil.ReadFile("../testdata/response_create_event_notification.json")
buf, err := ioutil.ReadFile("../testdata/event_notification/response_create_event_notification.json")
require.Nil(t, err)
bodyStr := string(buf)

Expand All @@ -154,11 +146,7 @@ func TestClient_GetEventNotification(t *testing.T) {
Path: "/api/events/notifications/" + testdata.EventNotification().ID,
},
Tester: &flute.Tester{
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
PartOfHeader: getTestHeader(),
},
Response: &flute.Response{
Base: http.Response{
Expand Down Expand Up @@ -186,7 +174,7 @@ func TestClient_GetEventNotifications(t *testing.T) {
cl, err := client.NewClient("http://example.com/api", "admin", "admin")
require.Nil(t, err)

buf, err := ioutil.ReadFile("../testdata/event_notifications.json")
buf, err := ioutil.ReadFile("../testdata/event_notification/event_notifications.json")
require.Nil(t, err)
bodyStr := string(buf)

Expand All @@ -203,11 +191,7 @@ func TestClient_GetEventNotifications(t *testing.T) {
Path: "/api/events/notifications",
},
Tester: &flute.Tester{
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
PartOfHeader: getTestHeader(),
},
Response: &flute.Response{
Base: http.Response{
Expand Down Expand Up @@ -235,7 +219,7 @@ func TestClient_UpdateEventNotification(t *testing.T) {
cl, err := client.NewClient("http://example.com/api", "admin", "admin")
require.Nil(t, err)

buf, err := ioutil.ReadFile("../testdata/response_create_event_notification.json")
buf, err := ioutil.ReadFile("../testdata/event_notification/response_create_event_notification.json")
require.Nil(t, err)
bodyStr := string(buf)

Expand All @@ -255,11 +239,7 @@ func TestClient_UpdateEventNotification(t *testing.T) {
Path: "/api/events/notifications/" + testdata.EventNotification().ID,
},
Tester: &flute.Tester{
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
PartOfHeader: getTestHeader(),
BodyJSONString: ``,
},
Response: &flute.Response{
Expand Down
10 changes: 3 additions & 7 deletions client/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,9 @@ func setExampleMock(cl *client.Client) {
Routes: []flute.Route{
{
Tester: &flute.Tester{
Method: "GET",
Path: "/api/roles/Admin",
PartOfHeader: http.Header{
"Content-Type": []string{"application/json"},
"X-Requested-By": []string{"go-graylog"},
"Authorization": nil,
},
Method: "GET",
Path: "/api/roles/Admin",
PartOfHeader: getTestHeader(),
},
Response: &flute.Response{
Base: http.Response{
Expand Down

0 comments on commit 7af7d24

Please sign in to comment.