Files
ai/models/server_test.go
2023-06-05 10:16:51 +08:00

58 lines
1.7 KiB
Go

package models
import (
"io/ioutil"
"path/filepath"
"testing"
"gopkg.in/yaml.v2"
)
// 單元測試:創建服務器
func TestCreateServerByTencentCloud(t *testing.T) {
absPath, _ := filepath.Abs("../data/config.yaml")
configFile, err := ioutil.ReadFile(absPath)
if err != nil {
t.Errorf("讀取配置文件失敗: %v", err)
}
var config Config
if err := yaml.Unmarshal(configFile, &config); err != nil {
t.Errorf("格式化配置文件失敗: %v", err)
}
if err := CreateServerByTencentCloud(config.TencentCloud.SecretId, config.TencentCloud.SecretKey); err != nil {
t.Errorf("創建服務器失敗: %v", err)
}
}
// 單元測試:獲取服務器列表
func TestGetServerListByTencentCloud(t *testing.T) {
absPath, _ := filepath.Abs("../data/config.yaml")
configFile, err := ioutil.ReadFile(absPath)
if err != nil {
t.Errorf("讀取配置文件失敗: %v", err)
}
var config Config
if err := yaml.Unmarshal(configFile, &config); err != nil {
t.Errorf("格式化配置文件失敗: %v", err)
}
if err := CheckServerStatusByTencentCloud(config.TencentCloud.SecretId, config.TencentCloud.SecretKey); err != nil {
t.Errorf("獲取服務器列表失敗: %v", err)
}
}
// 單元測試:註銷服務器
func TestTerminateServerByTencentCloud(t *testing.T) {
absPath, _ := filepath.Abs("../data/config.yaml")
configFile, err := ioutil.ReadFile(absPath)
if err != nil {
t.Errorf("讀取配置文件失敗: %v", err)
}
var config Config
if err := yaml.Unmarshal(configFile, &config); err != nil {
t.Errorf("格式化配置文件失敗: %v", err)
}
if err := TerminateServerByTencentCloud(config.TencentCloud.SecretId, config.TencentCloud.SecretKey); err != nil {
t.Errorf("註銷服務器失敗: %v", err)
}
}