| 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 |
"testing" |
| 21 |
|
| 22 |
. "github.com/onsi/ginkgo/v2" |
| 23 |
. "github.com/onsi/gomega" |
| 24 |
"github.com/onsi/gomega/gexec" |
| 25 |
) |
| 26 |
|
| 27 |
func TestLibcni(t *testing.T) { |
| 28 |
RegisterFailHandler(Fail) |
| 29 |
RunSpecs(t, "Libcni Suite") |
| 30 |
} |
| 31 |
|
| 32 |
var pluginPackages = map[string]string{ |
| 33 |
"noop": "github.com/containernetworking/cni/plugins/test/noop", |
| 34 |
"sleep": "github.com/containernetworking/cni/plugins/test/sleep", |
| 35 |
} |
| 36 |
|
| 37 |
var ( |
| 38 |
pluginPaths map[string]string |
| 39 |
pluginDirs []string // array of plugin dirs |
| 40 |
) |
| 41 |
|
| 42 |
var _ = SynchronizedBeforeSuite(func() []byte { |
| 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 |
}) |