Files
odo/pkg/api/running-mode_test.go
Armel Soro 6ed95b7e6f Make odo describe component show information about components running on Podman (#6431)
* Allow using the '--run-on' flag with 'odo describe component'

* Add "platform" to the ForwardedPort output

* Move RunningMode* structs to a dedicated file and add (tested) method for merging running modes

* Add RunningOn field to the Component API

* Make component#GetRunningModes able to return all modes for all specified platforms

* Do not display the namespace from NoComponentFoundError if no namespace is set

* Add more validation logic to the 'describe component' CLI

* Update 'odo describe component' logic for Devfile-based component

* Update 'odo describe component' logic for name-based component

This checks for the component with such name on all platforms.
If it finds several components on both platforms, it needs to extract
Devfile information from those resources.
To do so, it checks if the relevant labels (project type and name) are matching.
It errors out if they do not match, because this would imply that we
don't know what to display as Devfile information.

* Conditionally display "running on" information in human-readable output.

This is displayed only if the "run-on" feature is enabled.

* Implement GetAllResourcesFromSelector in the PodmanCli client

* Add more unit tests

* Update integration tests

* fixup! Update integration tests

* fixup! fixup! Update integration tests
2023-01-02 14:12:58 -05:00

90 lines
1.8 KiB
Go

package api
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestMergeRunningModes(t *testing.T) {
type args struct {
m map[string]RunningModes
}
tests := []struct {
name string
args args
want RunningModes
}{
{
name: "nil map",
want: nil,
},
{
name: "all false with some unknown modes",
args: args{
m: map[string]RunningModes{
"podman": map[RunningMode]bool{
RunningModeDev: false,
RunningModeDeploy: false,
},
"cluster": map[RunningMode]bool{
RunningModeDev: false,
RunningModeDeploy: false,
},
"unknown-platform": map[RunningMode]bool{
"unknown-mode": true,
"another-mode": true,
},
},
},
want: NewRunningModes(),
},
{
name: "true for one platform and false for another",
args: args{
m: map[string]RunningModes{
"podman": map[RunningMode]bool{
RunningModeDev: true,
RunningModeDeploy: false,
},
"cluster": map[RunningMode]bool{
RunningModeDev: false,
RunningModeDeploy: true,
},
},
},
want: map[RunningMode]bool{
RunningModeDev: true,
RunningModeDeploy: true,
},
},
{
name: "true for all platforms",
args: args{
m: map[string]RunningModes{
"podman": map[RunningMode]bool{
RunningModeDev: true,
RunningModeDeploy: true,
},
"cluster": map[RunningMode]bool{
RunningModeDev: true,
RunningModeDeploy: true,
},
},
},
want: map[RunningMode]bool{
RunningModeDev: true,
RunningModeDeploy: true,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := MergeRunningModes(tt.args.m)
if diff := cmp.Diff(tt.want, got); diff != "" {
t.Errorf("MergeRunningModes() mismatch (-want +got):\n%s", diff)
}
})
}
}