-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: issue with headless installation (#7958)
fix: issue with headless installation (#7958) Signed-off-by: pashavictorovich <pavel@codefresh.io>
- Loading branch information
1 parent
a7e7f32
commit 84f949f
Showing
2 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package headless | ||
|
||
import ( | ||
"testing" | ||
|
||
flag "github.com/spf13/pflag" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type StringFlag struct { | ||
// The exact value provided on the flag | ||
value string | ||
} | ||
|
||
func (f StringFlag) String() string { | ||
return f.value | ||
} | ||
|
||
func (f *StringFlag) Set(value string) error { | ||
f.value = value | ||
return nil | ||
} | ||
|
||
func (f *StringFlag) Type() string { | ||
return "string" | ||
} | ||
|
||
func Test_FlagContextNotChanged(t *testing.T) { | ||
res := retrieveContextIfChanged(&flag.Flag{ | ||
Name: "", | ||
Shorthand: "", | ||
Usage: "", | ||
Value: &StringFlag{value: "test"}, | ||
DefValue: "", | ||
Changed: false, | ||
NoOptDefVal: "", | ||
Deprecated: "", | ||
Hidden: false, | ||
ShorthandDeprecated: "", | ||
Annotations: nil, | ||
}) | ||
|
||
assert.Equal(t, "", res) | ||
} | ||
|
||
func Test_FlagContextChanged(t *testing.T) { | ||
res := retrieveContextIfChanged(&flag.Flag{ | ||
Name: "", | ||
Shorthand: "", | ||
Usage: "", | ||
Value: &StringFlag{value: "test"}, | ||
DefValue: "", | ||
Changed: true, | ||
NoOptDefVal: "", | ||
Deprecated: "", | ||
Hidden: false, | ||
ShorthandDeprecated: "", | ||
Annotations: nil, | ||
}) | ||
|
||
assert.Equal(t, "test", res) | ||
} | ||
|
||
func Test_FlagContextNil(t *testing.T) { | ||
res := retrieveContextIfChanged(&flag.Flag{ | ||
Name: "", | ||
Shorthand: "", | ||
Usage: "", | ||
Value: nil, | ||
DefValue: "", | ||
Changed: false, | ||
NoOptDefVal: "", | ||
Deprecated: "", | ||
Hidden: false, | ||
ShorthandDeprecated: "", | ||
Annotations: nil, | ||
}) | ||
|
||
assert.Equal(t, "", res) | ||
} |