-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Matthias Bertschy <[email protected]>
- Loading branch information
Showing
2 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/armosec/utils-k8s-go/armometadata" | ||
"github.com/kubescape/backend/pkg/servicediscovery/schema" | ||
v2 "github.com/kubescape/backend/pkg/servicediscovery/v2" | ||
pulsarconfig "github.com/kubescape/messaging/pulsar/config" | ||
"github.com/kubescape/synchronizer/domain" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLoadClusterConfig(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
want armometadata.ClusterConfig | ||
wantErr bool | ||
}{ | ||
// TODO: Add test cases. | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := LoadClusterConfig() | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("LoadClusterConfig() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("LoadClusterConfig() got = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
path string | ||
want Config | ||
}{ | ||
{ | ||
name: "client config", | ||
path: "../configuration/client", | ||
want: Config{ | ||
InCluster: InCluster{ | ||
ServerUrl: "ws://127.0.0.1:8080/", | ||
ClusterName: "cluster-1", | ||
Account: "11111111-2222-3333-4444-11111111", | ||
AccessKey: "xxxxxxxx-1111-1111-1111-xxxxxxxx", | ||
Resources: []Resource{ | ||
{Group: "apps", Version: "v1", Resource: "deployments", Strategy: "patch"}, | ||
{Group: "", Version: "v1", Resource: "pods", Strategy: "patch"}, | ||
{Group: "spdx.softwarecomposition.kubescape.io", Version: "v1beta1", Resource: "sbomspdxv2p3s", Strategy: "copy"}, | ||
{Group: "spdx.softwarecomposition.kubescape.io", Version: "v1beta1", Resource: "sbomspdxv2p3filtereds", Strategy: "copy"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "server config", | ||
path: "../configuration/server", | ||
want: Config{ | ||
Backend: Backend{ | ||
AuthenticationServer: &AuthenticationServerConfig{ | ||
Url: "https://api.armosec.io/api/v1", | ||
HeaderToQueryParamMapping: map[string]string{"x-api-account": "customerGUID"}, | ||
HeaderToHeaderMapping: map[string]string{"x-api-key": "X-API-KEY"}, | ||
}, | ||
Subscription: "subscription", | ||
PulsarConfig: &pulsarconfig.PulsarConfig{ | ||
URL: "pulsar://localhost:6650", | ||
Tenant: "kubescape", | ||
Namespace: "kubescape", | ||
AdminUrl: "http://localhost:8081", | ||
Clusters: []string{"standalone"}, | ||
RedeliveryDelaySeconds: 0, | ||
MaxDeliveryAttempts: 2, | ||
}, | ||
Topic: "synchronizer", | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := LoadConfig(tt.path) | ||
assert.NoError(t, err) | ||
assert.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} | ||
|
||
func TestLoadServiceURLs(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
env map[string]string | ||
filePath string | ||
want schema.IBackendServices | ||
}{ | ||
{ | ||
name: "via filePath", | ||
filePath: "../configuration/services.json", | ||
want: &v2.ServicesV2{ | ||
EventReceiverHttpUrl: "https://er-test.com", | ||
EventReceiverWebsocketUrl: "wss://er-test.com", | ||
GatewayUrl: "https://gw.test.com", | ||
ApiServerUrl: "https://api.test.com", | ||
MetricsUrl: "https://metrics.test.com", | ||
SynchronizerUrl: "wss://synchronizer.test.com", | ||
}, | ||
}, | ||
{ | ||
name: "via env", | ||
env: map[string]string{"SERVICES": "../configuration/services.json"}, | ||
want: &v2.ServicesV2{ | ||
EventReceiverHttpUrl: "https://er-test.com", | ||
EventReceiverWebsocketUrl: "wss://er-test.com", | ||
GatewayUrl: "https://gw.test.com", | ||
ApiServerUrl: "https://api.test.com", | ||
MetricsUrl: "https://metrics.test.com", | ||
SynchronizerUrl: "wss://synchronizer.test.com", | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
for k, v := range tt.env { | ||
err := os.Setenv(k, v) | ||
assert.NoError(t, err) | ||
} | ||
got, err := LoadServiceURLs(tt.filePath) | ||
assert.NoError(t, err) | ||
assert.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} | ||
|
||
func TestResource_String(t *testing.T) { | ||
type fields struct { | ||
Group string | ||
Version string | ||
Resource string | ||
Strategy domain.Strategy | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
want string | ||
}{ | ||
// TODO: Add test cases. | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
r := Resource{ | ||
Group: tt.fields.Group, | ||
Version: tt.fields.Version, | ||
Resource: tt.fields.Resource, | ||
Strategy: tt.fields.Strategy, | ||
} | ||
if got := r.String(); got != tt.want { | ||
t.Errorf("String() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"version": "v2", | ||
"response": { | ||
"event-receiver-http": "https://er-test.com", | ||
"event-receiver-ws": "wss://er-test.com", | ||
"gateway": "https://gw.test.com", | ||
"api-server": "https://api.test.com", | ||
"metrics": "https://metrics.test.com", | ||
"synchronizer": "wss://synchronizer.test.com" | ||
} | ||
} |