Skip to content

Commit af1a8ae

Browse files
committed
filecoin: test node validation
1 parent 4225df1 commit af1a8ae

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package v1alpha1
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/kotalco/kotal/apis/shared"
7+
. "github.com/onsi/ginkgo"
8+
. "github.com/onsi/gomega"
9+
"k8s.io/apimachinery/pkg/api/errors"
10+
"k8s.io/apimachinery/pkg/util/validation/field"
11+
)
12+
13+
var _ = Describe("Filecoin node validation", func() {
14+
15+
updateCases := []struct {
16+
Title string
17+
OldNode *Node
18+
NewNode *Node
19+
Errors field.ErrorList
20+
}{
21+
{
22+
Title: "network #1",
23+
OldNode: &Node{
24+
Spec: NodeSpec{
25+
Network: MainNetwork,
26+
},
27+
},
28+
NewNode: &Node{
29+
Spec: NodeSpec{
30+
Network: NerpaNetwork,
31+
},
32+
},
33+
Errors: field.ErrorList{
34+
{
35+
Type: field.ErrorTypeInvalid,
36+
Field: "spec.network",
37+
BadValue: NerpaNetwork,
38+
Detail: "field is immutable",
39+
},
40+
},
41+
},
42+
}
43+
44+
Context("While updating node", func() {
45+
for _, c := range updateCases {
46+
func() {
47+
cc := c
48+
It(fmt.Sprintf("Should validate %s", cc.Title), func() {
49+
cc.NewNode.Default()
50+
err := cc.NewNode.ValidateUpdate(cc.OldNode)
51+
52+
errStatus := err.(*errors.StatusError)
53+
54+
causes := shared.ErrorsToCauses(cc.Errors)
55+
56+
Expect(errStatus.ErrStatus.Details.Causes).To(ContainElements(causes))
57+
})
58+
}()
59+
}
60+
})
61+
62+
})

0 commit comments

Comments
 (0)