|
| 1 | +package outputs |
| 2 | + |
| 3 | +import ( |
| 4 | + . "github.com/onsi/ginkgo/v2" |
| 5 | + . "github.com/onsi/gomega" |
| 6 | + "github.com/openshift/cluster-logging-operator/api/observability/v1" |
| 7 | +) |
| 8 | + |
| 9 | +var _ = Describe("[internal][validations] ClusterLogForwarder will validate headers in Elasticsearch Output", func() { |
| 10 | + var ( |
| 11 | + es *v1.Elasticsearch |
| 12 | + spec v1.OutputSpec |
| 13 | + ) |
| 14 | + BeforeEach(func() { |
| 15 | + es = &v1.Elasticsearch{} |
| 16 | + spec = v1.OutputSpec{ |
| 17 | + Name: "esOutput", |
| 18 | + Type: v1.OutputTypeElasticsearch, |
| 19 | + Elasticsearch: es, |
| 20 | + } |
| 21 | + }) |
| 22 | + |
| 23 | + Context("#validateElasticsearchHeaders", func() { |
| 24 | + |
| 25 | + It("should pass validation with empty headers", func() { |
| 26 | + Expect(validateElasticsearchHeaders(spec)).To(BeEmpty()) |
| 27 | + }) |
| 28 | + It("should pass validation when no invalid headers set", func() { |
| 29 | + spec.Elasticsearch.Headers = map[string]string{ |
| 30 | + "Accept": "application/json", |
| 31 | + } |
| 32 | + Expect(validateElasticsearchHeaders(spec)).To(BeEmpty()) |
| 33 | + }) |
| 34 | + It("should fail validation when the Content-Type header is set", func() { |
| 35 | + spec.Elasticsearch.Headers = map[string]string{ |
| 36 | + "Content-Type": "application/json", |
| 37 | + } |
| 38 | + Expect(validateElasticsearchHeaders(spec)).ToNot(BeEmpty()) |
| 39 | + }) |
| 40 | + It("should fail validation when the Authorization header is set", func() { |
| 41 | + spec.Elasticsearch.Headers = map[string]string{ |
| 42 | + "Authorization": "test", |
| 43 | + } |
| 44 | + Expect(validateElasticsearchHeaders(spec)).ToNot(BeEmpty()) |
| 45 | + }) |
| 46 | + It("should pass validation when no Elasticsearch Output", func() { |
| 47 | + spec = v1.OutputSpec{ |
| 48 | + Name: "esOutput", |
| 49 | + Type: v1.OutputTypeElasticsearch, |
| 50 | + Elasticsearch: &v1.Elasticsearch{}, |
| 51 | + } |
| 52 | + Expect(validateElasticsearchHeaders(spec)).To(BeEmpty()) |
| 53 | + }) |
| 54 | + }) |
| 55 | +}) |
0 commit comments