github.com/baraj55/containernetworking-cni@v0.7.2-0.20200219164625-56ace59a9e7f/libcni/libcni_suite_test.go (about)

     1  // Copyright 2016 CNI authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package libcni_test
    16  
    17  import (
    18  	"encoding/json"
    19  	"path/filepath"
    20  
    21  	. "github.com/onsi/ginkgo"
    22  	. "github.com/onsi/gomega"
    23  	"github.com/onsi/gomega/gexec"
    24  
    25  	"testing"
    26  )
    27  
    28  func TestLibcni(t *testing.T) {
    29  	RegisterFailHandler(Fail)
    30  	RunSpecs(t, "Libcni Suite")
    31  }
    32  
    33  var pluginPackages = map[string]string{
    34  	"noop":  "github.com/containernetworking/cni/plugins/test/noop",
    35  	"sleep": "github.com/containernetworking/cni/plugins/test/sleep",
    36  }
    37  
    38  var pluginPaths map[string]string
    39  var pluginDirs []string // array of plugin dirs
    40  
    41  var _ = SynchronizedBeforeSuite(func() []byte {
    42  
    43  	paths := map[string]string{}
    44  	for name, packagePath := range pluginPackages {
    45  		execPath, err := gexec.Build(packagePath)
    46  		Expect(err).NotTo(HaveOccurred())
    47  		paths[name] = execPath
    48  	}
    49  	crossNodeData, err := json.Marshal(paths)
    50  	Expect(err).NotTo(HaveOccurred())
    51  
    52  	return crossNodeData
    53  }, func(crossNodeData []byte) {
    54  	Expect(json.Unmarshal(crossNodeData, &pluginPaths)).To(Succeed())
    55  	for _, pluginPath := range pluginPaths {
    56  		pluginDirs = append(pluginDirs, filepath.Dir(pluginPath))
    57  	}
    58  })
    59  
    60  var _ = SynchronizedAfterSuite(func() {}, func() {
    61  	gexec.CleanupBuildArtifacts()
    62  })