github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/upgrade/post-upgrade/opensearch/opensearch_dashboards_test.go (about) 1 // Copyright (c) 2022, 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 4 package opensearch 5 6 import ( 7 "bufio" 8 "fmt" 9 . "github.com/onsi/ginkgo/v2" 10 . "github.com/onsi/gomega" 11 "github.com/verrazzano/verrazzano/pkg/k8sutil" 12 "github.com/verrazzano/verrazzano/tests/e2e/pkg" 13 "os" 14 "strings" 15 ) 16 17 const ( 18 oldPatternsTestDataFile = "testdata/upgrade/opensearch-dashboards/old-index-patterns.txt" 19 updatedPatternsTestDataFile = "testdata/upgrade/opensearch-dashboards/updated-index-patterns.txt" 20 ) 21 22 var _ = t.Describe("Index Patterns", Label("f:observability.logging.kibana"), func() { 23 // It Wrapper to only run spec if component is supported on the current Verrazzano installation 24 MinimumVerrazzanoIt := func(description string, f func()) { 25 kubeconfigPath, err := k8sutil.GetKubeConfigLocation() 26 if err != nil { 27 t.It(description, func() { 28 Fail(fmt.Sprintf("Failed to get default kubeconfig path: %s", err.Error())) 29 }) 30 } 31 supported, err := pkg.IsVerrazzanoMinVersion("1.3.0", kubeconfigPath) 32 if err != nil { 33 t.It(description, func() { 34 Fail(err.Error()) 35 }) 36 } 37 // Only run tests if Verrazzano is at least version 1.3.0 38 if supported { 39 t.It(description, f) 40 } else { 41 pkg.Log(pkg.Info, fmt.Sprintf("Skipping check '%v', Verrazzano is not at version 1.3.0", description)) 42 } 43 } 44 // GIVEN the OpenSearch Dashboards pod 45 // WHEN the index patterns are retrieved 46 // THEN verify that they are as expected 47 MinimumVerrazzanoIt("Verify Index Patterns", func() { 48 Eventually(func() bool { 49 kubeConfigPath, _ := k8sutil.GetKubeConfigLocation() 50 if pkg.IsOpenSearchDashboardsEnabled(kubeConfigPath) { 51 isVersionAbove1_3_0, err := pkg.IsVerrazzanoMinVersion("1.3.0", kubeConfigPath) 52 if err != nil { 53 pkg.Log(pkg.Error, fmt.Sprintf("failed to find the verrazzano version: %v", err)) 54 return false 55 } 56 patternFile := oldPatternsTestDataFile 57 if isVersionAbove1_3_0 { 58 patternFile = updatedPatternsTestDataFile 59 } 60 file, err := pkg.FindTestDataFile(patternFile) 61 if err != nil { 62 pkg.Log(pkg.Error, fmt.Sprintf("failed to find test data file %s: %v", patternFile, err)) 63 return false 64 } 65 found, err := os.Open(file) 66 if err != nil { 67 pkg.Log(pkg.Error, fmt.Sprintf("failed to open test data file %s: %v", patternFile, err)) 68 return false 69 } 70 reader := bufio.NewScanner(found) 71 reader.Split(bufio.ScanLines) 72 defer found.Close() 73 var expectedPatterns []string 74 for reader.Scan() { 75 line := strings.TrimSpace(reader.Text()) 76 // skip empty lines 77 if len(line) == 0 { 78 continue 79 } 80 // ignore lines starting with "#" 81 if strings.HasPrefix(line, "#") { 82 continue 83 } 84 expectedPatterns = append(expectedPatterns, line) 85 } 86 actualPatterns := pkg.ListIndexPatterns(kubeConfigPath) 87 pkg.Log(pkg.Info, fmt.Sprintf("Expected Patterns: %v, Actual Patterns: %v", expectedPatterns, actualPatterns)) 88 return pkg.SlicesContainSameStrings(expectedPatterns, actualPatterns) 89 } 90 return true 91 }).WithPolling(pollingInterval).WithTimeout(longTimeout).Should(BeTrue(), "Expected not to fail creation of index patterns") 92 }) 93 })