Files
kubescape/core/cautils/getter/kscloudapi_test.go
Amir Malka 592e0e2b43 Service discovery (#1359)
* remove hardcoded urls

Signed-off-by: Amir Malka <amirm@armosec.io>

* update

Signed-off-by: Amir Malka <amirm@armosec.io>

* fix test

Signed-off-by: Amir Malka <amirm@armosec.io>

* update providers docs

Signed-off-by: Amir Malka <amirm@armosec.io>

* fix

Signed-off-by: Amir Malka <amirm@armosec.io>

* hardcoded systests branch

Signed-off-by: Amir Malka <amirm@armosec.io>

* fix

Signed-off-by: Amir Malka <amirm@armosec.io>

* added logs

Signed-off-by: Amir Malka <amirm@armosec.io>

* added logs

Signed-off-by: Amir Malka <amirm@armosec.io>

* create config path if it does not exist

Signed-off-by: Amir Malka <amirm@armosec.io>

* fix

Signed-off-by: Amir Malka <amirm@armosec.io>

* fix

Signed-off-by: Amir Malka <amirm@armosec.io>

---------

Signed-off-by: Amir Malka <amirm@armosec.io>
2023-08-30 09:54:50 +03:00

50 lines
1.1 KiB
Go

package getter
import (
"os"
"sync"
"testing"
v1 "github.com/kubescape/backend/pkg/client/v1"
"github.com/stretchr/testify/require"
)
const (
// extra mock API routes
pathTestPost = "/test-post"
pathTestDelete = "/test-delete"
pathTestGet = "/test-get"
)
var (
globalMx sync.Mutex // a mutex to avoid data races on package globals while testing
testOptions = []v1.KSCloudOption{
v1.WithTrace(os.Getenv("DEBUG_TEST") != ""),
}
)
func TestGlobalKSCloudAPIConnector(t *testing.T) {
t.Parallel()
globalMx.Lock()
defer globalMx.Unlock()
globalKSCloudAPIConnector = nil
t.Run("uninitialized global connector should yield an empty KS client", func(t *testing.T) {
empty := v1.NewEmptyKSCloudAPI()
require.EqualValues(t, empty, GetKSCloudAPIConnector())
})
t.Run("initialized global connector should yield the same pointer", func(t *testing.T) {
ksCloud, _ := v1.NewKSCloudAPI("test-123", "test-456", "account")
SetKSCloudAPIConnector(ksCloud)
client := GetKSCloudAPIConnector()
require.Equal(t, ksCloud, client)
require.Equal(t, client, GetKSCloudAPIConnector())
})
}