github.com/Jeffail/benthos/v3@v3.65.0/lib/tracer/constructor_test.go (about)

     1  package tracer_test
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/Jeffail/benthos/v3/lib/tracer"
     8  	"github.com/Jeffail/benthos/v3/lib/util/config"
     9  	yaml "gopkg.in/yaml.v3"
    10  
    11  	_ "github.com/Jeffail/benthos/v3/public/components/all"
    12  )
    13  
    14  func TestSanitise(t *testing.T) {
    15  	exp := config.Sanitised{
    16  		"type": "none",
    17  		"none": map[string]interface{}{},
    18  	}
    19  
    20  	conf := tracer.NewConfig()
    21  	conf.Type = tracer.TypeNone
    22  
    23  	act, err := tracer.SanitiseConfig(conf)
    24  	if err != nil {
    25  		t.Fatal(err)
    26  	}
    27  	if !reflect.DeepEqual(act, exp) {
    28  		t.Errorf("Wrong sanitised output: %v != %v", act, exp)
    29  	}
    30  }
    31  
    32  func TestConstructorConfigYAMLInference(t *testing.T) {
    33  	conf := []tracer.Config{}
    34  
    35  	if err := yaml.Unmarshal([]byte(`[
    36  		{
    37  			"jaeger": {
    38  				"value": "foo"
    39  			},
    40  			"none": {
    41  				"query": "foo"
    42  			}
    43  		}
    44  	]`), &conf); err == nil {
    45  		t.Error("Expected error from multi candidates")
    46  	}
    47  
    48  	if err := yaml.Unmarshal([]byte(`[
    49  		{
    50  			"jaeger": {
    51  				"agent_address": "foo"
    52  			}
    53  		}
    54  	]`), &conf); err != nil {
    55  		t.Error(err)
    56  	}
    57  
    58  	if exp, act := 1, len(conf); exp != act {
    59  		t.Errorf("Wrong number of config parts: %v != %v", act, exp)
    60  		return
    61  	}
    62  	if exp, act := tracer.TypeJaeger, conf[0].Type; exp != act {
    63  		t.Errorf("Wrong inferred type: %v != %v", act, exp)
    64  	}
    65  	if exp, act := "benthos", conf[0].Jaeger.ServiceName; exp != act {
    66  		t.Errorf("Wrong default operator: %v != %v", act, exp)
    67  	}
    68  	if exp, act := "foo", conf[0].Jaeger.AgentAddress; exp != act {
    69  		t.Errorf("Wrong value: %v != %v", act, exp)
    70  	}
    71  }