1- package client
1+ package client_test
22
33import (
44 "os"
@@ -9,36 +9,58 @@ import (
99 "k8s.io/klog/v2/ktesting"
1010
1111 "github.com/jetstack/preflight/api"
12+ "github.com/jetstack/preflight/pkg/client"
13+ "github.com/jetstack/preflight/pkg/testutil"
1214
1315 _ "k8s.io/klog/v2/ktesting/init"
1416)
1517
16- func TestCyberArkClient_PostDataReadingsWithOptions (t * testing.T ) {
17- // TestCyberArkClient_PostDataReadingsWithOptions/RealAPI demonstrates that the
18- // dataupload code works with the real inventory API.
19- //
20- // To enable verbose request logging:
21- //
22- // go test ./pkg/internal/cyberark/dataupload/... \
23- // -v -count 1 -run TestPostDataReadingsWithOptionsWithRealAPI -args -testing.v 6
24- t .Run ("RealAPI" , func (t * testing.T ) {
25- platformDomain := os .Getenv ("ARK_PLATFORM_DOMAIN" )
18+ func TestCyberArkClient_PostDataReadingsWithOptions_MockAPI (t * testing.T ) {
19+ t .Setenv ("ARK_SUBDOMAIN" , "dummy-subdomain" )
20+ t .Setenv ("ARK_USERNAME" , "dummy-username" )
21+ t .Setenv ("ARK_SECRET" , "dummy-secret" )
22+ t .Run ("success" , func (t * testing.T ) {
23+ logger := ktesting .NewLogger (t , ktesting .DefaultConfig )
24+ ctx := klog .NewContext (t .Context (), logger )
25+
26+ server , serverCert := testutil .FakeCyberArk (t )
27+ t .Setenv ("ARK_DISCOVERY_API" , server .URL )
28+ cl , err := client .NewCyberArk ()
29+ require .NoError (t , err )
30+
31+ testutil .TrustCA (t , cl , serverCert )
32+
33+ var readings []* api.DataReading
34+ err = cl .PostDataReadingsWithOptions (ctx , readings , client.Options {})
35+ require .NoError (t , err )
36+ })
37+ }
38+
39+ // TestCyberArkClient_PostDataReadingsWithOptions_RealAPI demonstrates that the
40+ // dataupload code works with the real inventory API.
41+ //
42+ // To enable verbose request logging:
43+ //
44+ // go test ./pkg/internal/cyberark/dataupload/... \
45+ // -v -count 1 -run TestCyberArkClient_PostDataReadingsWithOptions_RealAPI -args -testing.v 6
46+ func TestCyberArkClient_PostDataReadingsWithOptions_RealAPI (t * testing.T ) {
47+ t .Run ("success" , func (t * testing.T ) {
2648 subdomain := os .Getenv ("ARK_SUBDOMAIN" )
2749 username := os .Getenv ("ARK_USERNAME" )
2850 secret := os .Getenv ("ARK_SECRET" )
2951
30- if platformDomain == "" || subdomain == "" || username == "" || secret == "" {
31- t .Skip ("Skipping because one of the following environment variables is unset or empty: ARK_PLATFORM_DOMAIN, ARK_SUBDOMAIN, ARK_USERNAME, ARK_SECRET" )
52+ if subdomain == "" || username == "" || secret == "" {
53+ t .Skip ("Skipping because one of the following environment variables is unset or empty: ARK_SUBDOMAIN, ARK_USERNAME, ARK_SECRET" )
3254 return
3355 }
3456
3557 logger := ktesting .NewLogger (t , ktesting .DefaultConfig )
3658 ctx := klog .NewContext (t .Context (), logger )
3759
38- c , err := NewCyberArk ()
60+ c , err := client . NewCyberArk ()
3961 require .NoError (t , err )
4062 var readings []* api.DataReading
41- err = c .PostDataReadingsWithOptions (ctx , readings , Options {})
63+ err = c .PostDataReadingsWithOptions (ctx , readings , client. Options {})
4264 require .NoError (t , err )
4365 })
4466}
0 commit comments