Skip to content

Commit

Permalink
Fix typo.
Browse files Browse the repository at this point in the history
  • Loading branch information
q-uint committed May 29, 2024
1 parent 2d16808 commit 1e0635b
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
test:
go test -v -cover ./...

test-registry:
REGISTRY_TEST_ENABLE=true go test -v -cover ./registry/...

check-moc:
find ic -type f -name '*.mo' -print0 | xargs -0 $(shell dfx cache show)/moc --check

Expand Down
48 changes: 46 additions & 2 deletions registry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (c *Client) GetNNSSubnetID() (*principal.Principal, error) {
return &principal.Principal{Raw: nnsSubnetID.PrincipalId.Raw}, nil
}

func (c *Client) GetNodeListSince(version uint64) (map[string]NodeDetails, error) {
func (c *Client) GetNodeListSince(version uint64) (NodeMap, error) {
nnsSubnetID, err := c.GetNNSSubnetID()
if err != nil {
return nil, err
Expand Down Expand Up @@ -93,7 +93,7 @@ func (c *Client) GetNodeListSince(version uint64) (map[string]NodeDetails, error
var nodeProviderID principal.Principal
var dcID string
if no, ok := nodeOperatorMap[nodeOperatorID.String()]; ok {
nodeProviderID = principal.Principal{Raw: no.NodeOperatorPrincipalId}
nodeProviderID = principal.Principal{Raw: no.NodeProviderPrincipalId}
dcID = no.DcId
}
var ipv6 string
Expand Down Expand Up @@ -164,6 +164,8 @@ func (c *Client) GetSubnetPublicKey(subnetID principal.Principal) ([]byte, error
return certification.PublicKeyToDER(publicKey.KeyValue)
}

type DataCenterMap map[string][]NodeDetails

type IPv4Interface struct {
Address string
Gateways []string
Expand All @@ -179,3 +181,45 @@ type NodeDetails struct {
HostOSVersionID *string
Domain *string
}

type NodeMap map[string]NodeDetails

func (n NodeMap) ByDataCenter() DataCenterMap {
dcMap := make(map[string][]NodeDetails)
for _, node := range n {
if v, ok := dcMap[node.DCID]; ok {
dcMap[node.DCID] = append(v, node)
} else {
dcMap[node.DCID] = []NodeDetails{node}
}
}
return dcMap
}

func (n NodeMap) ByNodeOperator() NodeOperatorMap {
noMap := make(map[string][]NodeDetails)
for _, node := range n {
if v, ok := noMap[node.NodeOperatorID.String()]; ok {
noMap[node.NodeOperatorID.String()] = append(v, node)
} else {
noMap[node.NodeOperatorID.String()] = []NodeDetails{node}
}
}
return noMap
}

func (n NodeMap) ByNodeProvider() NodeProviderMap {
npMap := make(map[string][]NodeDetails)
for _, node := range n {
if v, ok := npMap[node.NodeProviderID.String()]; ok {
npMap[node.NodeProviderID.String()] = append(v, node)
} else {
npMap[node.NodeProviderID.String()] = []NodeDetails{node}
}
}
return npMap
}

type NodeOperatorMap map[string][]NodeDetails

type NodeProviderMap map[string][]NodeDetails
24 changes: 24 additions & 0 deletions registry/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package registry

import (
"os"
"testing"
)

func TestClient_GetNodeListSince(t *testing.T) {
checkEnabled(t)
c, err := New()
if err != nil {
t.Fatal(err)
}
if _, err := c.GetNodeListSince(0); err != nil {
t.Fatal(err)
}
}

func checkEnabled(t *testing.T) {
// The reason for this is that the tests are very slow.
if os.Getenv("REGISTRY_TEST_ENABLE") != "true" {
t.Skip("Skipping registry tests. Set REGISTRY_TEST_ENABLE=true to enable.")
}
}
6 changes: 3 additions & 3 deletions registry/proto/v1/node.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1e0635b

Please sign in to comment.