package channels import ( _ "embed" "testing" "github.com/stretchr/testify/assert" ) var ( //go:embed testdata/config-without-channel.yaml configWithoutChannel []byte //go:embed testdata/config-with-valid-channel.yaml configWithValidChannel []byte //go:embed testdata/config-with-invalid-channel.yaml configWithInvalidChannel []byte ) func TestParseChannelFromHelmConfig(t *testing.T) { var invalidYaml = append(configWithoutChannel, '\n', '{') testCases := []struct { title string helmConfig string expected []string // names expected expectErr bool }{ { title: "Helm config is an empty string", helmConfig: "", expected: []string{}, expectErr: false, }, { title: "Helm config does not contain channel info", helmConfig: string(configWithoutChannel), expected: []string{}, expectErr: false, }, { title: "Helm config contains a valid channel", helmConfig: string(configWithValidChannel), expected: []string{"test-name", "test-name-2"}, expectErr: false, }, { title: "Helm config is not valid yaml", helmConfig: string(invalidYaml), expectErr: true, }, { title: "Helm config does not contain a valid channel (missing bannerEdgeID)", helmConfig: string(configWithInvalidChannel), expectErr: true, }, } for _, tc := range testCases { t.Run(tc.title, func(t *testing.T) { got, err := ParseHelmConfigChannels(tc.helmConfig) if err != nil { assert.True(t, tc.expectErr) return } assert.False(t, tc.expectErr) assert.Len(t, got.Channels, len(tc.expected)) for _, channel := range got.Channels { assert.Contains(t, tc.expected, channel.Name) } }) } }