From 0fd3447d0177d8f3946a211284e14372b51c9b6c Mon Sep 17 00:00:00 2001 From: Michel Laterman <82832767+michel-laterman@users.noreply.github.com> Date: Thu, 13 Apr 2023 12:25:53 -0700 Subject: [PATCH] Add additional unit tests to fleet-server config (#2499) --- .../agent/configuration/fleet_server_test.go | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/internal/pkg/agent/configuration/fleet_server_test.go b/internal/pkg/agent/configuration/fleet_server_test.go index 3566809e798..2f4f3d0ea80 100644 --- a/internal/pkg/agent/configuration/fleet_server_test.go +++ b/internal/pkg/agent/configuration/fleet_server_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/assert" + "github.com/elastic/elastic-agent-libs/transport/tlscommon" "github.com/elastic/elastic-agent/internal/pkg/agent/errors" ) @@ -53,6 +54,49 @@ func TestElasticsearchFromConnStr(t *testing.T) { insecure: false, es: Elasticsearch{}, err: errors.New("invalid connection string: must include a service token"), + }, { + name: "http connection", + conn: "http://localhost:9200", + token: "my-token", + path: "", + insecure: false, + es: Elasticsearch{ + Protocol: "http", + Hosts: []string{"localhost:9200"}, + ServiceToken: "my-token", + }, + err: nil, + }, { + name: "insecure https", + conn: "https://localhost:9200", + token: "my-token", + path: "", + insecure: true, + es: Elasticsearch{ + Protocol: "https", + Hosts: []string{"localhost:9200"}, + ServiceToken: "my-token", + TLS: &tlscommon.Config{ + VerificationMode: tlscommon.VerifyNone, + }, + }, + err: nil, + }, { + name: "file schema", + conn: "file:///path/to/socket", + token: "my-token", + path: "", + insecure: false, + es: Elasticsearch{}, + err: errors.New("invalid connection string: scheme must be http or https"), + }, { + name: "bad conn string", + conn: "http://local host", + token: "my-token", + path: "", + insecure: false, + es: Elasticsearch{}, + err: errors.New("parse \"http://local host\": invalid character \" \" in host name"), }} for _, tc := range testcases {