Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove the need for the framework test.streams cps property #225

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/cmd/runsSubmitLocal.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (cmd *RunsSubmitLocalCommand) executeSubmitLocal(
)

if err == nil {
reportOnExpandedImages(expander, console)
reportOnExpandedImages(expander)
}
}
}
Expand All @@ -239,7 +239,7 @@ func (cmd *RunsSubmitLocalCommand) executeSubmitLocal(
return err
}

func reportOnExpandedImages(expander images.ImageExpander, console utils.Console) error {
func reportOnExpandedImages(expander images.ImageExpander) error {
eamansour marked this conversation as resolved.
Show resolved Hide resolved

// Write out a status string to the console about how many files were rendered.
count := expander.GetExpandedImageFileCount()
Expand Down
30 changes: 21 additions & 9 deletions pkg/launcher/remoteLauncher.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,37 @@ func (launcher *RemoteLauncher) GetStreams() ([]string, error) {

var restApiVersion string
var err error
var cpsProperty *galasaapi.CpsProperty

restApiVersion, err = embedded.GetGalasactlRestApiVersion()

if err == nil {

cpsProperty, _, err = launcher.apiClient.ConfigurationPropertyStoreAPIApi.
GetCpsNamespaceCascadeProperty(nil, "framework", "test", "streams").ClientApiVersion(restApiVersion).Execute()
var properties []galasaapi.GalasaProperty
properties, _, err = launcher.apiClient.ConfigurationPropertyStoreAPIApi.
QueryCpsNamespaceProperties(nil, "framework").Prefix("test.stream").Suffix("repo").ClientApiVersion(restApiVersion).Execute()
if err == nil {
if cpsProperty == nil || cpsProperty.Value == nil {
streams = make([]string, 0)
} else {
streams = strings.Split(*cpsProperty.Value, ",")
}

streams, err = getStreamNamesFromProperties(properties)
}
}
return streams, err
}

// When passed an array of GalasaProperty objects, extract the stream names from them.
func getStreamNamesFromProperties(properties []galasaapi.GalasaProperty) ([]string, error) {
var err error
var streams []string = make([]string,0)
for _, property := range properties {
propertyNamePtr := property.GetMetadata().Name

propertyName := *propertyNamePtr
// This is something like "test.stream.zosk8s.repo"

streamName := propertyName[12 : len(propertyName)-5]
streams = append(streams, streamName)
}
return streams, err
}

func (launcher *RemoteLauncher) GetTestCatalog(stream string) (TestCatalog, error) {

var err error = nil
Expand Down
56 changes: 56 additions & 0 deletions pkg/launcher/remoteLauncher_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright contributors to the Galasa project
*
* SPDX-License-Identifier: EPL-2.0
*/
package launcher

import (
"testing"

"github.com/galasa-dev/cli/pkg/galasaapi"
"github.com/stretchr/testify/assert"
)

func TestProcessingGoodPropertiesExtractsStreamsOk(t *testing.T) {

var inputProperties []galasaapi.GalasaProperty = make([]galasaapi.GalasaProperty, 0)

name1 := "thames"
name1full := "test.stream." + name1 + ".repo"
name2 := "avon"
name2full := "test.stream." + name2 + ".repo"

inputProperties = append(inputProperties, galasaapi.GalasaProperty{
Metadata: &galasaapi.GalasaPropertyMetadata{
Name: &name1full,
},
})

inputProperties = append(inputProperties, galasaapi.GalasaProperty{
Metadata: &galasaapi.GalasaPropertyMetadata{
Name: &name2full,
},
})

streams, err := getStreamNamesFromProperties(inputProperties)
assert.Nil(t, err)
assert.NotNil(t, streams)
assert.Equal(t, 2, len(streams))

assert.Equal(t, streams[0], name1)
assert.Equal(t, streams[1], name2)
}

func TestProcessingEmptyPropertiesListExtractsZeroStreamsOk(t *testing.T) {

var inputProperties []galasaapi.GalasaProperty = make([]galasaapi.GalasaProperty, 0)

streams, err := getStreamNamesFromProperties(inputProperties)

assert.Nil(t, err)
assert.NotNil(t, streams)
assert.Equal(t, 0, len(streams))
}