-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added ES document indexing After each test is finished if the elastic config is set the process will read the file and Bulk index all the results to the ES server Signed-off-by: Vicente Zepeda Mas <[email protected]> * Adding unit test for ES Indexer Signed-off-by: Vicente Zepeda Mas <[email protected]> * Adding support for lines bigger than buffer size Signed-off-by: Vicente Zepeda Mas <[email protected]> * Adding documentation Signed-off-by: Vicente Zepeda Mas <[email protected]>
- Loading branch information
Showing
12 changed files
with
924 additions
and
227 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
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
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,137 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/spf13/viper" | ||
) | ||
|
||
func initConfigTests() { | ||
viper.Reset() | ||
viper.SetConfigType("yaml") | ||
viper.AddConfigPath(".") | ||
viper.SetConfigFile("test.yaml") | ||
viper.AutomaticEnv() | ||
} | ||
func Test_configAWS(t *testing.T) { | ||
|
||
t.Run("TestingFlags", func(t *testing.T) { | ||
initConfigTests() | ||
viper.Set("aws-region", "us-east-2") | ||
viper.Set("aws-access-key", "THISISAKEY") | ||
viper.Set("aws-access-secret", "THISISASECRET") | ||
viper.Set("aws-account-id", "THEID") | ||
configAWS() | ||
aws := viper.Get("aws").([]interface{})[0].(map[interface{}]interface{}) | ||
if aws["region"] == "" { | ||
t.Fatalf("Flags are set and `aws.0.region` should be set") | ||
} | ||
}) | ||
|
||
t.Run("TestingWithIncompleteFlags", func(t *testing.T) { | ||
initConfigTests() | ||
viper.Set("aws-region", "us-east-2") | ||
viper.Set("aws-access-secret", "THISISASECRET") | ||
viper.Set("aws-account-id", "THEID") | ||
err := configAWS() | ||
if err == nil { | ||
t.Fatalf("Shold fail because of missing AWS config") | ||
} | ||
}) | ||
|
||
t.Run("TestingNoFlagsNoConfig", func(t *testing.T) { | ||
initConfigTests() | ||
err := configAWS() | ||
if err == nil { | ||
t.Fatalf("This test should fail because there is no configuraiton") | ||
} | ||
}) | ||
|
||
t.Run("TestingNoFlagsWithConfig", func(t *testing.T) { | ||
initConfigTests() | ||
config := []interface{}{map[interface{}]interface{}{ | ||
"region": "aws-region", | ||
"access-key": "aws-access-key", | ||
"secret-access-key": "aws-access-secret", | ||
"account-id": "aws-account-id", | ||
}} | ||
viper.Set("aws", config) | ||
err := configAWS() | ||
if err != nil { | ||
t.Fatalf("This test should not fail because there is a YAML config") | ||
} | ||
aws := viper.Get("aws").([]interface{})[0].(map[interface{}]interface{}) | ||
if aws["region"] == "" { | ||
t.Fatalf("Config is set and `aws.0.region` should be set") | ||
} | ||
}) | ||
|
||
t.Run("TestingNoFlagsWithConfig", func(t *testing.T) { | ||
initConfigTests() | ||
config := []interface{}{map[interface{}]interface{}{ | ||
"region": "aws-region", | ||
"access-key": "aws-access-key", | ||
"secret-access-key": "aws-access-secret", | ||
"account-id": "aws-account-id", | ||
}, map[interface{}]interface{}{ | ||
"region": "aws-region-2", | ||
"access-key": "aws-access-key-2", | ||
"secret-access-key": "aws-access-secret-2", | ||
"account-id": "aws-account-id-2", | ||
}} | ||
viper.Set("aws", config) | ||
err := configAWS() | ||
if err == nil { | ||
t.Fatalf("This test should fail because there are multiple AWS configs") | ||
} | ||
}) | ||
} | ||
|
||
func Test_configES(t *testing.T) { | ||
t.Run("TestWithFlags", func(t *testing.T) { | ||
initConfigTests() | ||
viper.Set("elastic-server", "http://localhost:9200") | ||
viper.Set("elastic-user", "user") | ||
viper.Set("elastic-password", "password") | ||
viper.Set("elastic-index", "es-index") | ||
if err := configES(); (err != nil) != false { | ||
if !viper.IsSet("elastic.server") { | ||
t.Fatalf("Flags are set and `elastic.server` should be set") | ||
} | ||
} | ||
}) | ||
|
||
t.Run("TestingNoFlagsNoConfig", func(t *testing.T) { | ||
initConfigTests() | ||
err := configES() | ||
if err != nil { | ||
t.Fatalf("This test not should fail even with empty config") | ||
} | ||
}) | ||
|
||
t.Run("TestingNoFlagsWithConfig", func(t *testing.T) { | ||
initConfigTests() | ||
config := map[string]interface{}{ | ||
"server": "https://localhost:9200", | ||
"user": "user", | ||
"password": "password", | ||
"index": "elastic-index", | ||
} | ||
viper.Set("elastic", config) | ||
err := configES() | ||
if err != nil { | ||
t.Fatalf("This test should not fail because there is a YAML config") | ||
} | ||
if viper.GetString("elastic.server") == "" { | ||
t.Fatalf("Config is set `elastic.server` should be set") | ||
} | ||
}) | ||
|
||
t.Run("TestWithInclompleteFlags", func(t *testing.T) { | ||
initConfigTests() | ||
viper.Set("elastic-server", "http://localhost:9200") | ||
if err := configES(); (err != nil) != true { | ||
t.Fatalf("Should fail because of missing index.") | ||
} | ||
}) | ||
} |
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
Oops, something went wrong.