| 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 diskscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/disk`/ |
| 16 | |
| 17 | import ( |
| 18 | "osscip-go gomod github.com/golang/go/src go1.24.2 os/" |
| 19 | "path/filepathscip-go gomod github.com/golang/go/src go1.24.2 `path/filepath`/" |
| 20 | |
| 21 | . "github.com/onsi/ginkgo/v2scip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/" |
| 22 | . "github.com/onsi/gomegascip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/" |
| 23 | ) |
| 24 | |
| 25 | var _ = Describescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Describe().("Lock Operations", func() { |
| 26 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("locks a file path", func() { |
| 27 | dir, err := osscip-go gomod github.com/golang/go/src go1.24.2 os/.MkdirTempscip-go gomod github.com/golang/go/src go1.24.2 os/MkdirTemp().("", "") |
| 28 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).ToNotscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#ToNot().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 29 | defer osscip-go gomod github.com/golang/go/src go1.24.2 os/.RemoveAllscip-go gomod github.com/golang/go/src go1.24.2 os/RemoveAll().(dir) |
| 30 | |
| 31 | // create a dummy file to lock |
| 32 | path := filepathscip-go gomod github.com/golang/go/src go1.24.2 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.2 `path/filepath`/Join().(dir, "x") |
| 33 | f, err := osscip-go gomod github.com/golang/go/src go1.24.2 os/.OpenFilescip-go gomod github.com/golang/go/src go1.24.2 os/OpenFile().(path, osscip-go gomod github.com/golang/go/src go1.24.2 os/.O_RDONLYscip-go gomod github.com/golang/go/src go1.24.2 os/O_RDONLY.|osscip-go gomod github.com/golang/go/src go1.24.2 os/.O_CREATEscip-go gomod github.com/golang/go/src go1.24.2 os/O_CREATE., 0o666) |
| 34 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).ToNotscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#ToNot().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 35 | err = f.Closescip-go gomod github.com/golang/go/src go1.24.2 os/File#Close().() |
| 36 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).ToNotscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#ToNot().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 37 | |
| 38 | // now use it to lock |
| 39 | m, err := NewFileLockscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/disk`/NewFileLock().(path) |
| 40 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).ToNotscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#ToNot().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 41 | |
| 42 | err = m.Lockscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/disk`/FileLock#Lock().() |
| 43 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).ToNotscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#ToNot().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 44 | err = m.Unlockscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/disk`/FileLock#Unlock().() |
| 45 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).ToNotscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#ToNot().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 46 | }) |
| 47 | |
| 48 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("locks a folder path", func() { |
| 49 | dir, err := osscip-go gomod github.com/golang/go/src go1.24.2 os/.MkdirTempscip-go gomod github.com/golang/go/src go1.24.2 os/MkdirTemp().("", "") |
| 50 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).ToNotscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#ToNot().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 51 | defer osscip-go gomod github.com/golang/go/src go1.24.2 os/.RemoveAllscip-go gomod github.com/golang/go/src go1.24.2 os/RemoveAll().(dir) |
| 52 | |
| 53 | // use the folder to lock |
| 54 | m, err := NewFileLockscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/disk`/NewFileLock().(dir) |
| 55 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).ToNotscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#ToNot().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 56 | |
| 57 | err = m.Lockscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/disk`/FileLock#Lock().() |
| 58 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).ToNotscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#ToNot().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 59 | err = m.Unlockscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/disk`/FileLock#Unlock().() |
| 60 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).ToNotscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#ToNot().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 61 | }) |
| 62 | }) |