🚨 Set ConfigFilePath as omitempty and remove the incorrect TestConfigWriteIgnoresReadonlyFields test

This commit is contained in:
M. Mert Yildiran 2022-12-28 07:14:49 +03:00
parent 0d517b4a4c
commit 86b1289c5d
No known key found for this signature in database
GPG Key ID: DA5D6DCBB758A461
2 changed files with 1 additions and 22 deletions

View File

@ -33,7 +33,7 @@ type ConfigStruct struct {
Kube KubeConfig `yaml:"kube"`
SelfNamespace string `yaml:"selfnamespace" default:"kubeshark"`
DumpLogs bool `yaml:"dumplogs" default:"false"`
ConfigFilePath string `yaml:"configpath" readonly:""`
ConfigFilePath string `yaml:"configpath,omitempty" readonly:""`
HeadlessMode bool `yaml:"headless" default:"false"`
}

View File

@ -1,33 +1,12 @@
package config_test
import (
"fmt"
"reflect"
"strings"
"testing"
"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) {
for i := 0; i < currentElem.NumField(); i++ {
currentField := currentElem.Type().Field(i)