github.com/Racer159/jackal@v0.32.7-0.20240401174413-0bd2339e4f2e/src/pkg/utils/wait_test.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // SPDX-FileCopyrightText: 2021-Present The Jackal Authors
     3  
     4  // Package utils provides generic helper functions.
     5  package utils
     6  
     7  import (
     8  	"testing"
     9  
    10  	"github.com/Racer159/jackal/src/pkg/message"
    11  	"github.com/stretchr/testify/require"
    12  	"github.com/stretchr/testify/suite"
    13  )
    14  
    15  type TestIsJSONPathWaitTypeSuite struct {
    16  	suite.Suite
    17  	*require.Assertions
    18  	waitTypes testWaitTypes
    19  }
    20  
    21  type testWaitTypes struct {
    22  	jsonPathType  []string
    23  	conditionType []string
    24  }
    25  
    26  func (suite *TestIsJSONPathWaitTypeSuite) SetupSuite() {
    27  	suite.Assertions = require.New(suite.T())
    28  
    29  	suite.waitTypes.jsonPathType = []string{
    30  		"{.status.availableReplicas}=1",
    31  		"{.status.containerStatuses[0].ready}=true",
    32  		"{.spec.containers[0].ports[0].containerPort}=80",
    33  		"{.spec.nodeName}=knode0",
    34  	}
    35  	suite.waitTypes.conditionType = []string{
    36  		"Ready",
    37  		"delete",
    38  		"",
    39  	}
    40  }
    41  
    42  func (suite *TestIsJSONPathWaitTypeSuite) Test_0_IsJSONPathWaitType() {
    43  	for _, waitType := range suite.waitTypes.conditionType {
    44  		suite.False(isJSONPathWaitType(waitType), "Expected %s not to be a JSONPath wait type", waitType)
    45  	}
    46  	for _, waitType := range suite.waitTypes.jsonPathType {
    47  		suite.True(isJSONPathWaitType(waitType), "Expected %s to be a JSONPath wait type", waitType)
    48  	}
    49  }
    50  
    51  func TestIsJSONPathWaitType(t *testing.T) {
    52  	message.SetLogLevel(message.DebugLevel)
    53  	suite.Run(t, new(TestIsJSONPathWaitTypeSuite))
    54  }