Exemple #1
0
func TestInfluxConfig(t *testing.T) {
	configFile := `
database: aDatabase
hostAndPort: localhost:8085
username: foo
password: apassword
precision: ms
writeConsistency: one
retentionPolicy: myPolicy
`
	buffer := bytes.NewBuffer(([]byte)(configFile))
	var aconfig Config
	if err := utils.Read(buffer, &aconfig); err != nil {
		t.Fatal(err)
	}
	expected := Config{
		Database:         "aDatabase",
		HostAndPort:      "localhost:8085",
		UserName:         "******",
		Password:         "******",
		RetentionPolicy:  "myPolicy",
		WriteConsistency: "one",
		Precision:        "ms",
	}
	if !reflect.DeepEqual(expected, aconfig) {
		t.Errorf("Expected %v, got %v", expected, aconfig)
	}
}
Exemple #2
0
func TestKafkaConfig(t *testing.T) {
	configFile := `
# A comment
endpoints:
    - 10.0.0.1:9092
    - 10.0.1.3:9092
    - 10.0.1.6:9092
topic: someTopic
apiKey: someApiKey
tenantId: someTenantId
clientId: someClientId
`
	buffer := bytes.NewBuffer(([]byte)(configFile))
	var aconfig Config
	if err := utils.Read(buffer, &aconfig); err != nil {
		t.Fatal(err)
	}
	expected := Config{
		ApiKey:   "someApiKey",
		TenantId: "someTenantId",
		ClientId: "someClientId",
		Topic:    "someTopic",
		Endpoints: []string{
			"10.0.0.1:9092", "10.0.1.3:9092", "10.0.1.6:9092"},
	}
	if !reflect.DeepEqual(expected, aconfig) {
		t.Errorf("Expected %v, got %v", expected, aconfig)
	}
}
Exemple #3
0
func consumerBuildersFromString(s string) (
	result []*pstore.ConsumerWithMetricsBuilder, err error) {
	buffer := bytes.NewBuffer(([]byte)(s))
	var c config.ConfigList
	if err = utils.Read(buffer, &c); err != nil {
		return
	}
	return c.CreateConsumerBuilders()
}
Exemple #4
0
func TestTsdbConfigError(t *testing.T) {
	configFile := `
hostAndPort: localhost:8085
timeouts: 35s
`
	buffer := bytes.NewBuffer(([]byte)(configFile))
	var aconfig Config
	if err := utils.Read(buffer, &aconfig); err == nil {
		t.Error("Expected error: misspelled fields timeouts")
	}
}
Exemple #5
0
func TestMixYAMLDefault(t *testing.T) {
	configFile := `
public: 1
private: 2
boo: 3
`
	buffer := bytes.NewBuffer(([]byte)(configFile))
	var m mixedType
	if err := utils.Read(buffer, &m); err == nil {
		t.Error("Expected error here.")
	}

	configFile = `
public: 1
boo: 3
`
	buffer = bytes.NewBuffer(([]byte)(configFile))
	if err := utils.Read(buffer, &m); err != nil {
		t.Error("Expected this to unmarshal.")
	}
	assertValueEquals(
		t, mixedType{Public: 1, YAML: 3}, m)
}
Exemple #6
0
func TestInfluxConfigError(t *testing.T) {
	configFile := `
database: aDatabase
hostAndPort: localhost:8085
username: foo
password: apassword
precision: ms
writeConsistencys: one
retentionPolicy: myPolicy
`
	buffer := bytes.NewBuffer(([]byte)(configFile))
	var aconfig Config
	if err := utils.Read(buffer, &aconfig); err == nil {
		t.Error("Expected error: misspelled writeConsistencys")
	}
}
Exemple #7
0
func TestTsdbConfig(t *testing.T) {
	configFile := `
hostAndPort: localhost:8085
timeout: 35s
`
	buffer := bytes.NewBuffer(([]byte)(configFile))
	var aconfig Config
	if err := utils.Read(buffer, &aconfig); err != nil {
		t.Fatal(err)
	}
	expected := Config{
		HostAndPort: "localhost:8085",
		Timeout:     35 * time.Second,
	}
	if !reflect.DeepEqual(expected, aconfig) {
		t.Errorf("Expected %v, got %v", expected, aconfig)
	}
}
Exemple #8
0
func TestKafkaConfigError(t *testing.T) {
	configFile := `
# A comment
endpoint:
    - 10.0.0.1:9092
    - 10.0.1.3:9092
    - 10.0.1.6:9092
topic: someTopic
apiKey: someApiKey
tenantId: someTenantId
clientId: someClientId
`
	buffer := bytes.NewBuffer(([]byte)(configFile))
	var aconfig Config
	if err := utils.Read(buffer, &aconfig); err == nil {
		t.Error("Expected error: misspelled endpoint")
	}
}