package apiconfig import ( "encoding/json" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" "testing" ) func TestUnmarshalActionYAML(t *testing.T) { yamlData := ` type: some_type config: key1: value1 key2: value2 next: next_action fail: fail_action ` var action Action err := yaml.Unmarshal([]byte(yamlData), &action) if err != nil { t.Fatalf("Failed to unmarshal Action: %v", err) } if action.Type != "some_type" { t.Errorf("Expected Type to be 'some_type', but got '%s'", action.Type) } expectedConfig := map[string]interface{}{ "key1": "value1", "key2": "value2", } var config map[string]interface{} if err := json.Unmarshal(action.Config, &config); err != nil { t.Fatalf("Failed to unmarshal action.Config: %v", err) } assert.Equal(t, expectedConfig, config) } func TestUnmarshalDatasourceConfigYAML(t *testing.T) { yamlData := ` id: some_id type: some_type config: key3: value3 key4: value4 ` var datasourceConfig DatasourceConfig err := yaml.Unmarshal([]byte(yamlData), &datasourceConfig) if err != nil { t.Fatalf("Failed to unmarshal DatasourceConfig: %v", err) } if datasourceConfig.ID != "some_id" { t.Errorf("Expected ID to be 'some_id', but got '%s'", datasourceConfig.ID) } if datasourceConfig.Type != "some_type" { t.Errorf("Expected Type to be 'some_type', but got '%s'", datasourceConfig.Type) } expectedConfig := map[string]interface{}{ "key3": "value3", "key4": "value4", } var config map[string]interface{} if err := json.Unmarshal(datasourceConfig.Config, &config); err != nil { t.Fatalf("Failed to unmarshal datasourceConfig.Config: %v", err) } assert.Equal(t, expectedConfig, config) }