github.com/nmstate/kubernetes-nmstate@v0.82.0/test/e2e/handler/examples_test.go (about) 1 /* 2 Copyright The Kubernetes NMState Authors. 3 4 5 Licensed under the Apache License, Version 2.0 (the "License"); 6 you may not use this file except in compliance with the License. 7 You may obtain a copy of the License at 8 9 http://www.apache.org/licenses/LICENSE-2.0 10 11 Unless required by applicable law or agreed to in writing, software 12 distributed under the License is distributed on an "AS IS" BASIS, 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 See the License for the specific language governing permissions and 15 limitations under the License. 16 */ 17 18 package handler 19 20 import ( 21 "fmt" 22 23 . "github.com/onsi/ginkgo/v2" 24 25 nmstate "github.com/nmstate/kubernetes-nmstate/api/shared" 26 example "github.com/nmstate/kubernetes-nmstate/test/doc" 27 ) 28 29 // This suite checks that all examples in our docs can be successfully applied. 30 // It only checks the top level API, hence it does not verify that the 31 // configuration is indeed applied on nodes. That should be tested by dedicated 32 // test suites for each feature. 33 var _ = Describe("[user-guide] Examples", func() { 34 35 beforeTestIfaceExample := func(fileName string) { 36 kubectlAndCheck("apply", "-f", fmt.Sprintf("docs/examples/%s", fileName)) 37 } 38 39 testIfaceExample := func(policyName string) { 40 kubectlAndCheck("wait", "nncp", policyName, "--for", "condition=Available", "--timeout", "2m") 41 } 42 43 afterIfaceExample := func(policyName string, ifaceNames []string, cleanupState *nmstate.State) { 44 deletePolicy(policyName) 45 46 if len(ifaceNames) > 0 { 47 for _, ifaceName := range ifaceNames { 48 updateDesiredStateAndWait(interfaceAbsent(ifaceName)) 49 } 50 } 51 52 if cleanupState != nil { 53 updateDesiredStateAndWait(*cleanupState) 54 } 55 56 resetDesiredStateForNodes() 57 } 58 59 for _, e := range example.ExampleSpecs() { 60 example := e 61 Context(e.Name, func() { 62 BeforeEach(func() { 63 beforeTestIfaceExample(example.FileName) 64 }) 65 66 AfterEach(func() { 67 afterIfaceExample(example.PolicyName, example.IfaceNames, example.CleanupState) 68 }) 69 70 It("should succeed applying the policy", func() { 71 testIfaceExample(example.PolicyName) 72 }) 73 }) 74 } 75 })