This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
439d4de
commit 3e2b2fd
Showing
7 changed files
with
119 additions
and
114 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 |
---|---|---|
@@ -1,119 +1,62 @@ | ||
package graylog | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/stretchr/testify/require" | ||
"github.com/suzuki-shunsuke/flute/flute" | ||
|
||
"github.com/suzuki-shunsuke/go-graylog/v9/testdata" | ||
) | ||
|
||
// func testDeleteStream( | ||
// ctx context.Context, cl *client.Client, key string, | ||
// ) resource.TestCheckFunc { | ||
// return func(tfState *terraform.State) error { | ||
// id, err := getIDFromTfState(tfState, key) | ||
// if err != nil { | ||
// return err | ||
// } | ||
// if _, _, err := cl.GetStream(ctx, id); err == nil { | ||
// return fmt.Errorf(`stream "%s" must be deleted`, id) | ||
// } | ||
// return nil | ||
// } | ||
// } | ||
func TestAccStream(t *testing.T) { | ||
setEnv() | ||
|
||
// func testCreateStream( | ||
// ctx context.Context, cl *client.Client, key string, | ||
// ) resource.TestCheckFunc { | ||
// return func(tfState *terraform.State) error { | ||
// id, err := getIDFromTfState(tfState, key) | ||
// if err != nil { | ||
// return err | ||
// } | ||
// | ||
// _, _, err = cl.GetStream(ctx, id) | ||
// return err | ||
// } | ||
// } | ||
stream := testdata.Stream() | ||
|
||
// func testUpdateStream( | ||
// ctx context.Context, cl *client.Client, key, title string, | ||
// ) resource.TestCheckFunc { | ||
// return func(tfState *terraform.State) error { | ||
// id, err := getIDFromTfState(tfState, key) | ||
// if err != nil { | ||
// return err | ||
// } | ||
// stream, _, err := cl.GetStream(ctx, id) | ||
// if err != nil { | ||
// return err | ||
// } | ||
// if stream.Title != title { | ||
// return fmt.Errorf("stream.Title == %s, wanted %s", stream.Title, title) | ||
// } | ||
// return nil | ||
// } | ||
// } | ||
tc := &testCase{ | ||
t: t, | ||
Name: "stream", | ||
CreatePath: "/api/streams", | ||
GetPath: "/api/streams/" + stream.ID, | ||
|
||
func TestAccStream(t *testing.T) { | ||
// ctx := context.Background() | ||
// cl, err := setEnv() | ||
// if err != nil { | ||
// t.Fatal(err) | ||
// } | ||
// | ||
// testAccProvider := Provider() | ||
// testAccProviders := map[string]terraform.ResourceProvider{ | ||
// "graylog": testAccProvider, | ||
// } | ||
// | ||
// u, err := uuid.NewV4() | ||
// if err != nil { | ||
// t.Fatal(err) | ||
// } | ||
// prefix := u.String() | ||
// roleTf := ` | ||
//resource "graylog_index_set" "test" { | ||
// title = "terraform test index set" | ||
// description = "terraform test index set description" | ||
// index_prefix = "%s" | ||
// shards = 4 | ||
// replicas = 0 | ||
// rotation_strategy_class = "org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy" | ||
// rotation_strategy { | ||
// type = "org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig" | ||
// } | ||
// retention_strategy_class = "org.graylog2.indexer.retention.strategies.DeletionRetentionStrategy" | ||
// retention_strategy { | ||
// type = "org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig" | ||
// } | ||
// index_analyzer = "standard" | ||
// writable = true | ||
// index_optimization_max_num_segments = 1 | ||
//} | ||
// | ||
//resource "graylog_stream" "test" { | ||
// title = "%s" | ||
// index_set_id = "${graylog_index_set.test.id}" | ||
// matching_type = "AND" | ||
//}` | ||
// createTitle := "terraform stream test" | ||
// updateTitle := "terraform stream test updated" | ||
// | ||
// key := "graylog_stream.test" | ||
// resource.Test(t, resource.TestCase{ | ||
// Providers: testAccProviders, | ||
// CheckDestroy: testDeleteStream(ctx, cl, key), | ||
// Steps: []resource.TestStep{ | ||
// { | ||
// Config: fmt.Sprintf(roleTf, prefix, createTitle), | ||
// Check: resource.ComposeTestCheckFunc( | ||
// testCreateStream(ctx, cl, key), | ||
// ), | ||
// }, | ||
// { | ||
// Config: fmt.Sprintf(roleTf, prefix, updateTitle), | ||
// Check: resource.ComposeTestCheckFunc( | ||
// testUpdateStream(ctx, cl, key, updateTitle), | ||
// ), | ||
// }, | ||
// }, | ||
// }) | ||
CreateReqBodyMap: testdata.CreateStreamReqBodyMap(), | ||
UpdateReqBodyMap: testdata.UpdateStreamReqBodyMap(), | ||
CreatedDataPath: "stream/stream.json", | ||
UpdatedDataPath: "stream/updated_stream.json", | ||
CreateRespBodyPath: "stream/create_response.json", | ||
UpdateRespBodyPath: "stream/stream.json", | ||
CreateTFPath: "stream/create.tf", | ||
UpdateTFPath: "stream/update.tf", | ||
} | ||
|
||
defaultTransport := http.DefaultClient.Transport | ||
defer func() { | ||
http.DefaultClient.Transport = defaultTransport | ||
}() | ||
transport, testCase, err := tc.Get() | ||
require.Nil(tc.t, err) | ||
tp := transport.(*flute.Transport) | ||
route := tp.Services[0].Routes[1] | ||
route.Matcher.Path = route.Tester.Path | ||
tp.Services[0].Routes[1] = route | ||
tp.Services[0].Routes = append(tp.Services[0].Routes, flute.Route{ | ||
Name: "Resume stream", | ||
Matcher: &flute.Matcher{ | ||
Method: "POST", | ||
Path: tc.GetPath + "/resume", | ||
}, | ||
Tester: &flute.Tester{ | ||
PartOfHeader: getTestHeader(), | ||
}, | ||
Response: &flute.Response{ | ||
Base: http.Response{ | ||
StatusCode: 204, | ||
}, | ||
}, | ||
}) | ||
http.DefaultClient.Transport = transport | ||
resource.Test(tc.t, testCase) | ||
} |
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
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,9 @@ | ||
resource "graylog_stream" "test" { | ||
title = "test" | ||
description = "test" | ||
|
||
index_set_id = "5d84bfbe2ab79c000d35d4a9" | ||
disabled = false | ||
matching_type = "AND" | ||
remove_matches_from_default_stream = true | ||
} |
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 @@ | ||
{ | ||
"stream_id": "000000000000000000000003" | ||
} |
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
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,9 @@ | ||
resource "graylog_stream" "test" { | ||
title = "updated title" | ||
description = "updated description" | ||
|
||
index_set_id = "5d84bfbe2ab79c000d35d4a9" | ||
disabled = false | ||
matching_type = "AND" | ||
remove_matches_from_default_stream = true | ||
} |
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,21 @@ | ||
{ | ||
"id": "000000000000000000000003", | ||
"title": "updated title", | ||
"description": "updated description", | ||
"creator_user_id": "admin", | ||
"outputs": [], | ||
"matching_type": "AND", | ||
"created_at": "2019-09-20T12:02:06.078Z", | ||
"disabled": false, | ||
"rules": [], | ||
"alert_conditions": [], | ||
"alert_receivers": { | ||
"emails": [], | ||
"users": [] | ||
}, | ||
"content_pack": null, | ||
"remove_matches_from_default_stream": true, | ||
"index_set_id": "5d84bfbe2ab79c000d35d4a9", | ||
"is_default": false | ||
} | ||
|