-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathappframework_suite_test.go
More file actions
138 lines (115 loc) · 4.19 KB
/
appframework_suite_test.go
File metadata and controls
138 lines (115 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright (c) 2018-2022 Splunk Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package c3appfw
import (
"context"
"os"
"path/filepath"
"testing"
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/joho/godotenv"
"github.com/splunk/splunk-operator/test/testenv"
)
const (
// PollInterval specifies the polling interval
PollInterval = 5 * time.Second
// ConsistentPollInterval is the interval to use to consistently check a state is stable
ConsistentPollInterval = 200 * time.Millisecond
ConsistentDuration = 2000 * time.Millisecond
)
var (
testenvInstance *testenv.TestEnv
testSuiteName = "c3appfw-" + testenv.RandomDNSName(3)
appListV1 []string
appListV2 []string
testDataS3Bucket = os.Getenv("TEST_BUCKET")
testS3Bucket = os.Getenv("TEST_INDEXES_S3_BUCKET")
s3AppDirV1 = testenv.AppLocationV1
s3AppDirV2 = testenv.AppLocationV2
s3PVTestApps = testenv.PVTestAppsLocation
currDir, _ = os.Getwd()
downloadDirV1 = filepath.Join(currDir, "c3appfwV1-"+testenv.RandomDNSName(4))
downloadDirV2 = filepath.Join(currDir, "c3appfwV2-"+testenv.RandomDNSName(4))
downloadDirPVTestApps = filepath.Join(currDir, "c3appfwPVTestApps-"+testenv.RandomDNSName(4))
cloudBackend testenv.CloudStorageBackend
)
// TestBasic is the main entry point
func TestBasic(t *testing.T) {
RegisterFailHandler(Fail)
// Find and load the .env file from the current directory upwards
err := loadEnvFile()
Expect(err).ToNot(HaveOccurred(), "Error loading .env file")
sc, _ := GinkgoConfiguration()
sc.Timeout = 240 * time.Minute
RunSpecs(t, "Running "+testSuiteName, sc)
}
//func TestMain(m *testing.M) {
// Run the tests
// os.Exit(m.Run())
//}
// loadEnvFile traverses up the directory tree to find a .env file
func loadEnvFile() error {
// Get the current working directory
dir, err := os.Getwd()
if err != nil {
return err
}
// Traverse up the directory tree
for {
// Check if .env file exists in the current directory
envFile := filepath.Join(dir, ".env")
if _, err := os.Stat(envFile); err == nil {
// .env file found, load it
return godotenv.Load(envFile)
}
// Move up to the parent directory
parentDir := filepath.Dir(dir)
if parentDir == dir {
// Reached the root directory
return nil
}
dir = parentDir
}
}
var _ = BeforeSuite(func() {
var err error
testenvInstance, err = testenv.NewDefaultTestEnv(testSuiteName)
Expect(err).ToNot(HaveOccurred())
ctx := context.TODO()
cloudBackend = testenv.NewCloudStorageBackend(testS3Bucket, testDataS3Bucket)
Expect(cloudBackend).NotTo(BeNil(), "failed to initialize cloud storage backend")
// Create a list of apps to upload
appListV1 = testenv.BasicApps
appFileList := testenv.GetAppFileList(appListV1)
// Download V1 Apps
err = cloudBackend.DownloadFiles(ctx, s3AppDirV1, downloadDirV1, appFileList)
Expect(err).To(Succeed(), "Unable to download V1 app files")
// Create a list of apps to upload after poll period
appListV2 = append(appListV1, testenv.NewAppsAddedBetweenPolls...)
appFileList = testenv.GetAppFileList(appListV2)
// Download V2 Apps
err = cloudBackend.DownloadFiles(ctx, s3AppDirV2, downloadDirV2, appFileList)
Expect(err).To(Succeed(), "Unable to download V2 app files")
})
var _ = AfterSuite(func() {
if testenvInstance != nil {
Expect(testenvInstance.Teardown()).ToNot(HaveOccurred())
}
// Delete locally downloaded app files
err := os.RemoveAll(downloadDirV1)
Expect(err).To(Succeed(), "Unable to delete locally downloaded V1 app files")
err = os.RemoveAll(downloadDirV2)
Expect(err).To(Succeed(), "Unable to delete locally downloaded V2 app files")
})