|
| 1 | +package configmap |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "gopkg.in/yaml.v2" |
| 7 | + |
| 8 | + corev1 "k8s.io/api/core/v1" |
| 9 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 10 | + |
| 11 | + configv1 "github.com/openshift/api/config/v1" |
| 12 | + consolev1 "github.com/openshift/api/console/v1" |
| 13 | + operatorv1 "github.com/openshift/api/operator/v1" |
| 14 | + routev1 "github.com/openshift/api/route/v1" |
| 15 | + "github.com/openshift/console-operator/pkg/console/subresource/consoleserver" |
| 16 | +) |
| 17 | + |
| 18 | +func TestTechPreviewEnabled(t *testing.T) { |
| 19 | + type args struct { |
| 20 | + techPreviewEnabled bool |
| 21 | + } |
| 22 | + tests := []struct { |
| 23 | + name string |
| 24 | + args args |
| 25 | + want bool |
| 26 | + }{ |
| 27 | + { |
| 28 | + name: "Technology Preview enabled", |
| 29 | + args: args{ |
| 30 | + techPreviewEnabled: true, |
| 31 | + }, |
| 32 | + want: true, |
| 33 | + }, |
| 34 | + { |
| 35 | + name: "Technology Preview disabled", |
| 36 | + args: args{ |
| 37 | + techPreviewEnabled: false, |
| 38 | + }, |
| 39 | + want: false, |
| 40 | + }, |
| 41 | + } |
| 42 | + |
| 43 | + for _, tt := range tests { |
| 44 | + t.Run(tt.name, func(t *testing.T) { |
| 45 | + // Create minimal test configuration |
| 46 | + operatorConfig := &operatorv1.Console{ |
| 47 | + ObjectMeta: metav1.ObjectMeta{ |
| 48 | + Name: "cluster", |
| 49 | + }, |
| 50 | + Spec: operatorv1.ConsoleSpec{}, |
| 51 | + } |
| 52 | + |
| 53 | + consoleConfig := &configv1.Console{ |
| 54 | + ObjectMeta: metav1.ObjectMeta{ |
| 55 | + Name: "cluster", |
| 56 | + }, |
| 57 | + } |
| 58 | + |
| 59 | + authConfig := &configv1.Authentication{ |
| 60 | + ObjectMeta: metav1.ObjectMeta{ |
| 61 | + Name: "cluster", |
| 62 | + }, |
| 63 | + } |
| 64 | + |
| 65 | + infrastructureConfig := &configv1.Infrastructure{ |
| 66 | + ObjectMeta: metav1.ObjectMeta{ |
| 67 | + Name: "cluster", |
| 68 | + }, |
| 69 | + Status: configv1.InfrastructureStatus{ |
| 70 | + APIServerURL: "https://api.test.cluster:6443", |
| 71 | + }, |
| 72 | + } |
| 73 | + |
| 74 | + route := &routev1.Route{ |
| 75 | + ObjectMeta: metav1.ObjectMeta{ |
| 76 | + Name: "console", |
| 77 | + }, |
| 78 | + Spec: routev1.RouteSpec{ |
| 79 | + Host: "console.test.cluster", |
| 80 | + }, |
| 81 | + } |
| 82 | + |
| 83 | + // Generate configmap with tech preview setting |
| 84 | + cm, _, err := DefaultConfigMap( |
| 85 | + operatorConfig, |
| 86 | + consoleConfig, |
| 87 | + authConfig, |
| 88 | + &corev1.ConfigMap{}, |
| 89 | + &corev1.ConfigMap{}, |
| 90 | + infrastructureConfig, |
| 91 | + route, |
| 92 | + 0, // inactivityTimeoutSeconds |
| 93 | + []*consolev1.ConsolePlugin{}, // availablePlugins |
| 94 | + []string{"amd64"}, // nodeArchitectures |
| 95 | + []string{"linux"}, // nodeOperatingSystems |
| 96 | + false, // copiedCSVsDisabled |
| 97 | + false, // contentSecurityPolicyEnabled |
| 98 | + map[string]string{}, // telemetryConfig |
| 99 | + "console.test.cluster", // consoleHost |
| 100 | + tt.args.techPreviewEnabled, |
| 101 | + ) |
| 102 | + |
| 103 | + if err != nil { |
| 104 | + t.Errorf("DefaultConfigMap() error = %v.", err) |
| 105 | + return |
| 106 | + } |
| 107 | + |
| 108 | + // Parse the generated config |
| 109 | + var config consoleserver.Config |
| 110 | + err = yaml.Unmarshal([]byte(cm.Data["console-config.yaml"]), &config) |
| 111 | + if err != nil { |
| 112 | + t.Errorf("Failed to unmarshal config: %v.", err) |
| 113 | + return |
| 114 | + } |
| 115 | + |
| 116 | + // Verify tech preview setting |
| 117 | + if config.ClusterInfo.TechPreviewEnabled != tt.want { |
| 118 | + t.Errorf("TechPreviewEnabled: got %t, want %t (case %q, techPreviewEnabled input=%t).", config.ClusterInfo.TechPreviewEnabled, tt.want, tt.name, tt.args.techPreviewEnabled) |
| 119 | + } |
| 120 | + }) |
| 121 | + } |
| 122 | +} |
0 commit comments