knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/test/upgrade/functions_test.go (about)

     1  /*
     2  Copyright 2020 The Knative Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package upgrade_test
    18  
    19  import (
    20  	"testing"
    21  
    22  	"knative.dev/pkg/test/upgrade"
    23  )
    24  
    25  const (
    26  	upgradeTestRunning = "🏃 Running upgrade test suite..."
    27  	upgradeTestSuccess = "🥳🎉 Success! Upgrade suite completed without errors."
    28  	upgradeTestFailure = "💣🤬💔️ Upgrade suite have failed!"
    29  )
    30  
    31  func TestExpectedTextsForEmptySuite(t *testing.T) {
    32  	assert := assertions{tb: t}
    33  	fp := notFailing
    34  	suite := emptySuiteExample()
    35  	txt := expectedTexts(suite, fp)
    36  	expected := []string{
    37  		"1) 💿 No base installation registered. Skipping.",
    38  		"2) ✅️️ No pre upgrade tests registered. Skipping.",
    39  		"3) 🔄 No continual tests registered. Skipping.",
    40  		"4) 📀 No upgrade operations registered. Skipping.",
    41  		"5) ✅️️ No post upgrade tests registered. Skipping.",
    42  		"6) 💿 No downgrade operations registered. Skipping.",
    43  		"7) ✅️️ No post downgrade tests registered. Skipping.",
    44  	}
    45  	assert.arraysEqual(txt.elms, expected)
    46  }
    47  
    48  func TestExpectedTextsForCompleteSuite(t *testing.T) {
    49  	assert := assertions{tb: t}
    50  	fp := notFailing
    51  	suite := completeSuiteExampleWithFailures(fp)
    52  	txt := expectedTexts(suite, fp)
    53  	expected := []string{
    54  		"1) 💿 Installing base installations. 2 are registered.",
    55  		`1.1) Installing base install of "Serving latest stable release".`,
    56  		`1.2) Installing base install of "Eventing latest stable release".`,
    57  		"2) ✅️️ Testing functionality before upgrade is performed. 2 tests are registered.",
    58  		`2.1) Testing with "Serving pre upgrade test".`,
    59  		`2.2) Testing with "Eventing pre upgrade test".`,
    60  		"3) 🔄 Starting continual tests. 1 tests are registered.",
    61  		`3.1) Starting continual tests of "Serving continual test".`,
    62  		"4) 📀 Upgrading with 2 registered operations.",
    63  		`4.1) Upgrading with "Serving HEAD".`,
    64  		`4.2) Upgrading with "Eventing HEAD".`,
    65  		"5) ✅️️ Testing functionality after upgrade is performed. 2 tests are registered.",
    66  		`5.1) Testing with "Serving post upgrade test".`,
    67  		`5.2) Testing with "Eventing post upgrade test".`,
    68  		"6) 💿 Downgrading with 2 registered operations.",
    69  		`6.1) Downgrading with "Serving latest stable release".`,
    70  		`6.2) Downgrading with "Eventing latest stable release".`,
    71  		"7) ✅️️ Testing functionality after downgrade is performed. 2 tests are registered.",
    72  		`7.1) Testing with "Serving post downgrade test".`,
    73  		`7.2) Testing with "Eventing post downgrade test".`,
    74  	}
    75  	assert.arraysEqual(txt.elms, expected)
    76  }
    77  
    78  func TestExpectedTextsForFailingCompleteSuite(t *testing.T) {
    79  	assert := assertions{tb: t}
    80  	fp := failurePoint{
    81  		step:    2,
    82  		element: 1,
    83  	}
    84  	suite := completeSuiteExampleWithFailures(fp)
    85  	txt := expectedTexts(suite, fp)
    86  	expected := []string{
    87  		"1) 💿 Installing base installations. 2 are registered.",
    88  		`1.1) Installing base install of "Serving latest stable release".`,
    89  		`1.2) Installing base install of "Eventing latest stable release".`,
    90  		"2) ✅️️ Testing functionality before upgrade is performed. 2 tests are registered.",
    91  		`2.1) Testing with "FailingOfServing pre upgrade test".`,
    92  	}
    93  	assert.arraysEqual(txt.elms, expected)
    94  }
    95  
    96  func TestSuiteExecuteEmpty(t *testing.T) {
    97  	assert := assertions{tb: t}
    98  	c, buf := newConfig(t)
    99  	fp := notFailing
   100  	suite := emptySuiteExample()
   101  	suite.Execute(c)
   102  	output := buf.String()
   103  	if c.T.Failed() {
   104  		return
   105  	}
   106  
   107  	txt := expectedTexts(suite, fp)
   108  	txt.append(upgradeTestRunning, upgradeTestSuccess)
   109  	assert.textContains(output, txt)
   110  }
   111  
   112  func TestSuiteExecuteWithComplete(t *testing.T) {
   113  	assert := assertions{t}
   114  	c, buf := newConfig(t)
   115  	suite := completeSuite()
   116  	upgrade.DefaultOnWait = probeOnWaitFunc()
   117  	suite.Execute(c)
   118  	output := buf.String()
   119  	if c.T.Failed() {
   120  		return
   121  	}
   122  	expected := expectedTexts(suite, notFailing)
   123  	expected.append(upgradeTestRunning, upgradeTestSuccess)
   124  	expected.append(
   125  		"Installing Serving stable 0.17.1",
   126  		"Installing Eventing stable 0.17.2",
   127  		"Installing Serving HEAD at e3c4563",
   128  		"Installing Eventing HEAD at 12f67cc",
   129  		"Installing Serving stable 0.17.1",
   130  		"Installing Eventing stable 0.17.2",
   131  		"Serving received a stop event",
   132  		"Running Serving continual test",
   133  		"Serving - probing functionality...",
   134  	)
   135  	assert.textContains(output, expected)
   136  }