mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
ffc931aad1
* Added unit tag as argument. Added description to runTests command. Changed code generator to have unit build tag in generated unit test files. * Added unit build tag to all unit test files. * added to new unit test unit build tag * Update verify-go.yml * small fix --------- Co-authored-by: Muhammadali Nazarov <Muhammadali.Nazarov@acronis.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
71 lines
1.5 KiB
Go
71 lines
1.5 KiB
Go
//go:build unit
|
|
// +build unit
|
|
|
|
package config
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestAvailableFlagValues(t *testing.T) {
|
|
var f StepFilters
|
|
|
|
var test0 string
|
|
var test1 string
|
|
var test2 []string
|
|
var test3 bool
|
|
|
|
var c = &cobra.Command{
|
|
Use: "test",
|
|
Short: "..",
|
|
}
|
|
|
|
c.Flags().StringVar(&test0, "test0", "val0", "Test 0")
|
|
c.Flags().StringVar(&test1, "test1", "", "Test 1")
|
|
c.Flags().StringSliceVar(&test2, "test2", []string{}, "Test 2")
|
|
c.Flags().BoolVar(&test3, "test3", false, "Test 3")
|
|
|
|
c.Flags().Set("test1", "val1")
|
|
c.Flags().Set("test2", "val3_1")
|
|
c.Flags().Set("test3", "true")
|
|
|
|
v := AvailableFlagValues(c, &f)
|
|
|
|
if v["test0"] != nil {
|
|
t.Errorf("expected: 'test0' to be empty but was %v", v["test0"])
|
|
}
|
|
|
|
assert.Equal(t, "val1", v["test1"])
|
|
assert.Equal(t, []string{"val3_1"}, v["test2"])
|
|
assert.Equal(t, true, v["test3"])
|
|
|
|
}
|
|
|
|
func TestMarkFlagsWithValue(t *testing.T) {
|
|
var test0 string
|
|
var test1 string
|
|
var test2 string
|
|
var c = &cobra.Command{
|
|
Use: "test",
|
|
Short: "..",
|
|
}
|
|
c.Flags().StringVar(&test0, "test0", "val0", "Test 0")
|
|
c.Flags().StringVar(&test1, "test1", "", "Test 1")
|
|
c.Flags().StringVar(&test2, "test2", "", "Test 2")
|
|
|
|
s := StepConfig{
|
|
Config: map[string]interface{}{
|
|
"test2": "val2",
|
|
},
|
|
}
|
|
|
|
MarkFlagsWithValue(c, s)
|
|
|
|
assert.Equal(t, true, c.Flags().Changed("test0"), "default not considered")
|
|
assert.Equal(t, false, c.Flags().Changed("test1"), "no value: considered as set")
|
|
assert.Equal(t, true, c.Flags().Changed("test2"), "config not considered")
|
|
}
|