Skip to content

Commit

Permalink
filecoin: test node validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mFarghaly committed Nov 20, 2020
1 parent 4225df1 commit af1a8ae
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions apis/filecoin/v1alpha1/node_validation_webhook_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package v1alpha1

import (
"fmt"

"github.com/kotalco/kotal/apis/shared"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/validation/field"
)

var _ = Describe("Filecoin node validation", func() {

updateCases := []struct {
Title string
OldNode *Node
NewNode *Node
Errors field.ErrorList
}{
{
Title: "network #1",
OldNode: &Node{
Spec: NodeSpec{
Network: MainNetwork,
},
},
NewNode: &Node{
Spec: NodeSpec{
Network: NerpaNetwork,
},
},
Errors: field.ErrorList{
{
Type: field.ErrorTypeInvalid,
Field: "spec.network",
BadValue: NerpaNetwork,
Detail: "field is immutable",
},
},
},
}

Context("While updating node", func() {
for _, c := range updateCases {
func() {
cc := c
It(fmt.Sprintf("Should validate %s", cc.Title), func() {
cc.NewNode.Default()
err := cc.NewNode.ValidateUpdate(cc.OldNode)

errStatus := err.(*errors.StatusError)

causes := shared.ErrorsToCauses(cc.Errors)

Expect(errStatus.ErrStatus.Details.Causes).To(ContainElements(causes))
})
}()
}
})

})

0 comments on commit af1a8ae

Please sign in to comment.