mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-05-21 08:33:28 +00:00
* Remove `logger` module * Remove `shared` module * Move `cli` folder contents into project root * Fix linter * Change the module name from `github.com/kubeshark/kubeshark/cli` to `github.com/kubeshark/kubeshark` * Set the default `Makefile` rule to `build` * Add `lint` rule * Fix the linter errors
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
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)
|
|
currentFieldByName := currentElem.FieldByName(currentField.Name)
|
|
|
|
if currentField.Type.Kind() == reflect.Struct {
|
|
getFieldsWithReadonlyTag(currentFieldByName, readonlyFields)
|
|
continue
|
|
}
|
|
|
|
if _, ok := currentField.Tag.Lookup(config.ReadonlyTag); ok {
|
|
fieldNameByTag := strings.Split(currentField.Tag.Get(config.FieldNameTag), ",")[0]
|
|
*readonlyFields = append(*readonlyFields, fieldNameByTag)
|
|
}
|
|
}
|
|
}
|