talos/pkg/resources/network/network_test.go
Andrey Smirnov 83fdb7721f
feat: provide first NIC hardware addr as a resource
This will be used to derive e.g. KubeSpan address.

Fixes #4132

Example:

```
$ talosctl -n 172.20.0.2 get hardwareaddresses -o yaml
node: 172.20.0.2
metadata:
    namespace: network
    type: HardwareAddresses.net.talos.dev
    id: first
    version: 1
    owner: network.HardwareAddrController
    phase: running
    created: 2021-08-24T20:30:43Z
    updated: 2021-08-24T20:30:43Z
spec:
    name: eth0
    hardwareAddr: 6a:2b:bd:b2:fc:e0
```

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
2021-08-25 17:11:24 +03:00

49 lines
1.3 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package network_test
import (
"context"
"testing"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/state"
"github.com/cosi-project/runtime/pkg/state/impl/inmem"
"github.com/cosi-project/runtime/pkg/state/impl/namespaced"
"github.com/cosi-project/runtime/pkg/state/registry"
"github.com/stretchr/testify/assert"
"github.com/talos-systems/talos/pkg/resources/network"
)
func TestRegisterResource(t *testing.T) {
ctx := context.TODO()
resources := state.WrapCore(namespaced.NewState(inmem.Build))
resourceRegistry := registry.NewResourceRegistry(resources)
for _, resource := range []resource.Resource{
&network.AddressStatus{},
&network.AddressSpec{},
&network.HardwareAddr{},
&network.HostnameStatus{},
&network.HostnameSpec{},
&network.LinkRefresh{},
&network.LinkStatus{},
&network.LinkSpec{},
&network.NodeAddress{},
&network.OperatorSpec{},
&network.ResolverStatus{},
&network.ResolverSpec{},
&network.RouteStatus{},
&network.RouteSpec{},
&network.Status{},
&network.TimeServerStatus{},
&network.TimeServerSpec{},
} {
assert.NoError(t, resourceRegistry.Register(ctx, resource))
}
}