Skip to content

Commit dc45b4e

Browse files
mdelapenyamtojek
andauthored
fix: add elastic-agent as available service (#493)
* fix: add elastic-agent as available service * chore: add unit tests * chore: better assertion method Co-authored-by: Marcin Tojek <[email protected]>
1 parent d969729 commit dc45b4e

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

cmd/stack.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
)
2020

2121
var availableServices = map[string]struct{}{
22+
"elastic-agent": {},
2223
"elasticsearch": {},
2324
"fleet-server": {},
2425
"kibana": {},

cmd/stack_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
// or more contributor license agreements. Licensed under the Elastic License;
3+
// you may not use this file except in compliance with the Elastic License.
4+
5+
package cmd
6+
7+
import (
8+
"fmt"
9+
"testing"
10+
11+
"github.com/stretchr/testify/require"
12+
)
13+
14+
func TestValidateServicesFlag(t *testing.T) {
15+
t.Run("a non available service returns error", func(t *testing.T) {
16+
err := validateServicesFlag([]string{"non-existing-service"})
17+
require.Error(t, err)
18+
})
19+
20+
t.Run("a non available service in a valid stack returns error", func(t *testing.T) {
21+
err := validateServicesFlag([]string{"elasticsearch", "non-existing-service"})
22+
require.Error(t, err)
23+
})
24+
25+
t.Run("not possible to start a service twice", func(t *testing.T) {
26+
err := validateServicesFlag([]string{"elasticsearch", "elasticsearch"})
27+
require.Error(t, err)
28+
})
29+
30+
availableStackServicesTest := []struct {
31+
services []string
32+
}{
33+
{services: []string{"elastic-agent"}},
34+
{services: []string{"elastic-agent", "elasticsearch"}},
35+
{services: []string{"elasticsearch"}},
36+
{services: []string{"kibana"}},
37+
{services: []string{"package-registry"}},
38+
{services: []string{"fleet-server"}},
39+
{services: []string{"elasticsearch", "fleet-server"}},
40+
}
41+
42+
for _, srv := range availableStackServicesTest {
43+
t.Run(fmt.Sprintf("%v are available as a stack service", srv.services), func(t *testing.T) {
44+
err := validateServicesFlag(srv.services)
45+
require.Nil(t, err)
46+
})
47+
}
48+
49+
}

0 commit comments

Comments
 (0)