github.com/mccv1r0/cni@v0.7.0-alpha1/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  }
    36  
    37  var pluginPaths map[string]string
    38  var pluginDirs []string // array of plugin dirs
    39  
    40  var _ = SynchronizedBeforeSuite(func() []byte {
    41  
    42  	paths := map[string]string{}
    43  	for name, packagePath := range pluginPackages {
    44  		execPath, err := gexec.Build(packagePath)
    45  		Expect(err).NotTo(HaveOccurred())
    46  		paths[name] = execPath
    47  	}
    48  	crossNodeData, err := json.Marshal(paths)
    49  	Expect(err).NotTo(HaveOccurred())
    50  
    51  	return crossNodeData
    52  }, func(crossNodeData []byte) {
    53  	Expect(json.Unmarshal(crossNodeData, &pluginPaths)).To(Succeed())
    54  	for _, pluginPath := range pluginPaths {
    55  		pluginDirs = append(pluginDirs, filepath.Dir(pluginPath))
    56  	}
    57  })
    58  
    59  var _ = SynchronizedAfterSuite(func() {}, func() {
    60  	gexec.CleanupBuildArtifacts()
    61  })