github.com/verrazzano/verrazzano@v1.7.1/tools/vz/pkg/internal/util/cluster/mysql_test.go (about) 1 // Copyright (c) 2024, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 package cluster 4 5 import ( 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 "github.com/verrazzano/verrazzano/tools/vz/pkg/internal/util/log" 10 "github.com/verrazzano/verrazzano/tools/vz/pkg/internal/util/report" 11 ) 12 13 // TestAnalyzeMySQLRelatedIssueWhenNamespaceAndMetadataNotPresent tests whether an error does not occur if a valid input is provided 14 // GIVEN a call to analyze mySQL related issues in a cluster-snapshot 15 // WHEN a valid input is provided, but the innoDBCluster resource and time capture data is not present 16 // THEN the function does not generate an error 17 func TestAnalyzeMySQLRelatedIssueWhenNamespaceAndMetadataNotPresent(t *testing.T) { 18 report.ClearReports() 19 logger := log.GetDebugEnabledLogger() 20 assert.NoError(t, AnalyzeMySQLRelatedIssues(logger, "../../test/cluster/testTCPKeepIdle/cluster-snapshot")) 21 report.ClearReports() 22 } 23 24 // TestAnalyzeMySQLRelatedIssueWhenInputIsNotVali tests whether an error occurs when an invalid input is provided 25 // GIVEN a call to analyze MySQL related issues in a cluster-snapshot 26 // WHEN an invalid input is provided 27 // THEN the function does not generate an error 28 func TestAnalyzeMySQLRelatedIssueWhenInputIsNotValid(t *testing.T) { 29 report.ClearReports() 30 logger := log.GetDebugEnabledLogger() 31 assert.Error(t, AnalyzeMySQLRelatedIssues(logger, "../../test/cluster/does-not-exist/cluster-snapshot")) 32 report.ClearReports() 33 } 34 35 // TestAnalyzeMySQLRelatedIssuesWhenMetadataFileIsNotProvided tests whether only one issue is created and no error is generated when a valid input without a metadata.json file and an innoDbCluster resource is provided 36 // GIVEN a call to analyze MySQL related issues in a cluster-snapshot 37 // WHEN a valid input is provided that has an innoDBCluster resource with issues and does not have a metadata.json file 38 // THEN the function does not generate an error and does not create an issue 39 func TestAnalyzeMySQLRelatedIssuesWhenMetadataFileIsNotProvided(t *testing.T) { 40 report.ClearReports() 41 logger := log.GetDebugEnabledLogger() 42 err := AnalyzeMySQLRelatedIssues(logger, "../../test/cluster/inno-db-cluster-stuck-terminating-no-metadata-file/cluster-snapshot") 43 assert.Nil(t, err) 44 reportedIssues := report.GetAllSourcesFilteredIssues(logger, true, 5, 0) 45 assert.True(t, len(reportedIssues) == 0) 46 } 47 48 // TestAnalyzeMySQLRelatedIssuesWhenMetadataFileIsNotProvided tests whether only one issue is created and no error is generated when a valid input when a metadata.json file and an inno-db-cluster.json file is provided 49 // GIVEN a call to analyze MySQL related issues in a cluster-snapshot 50 // WHEN a valid input is provided that has an innoDBCluster resource with issues and has a metadata.json file 51 // THEN the function does not generate an error and only creates one issue 52 func TestAnalyzeMySQLRelatedIssues(t *testing.T) { 53 report.ClearReports() 54 logger := log.GetDebugEnabledLogger() 55 err := AnalyzeMySQLRelatedIssues(logger, "../../test/cluster/inno-db-cluster-stuck-terminating-with-metadata-file/cluster-snapshot") 56 assert.Nil(t, err) 57 reportedIssues := report.GetAllSourcesFilteredIssues(logger, true, 5, 0) 58 assert.True(t, len(reportedIssues) == 1) 59 assert.True(t, reportedIssues[0].Type == report.InnoDBClusterResourceCurrentlyInTerminatingStateForLongDuration) 60 }