Skip to content

Commit

Permalink
Add additional unit tests to fleet-server config (#2499)
Browse files Browse the repository at this point in the history
  • Loading branch information
michel-laterman authored Apr 13, 2023
1 parent e8fe231 commit 0fd3447
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions internal/pkg/agent/configuration/fleet_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0fd3447

Please sign in to comment.