|
18 | 18 | package transform |
19 | 19 |
|
20 | 20 | import ( |
| 21 | + "errors" |
21 | 22 | "os" |
22 | 23 | "path" |
23 | 24 | "testing" |
24 | 25 |
|
25 | 26 | "github.com/netobserv/flowlogs-pipeline/pkg/api" |
26 | 27 | "github.com/netobserv/flowlogs-pipeline/pkg/config" |
| 28 | + "github.com/netobserv/flowlogs-pipeline/pkg/pipeline/transform/kubernetes" |
27 | 29 | "github.com/netobserv/flowlogs-pipeline/pkg/pipeline/transform/location" |
28 | 30 | netdb "github.com/netobserv/flowlogs-pipeline/pkg/pipeline/transform/netdb" |
29 | 31 | "github.com/netobserv/flowlogs-pipeline/pkg/test" |
| 32 | + "github.com/stretchr/testify/assert" |
30 | 33 | "github.com/stretchr/testify/require" |
31 | 34 | ) |
32 | 35 |
|
@@ -325,3 +328,41 @@ func Test_Transform_AddIfScientificNotation(t *testing.T) { |
325 | 328 | require.Equal(t, true, output["dir_Evaluate"]) |
326 | 329 | require.Equal(t, "out", output["dir"]) |
327 | 330 | } |
| 331 | + |
| 332 | +func TestTransform_K8sEmptyNamespace(t *testing.T) { |
| 333 | + kubernetes.Data = &fakeKubeData{} |
| 334 | + nt := Network{ |
| 335 | + TransformNetwork: api.TransformNetwork{ |
| 336 | + Rules: api.NetworkTransformRules{{ |
| 337 | + Type: api.OpAddKubernetes, |
| 338 | + Input: "SrcAddr", |
| 339 | + Output: "SrcK8s", |
| 340 | + }, { |
| 341 | + Type: api.OpAddKubernetes, |
| 342 | + Input: "DstAddr", |
| 343 | + Output: "DstK8s", |
| 344 | + }}, |
| 345 | + }, |
| 346 | + } |
| 347 | + // We need to check that, whether it returns NotFound or just an empty namespace, |
| 348 | + // there is no map entry for that namespace (an empty-valued map entry is not valid) |
| 349 | + out, _ := nt.Transform(config.GenericMap{ |
| 350 | + "SrcAddr": "1.2.3.4", // would return an empty namespace |
| 351 | + "DstAddr": "3.2.1.0", // would return NotFound |
| 352 | + }) |
| 353 | + assert.NotContains(t, out, "SrcK8s_Namespace") |
| 354 | + assert.NotContains(t, out, "DstK8s_Namespace") |
| 355 | +} |
| 356 | + |
| 357 | +type fakeKubeData struct{} |
| 358 | + |
| 359 | +func (d *fakeKubeData) InitFromConfig(_ string) error { |
| 360 | + return nil |
| 361 | +} |
| 362 | +func (*fakeKubeData) GetInfo(n string) (*kubernetes.Info, error) { |
| 363 | + // If found, returns an empty info (empty namespace) |
| 364 | + if n == "1.2.3.4" { |
| 365 | + return &kubernetes.Info{}, nil |
| 366 | + } |
| 367 | + return nil, errors.New("notFound") |
| 368 | +} |
0 commit comments