Move opentracing configuration for location to go (#4965)

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-01-25 21:39:20 -03:00 committed by GitHub
parent a4f3467f9b
commit 7ff49b25d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 44 deletions

View file

@ -30,16 +30,14 @@ type opentracing struct {
// Config contains the configuration to be used in the Ingress
type Config struct {
Enabled bool `json:"enabled"`
Set bool `json:"set"`
}
// Equal tests for equality between two Config types
func (bd1 *Config) Equal(bd2 *Config) bool {
if bd1.Set != bd2.Set {
return false
} else if bd1.Enabled != bd2.Enabled {
if bd1.Enabled != bd2.Enabled {
return false
}
return true
}
@ -51,7 +49,8 @@ func NewParser(r resolver.Resolver) parser.IngressAnnotation {
func (s opentracing) Parse(ing *networking.Ingress) (interface{}, error) {
enabled, err := parser.GetBoolAnnotation("enable-opentracing", ing)
if err != nil {
return &Config{Set: false, Enabled: false}, nil
return &Config{Enabled: false}, nil
}
return &Config{Set: true, Enabled: enabled}, nil
return &Config{Enabled: enabled}, nil
}

View file

@ -74,9 +74,7 @@ func TestIngressAnnotationOpentracingSetTrue(t *testing.T) {
if !ok {
t.Errorf("expected a Config type")
}
if !openTracing.Set {
t.Errorf("expected annotation value to be set")
}
if !openTracing.Enabled {
t.Errorf("expected annotation value to be true, got false")
}
@ -95,9 +93,7 @@ func TestIngressAnnotationOpentracingSetFalse(t *testing.T) {
if !ok {
t.Errorf("expected a Config type")
}
if !openTracing.Set {
t.Errorf("expected annotation value to be set")
}
if openTracing.Enabled {
t.Errorf("expected annotation value to be false, got true")
}
@ -111,11 +107,8 @@ func TestIngressAnnotationOpentracingUnset(t *testing.T) {
ing.SetAnnotations(data)
val, _ := NewParser(&resolver.Mock{}).Parse(ing)
openTracing, ok := val.(*Config)
_, ok := val.(*Config)
if !ok {
t.Errorf("expected a Config type")
}
if openTracing.Set {
t.Errorf("expected annotation value to be unset")
}
}