|
| 1 | +package aliyuncas_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "encoding/json" |
| 6 | + "flag" |
| 7 | + "fmt" |
| 8 | + "os" |
| 9 | + "strings" |
| 10 | + "testing" |
| 11 | + |
| 12 | + provider "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/aliyun-cas" |
| 13 | +) |
| 14 | + |
| 15 | +var ( |
| 16 | + fInputCertPath string |
| 17 | + fInputKeyPath string |
| 18 | + fAccessKeyId string |
| 19 | + fAccessKeySecret string |
| 20 | + fRegion string |
| 21 | +) |
| 22 | + |
| 23 | +func init() { |
| 24 | + argsPrefix := "CERTIMATE_SSLMANAGER_ALIYUNCAS_" |
| 25 | + |
| 26 | + flag.StringVar(&fInputCertPath, argsPrefix+"INPUTCERTPATH", "", "") |
| 27 | + flag.StringVar(&fInputKeyPath, argsPrefix+"INPUTKEYPATH", "", "") |
| 28 | + flag.StringVar(&fAccessKeyId, argsPrefix+"ACCESSKEYID", "", "") |
| 29 | + flag.StringVar(&fAccessKeySecret, argsPrefix+"ACCESSKEYSECRET", "", "") |
| 30 | + flag.StringVar(&fRegion, argsPrefix+"REGION", "", "") |
| 31 | +} |
| 32 | + |
| 33 | +/* |
| 34 | +Shell command to run this test: |
| 35 | +
|
| 36 | + go test -v ./aliyun_cas_test.go -args \ |
| 37 | + --CERTIMATE_SSLMANAGER_ALIYUNCAS_INPUTCERTPATH="/path/to/your-input-cert.pem" \ |
| 38 | + --CERTIMATE_SSLMANAGER_ALIYUNCAS_INPUTKEYPATH="/path/to/your-input-key.pem" \ |
| 39 | + --CERTIMATE_SSLMANAGER_ALIYUNCAS_ACCESSKEYID="your-access-key-id" \ |
| 40 | + --CERTIMATE_SSLMANAGER_ALIYUNCAS_ACCESSKEYSECRET="your-access-key-secret" \ |
| 41 | + --CERTIMATE_SSLMANAGER_ALIYUNCAS_REGION="cn-hangzhou" |
| 42 | +*/ |
| 43 | +func TestDeploy(t *testing.T) { |
| 44 | + flag.Parse() |
| 45 | + |
| 46 | + t.Run("Deploy", func(t *testing.T) { |
| 47 | + t.Log(strings.Join([]string{ |
| 48 | + "args:", |
| 49 | + fmt.Sprintf("INPUTCERTPATH: %v", fInputCertPath), |
| 50 | + fmt.Sprintf("INPUTKEYPATH: %v", fInputKeyPath), |
| 51 | + fmt.Sprintf("ACCESSKEYID: %v", fAccessKeyId), |
| 52 | + fmt.Sprintf("ACCESSKEYSECRET: %v", fAccessKeySecret), |
| 53 | + fmt.Sprintf("REGION: %v", fRegion), |
| 54 | + }, "\n")) |
| 55 | + |
| 56 | + sslmanager, err := provider.NewSSLManagerProvider(&provider.SSLManagerProviderConfig{ |
| 57 | + AccessKeyId: fAccessKeyId, |
| 58 | + AccessKeySecret: fAccessKeySecret, |
| 59 | + Region: fRegion, |
| 60 | + }) |
| 61 | + if err != nil { |
| 62 | + t.Errorf("err: %+v", err) |
| 63 | + return |
| 64 | + } |
| 65 | + |
| 66 | + fInputCertData, _ := os.ReadFile(fInputCertPath) |
| 67 | + fInputKeyData, _ := os.ReadFile(fInputKeyPath) |
| 68 | + res, err := sslmanager.Upload(context.Background(), string(fInputCertData), string(fInputKeyData)) |
| 69 | + if err != nil { |
| 70 | + t.Errorf("err: %+v", err) |
| 71 | + return |
| 72 | + } |
| 73 | + |
| 74 | + sres, _ := json.Marshal(res) |
| 75 | + t.Logf("ok: %s", string(sres)) |
| 76 | + }) |
| 77 | +} |
0 commit comments