|
| 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