github.com/apache/incubator-kie-tools/packages/kn-plugin-workflow@v0.28.1-0.20240311201729-34c6856b157f/pkg/common/operator_test.go (about)

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one
     3   * or more contributor license agreements.  See the NOTICE file
     4   * distributed with this work for additional information
     5   * regarding copyright ownership.  The ASF licenses this file
     6   * to you under the Apache License, Version 2.0 (the
     7   * "License"); you may not use this file except in compliance
     8   * with the License.  You may obtain a copy of the License at
     9   * 
    10   *  http://www.apache.org/licenses/LICENSE-2.0
    11   * 
    12   * Unless required by applicable law or agreed to in writing,
    13   * software distributed under the License is distributed on an
    14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    15   * KIND, either express or implied.  See the License for the
    16   * specific language governing permissions and limitations
    17   * under the License. 
    18   */
    19  
    20  package common
    21  
    22  import (
    23  	"testing"
    24  )
    25  
    26  var testCasesCheckOperatorRunning = []struct {
    27  	name     string
    28  	input    string
    29  	expected bool
    30  }{
    31  	{
    32  		name: "pod running",
    33  		input: `NAME   READY   STATUS    RESTARTS   AGE
    34  sonataflow-operator-controller-manager-78cb446b89-gj9jz   2/2     Running   0          95m`,
    35  		expected: true,
    36  	},
    37  	{
    38  		name:     "no pods",
    39  		input:    "No resources found in sonataflow-operator-system namespace.",
    40  		expected: false,
    41  	},
    42  	{
    43  		name:     "no pods - empty string",
    44  		input:    "",
    45  		expected: false,
    46  	},
    47  	{
    48  		name:     "no pods - - empty string 2",
    49  		input:    " ",
    50  		expected: false,
    51  	},
    52  	{
    53  		name:     "no pods - some return",
    54  		input:    " some weird return ",
    55  		expected: false,
    56  	},
    57  }
    58  
    59  func TestCheckOperatorRunning(t *testing.T) {
    60  	for _, tc := range testCasesCheckOperatorRunning {
    61  		t.Run(tc.name, func(t *testing.T) {
    62  			result := checkOperatorRunning(tc.input)
    63  			if result != tc.expected {
    64  				t.Errorf("Expected %v, but got %v", tc.expected, result)
    65  			}
    66  		})
    67  	}
    68  }