2016-12-03 09:42:26 +00:00
|
|
|
// +-------------------------------------------------------------------------
|
|
|
|
// | Copyright (C) 2016 Yunify, Inc.
|
|
|
|
// +-------------------------------------------------------------------------
|
|
|
|
// | Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// | you may not use this work except in compliance with the License.
|
|
|
|
// | You may obtain a copy of the License in the LICENSE file, or 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.
|
|
|
|
// +-------------------------------------------------------------------------
|
|
|
|
|
2018-04-01 14:08:32 +00:00
|
|
|
package main
|
2016-12-03 09:42:26 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2017-08-12 17:53:10 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v2"
|
2016-12-03 09:42:26 +00:00
|
|
|
|
|
|
|
"github.com/DATA-DOG/godog"
|
|
|
|
|
|
|
|
"github.com/yunify/qingcloud-sdk-go/config"
|
2017-01-05 14:04:19 +00:00
|
|
|
qc "github.com/yunify/qingcloud-sdk-go/service"
|
2016-12-03 09:42:26 +00:00
|
|
|
)
|
|
|
|
|
2017-08-12 17:53:10 +00:00
|
|
|
func TestMain(m *testing.M) {
|
2016-12-03 09:42:26 +00:00
|
|
|
setUp()
|
|
|
|
|
|
|
|
context := func(s *godog.Suite) {
|
|
|
|
QingCloudServiceFeatureContext(s)
|
2018-04-01 14:08:32 +00:00
|
|
|
InstanceFeatureContext(s)
|
|
|
|
JobFeatureContext(s)
|
2016-12-03 09:42:26 +00:00
|
|
|
}
|
|
|
|
options := godog.Options{
|
|
|
|
Format: "pretty",
|
|
|
|
Paths: []string{"./features"},
|
|
|
|
Tags: "",
|
|
|
|
}
|
|
|
|
status := godog.RunWithOptions("*", context, options)
|
2017-08-12 17:53:10 +00:00
|
|
|
if st := m.Run(); st > status {
|
|
|
|
status = st
|
|
|
|
}
|
2016-12-03 09:42:26 +00:00
|
|
|
os.Exit(status)
|
|
|
|
}
|
|
|
|
|
|
|
|
func setUp() {
|
|
|
|
loadTestConfig()
|
|
|
|
loadConfig()
|
2018-04-01 14:08:32 +00:00
|
|
|
initQingCloudService()
|
2016-12-03 09:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
var tc *testConfig
|
|
|
|
var c *config.Config
|
2017-01-05 14:04:19 +00:00
|
|
|
var qcService *qc.QingCloudService
|
2016-12-03 09:42:26 +00:00
|
|
|
|
|
|
|
type testConfig struct {
|
|
|
|
Zone string `json:"zone" yaml:"zone"`
|
|
|
|
|
|
|
|
RetryWaitTime int `json:"retry_wait_time" yaml:"retry_wait_time"`
|
|
|
|
MaxRetries int `json:"max_retries" yaml:"max_retries"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func loadTestConfig() {
|
|
|
|
if tc == nil {
|
|
|
|
configYAML, err := ioutil.ReadFile("./test_config.yaml")
|
|
|
|
checkErrorForExit(err)
|
|
|
|
|
|
|
|
tc = &testConfig{}
|
|
|
|
err = yaml.Unmarshal(configYAML, tc)
|
|
|
|
checkErrorForExit(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func loadConfig() {
|
|
|
|
if c == nil {
|
|
|
|
c, err = config.NewDefault()
|
|
|
|
checkErrorForExit(err)
|
|
|
|
|
|
|
|
err = c.LoadConfigFromFilepath("./config.yaml")
|
|
|
|
checkErrorForExit(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-01 14:08:32 +00:00
|
|
|
func initQingCloudService() {
|
2017-01-05 14:04:19 +00:00
|
|
|
if qcService == nil {
|
|
|
|
qcService, err = qc.Init(c)
|
2016-12-03 09:42:26 +00:00
|
|
|
checkErrorForExit(err)
|
|
|
|
}
|
|
|
|
}
|