mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-07-18 02:11:57 +00:00
🚨 Set ConfigFilePath
as omitempty
and remove the incorrect TestConfigWriteIgnoresReadonlyFields
test
This commit is contained in:
parent
0d517b4a4c
commit
86b1289c5d
@ -33,7 +33,7 @@ type ConfigStruct struct {
|
|||||||
Kube KubeConfig `yaml:"kube"`
|
Kube KubeConfig `yaml:"kube"`
|
||||||
SelfNamespace string `yaml:"selfnamespace" default:"kubeshark"`
|
SelfNamespace string `yaml:"selfnamespace" default:"kubeshark"`
|
||||||
DumpLogs bool `yaml:"dumplogs" default:"false"`
|
DumpLogs bool `yaml:"dumplogs" default:"false"`
|
||||||
ConfigFilePath string `yaml:"configpath" readonly:""`
|
ConfigFilePath string `yaml:"configpath,omitempty" readonly:""`
|
||||||
HeadlessMode bool `yaml:"headless" default:"false"`
|
HeadlessMode bool `yaml:"headless" default:"false"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,33 +1,12 @@
|
|||||||
package config_test
|
package config_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/kubeshark/kubeshark/config"
|
"github.com/kubeshark/kubeshark/config"
|
||||||
"gopkg.in/yaml.v3"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConfigWriteIgnoresReadonlyFields(t *testing.T) {
|
|
||||||
var readonlyFields []string
|
|
||||||
|
|
||||||
configElem := reflect.ValueOf(&config.ConfigStruct{}).Elem()
|
|
||||||
getFieldsWithReadonlyTag(configElem, &readonlyFields)
|
|
||||||
|
|
||||||
configWithDefaults, _ := config.GetConfigWithDefaults()
|
|
||||||
configWithDefaultsBytes, _ := yaml.Marshal(configWithDefaults)
|
|
||||||
for _, readonlyField := range readonlyFields {
|
|
||||||
t.Run(readonlyField, func(t *testing.T) {
|
|
||||||
readonlyFieldToCheck := fmt.Sprintf(" %s:", readonlyField)
|
|
||||||
if strings.Contains(string(configWithDefaultsBytes), readonlyFieldToCheck) {
|
|
||||||
t.Errorf("unexpected result - readonly field: %v, config: %v", readonlyField, configWithDefaults)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func getFieldsWithReadonlyTag(currentElem reflect.Value, readonlyFields *[]string) {
|
func getFieldsWithReadonlyTag(currentElem reflect.Value, readonlyFields *[]string) {
|
||||||
for i := 0; i < currentElem.NumField(); i++ {
|
for i := 0; i < currentElem.NumField(); i++ {
|
||||||
currentField := currentElem.Type().Field(i)
|
currentField := currentElem.Type().Field(i)
|
||||||
|
Loading…
Reference in New Issue
Block a user