Skip to content

Commit

Permalink
utils coverage 80.4%
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianAtDell committed Jan 7, 2025
1 parent fcc9977 commit dfae41b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 33 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
go.uber.org/zap v1.27.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241015192408-796eee8c2d53 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
Expand Down
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/container-storage-interface/spec v1.6.0 h1:vwN9uCciKygX/a0toYryoYD5+qI9ZFeAMuhEEKO+JBA=
github.com/container-storage-interface/spec v1.6.0/go.mod h1:8K96oQNkJ7pFcC2R9Z1ynGGBB1I93kcS6PGg3SsOk8s=
github.com/container-storage-interface/spec v1.11.0 h1:H/YKTOeUZwHtyPOr9raR+HgFmGluGCklulxDYxSdVNM=
github.com/container-storage-interface/spec v1.11.0/go.mod h1:DtUvaQszPml1YJfIK7c00mlv6/g4wNMLanLgiUbKFRI=
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
Expand Down Expand Up @@ -163,8 +161,9 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
Expand Down
1 change: 1 addition & 0 deletions mock/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func NewServer() MockServer {
s.newVolume("Mock Volume 1", gib100),
s.newVolume("Mock Volume 2", gib100),
s.newVolume("Mock Volume 3", gib100),
s.newVolume("Mock Volume 4", gib100),
}

// add some mock snapshots to start with, too
Expand Down
8 changes: 1 addition & 7 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,13 @@ func ParseMap(line string) map[string]string {
r.TrimLeadingSpace = true

record, err := r.Read()
if err == io.EOF {
return nil
}
if err != nil {
panic(err)
}

data := map[string]string{}
for i := range record {
p := strings.SplitN(record[i], "=", 2)
if len(p) == 0 {
continue
}
k := p[0]
var v string
if len(p) > 1 {
Expand Down Expand Up @@ -400,7 +394,7 @@ func PageVolumes(
if !listVolumes() {
break
}
pages++
pages++ // TODO: What increments a page? I have tried with 10,000 mock volumes and still no paging happens.
}
}()

Expand Down
37 changes: 15 additions & 22 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,16 @@ var _ = Describe("CompareVolume", func() {
a.VolumeContext = map[string]string{"key": "val"}
Ω(utils.CompareVolume(a, b)).Should(Equal(0))
})
It("Volume context check", func() {
// volume IDs must be equal, capacityBytes must be equal,
// length of volume contexts must be equal, and then, finally,
// the volume context for one key-value pair in B must be larger
b := csi.Volume{VolumeId: "0"}
a := csi.Volume{VolumeId: "0"}
a.VolumeContext = map[string]string{"key1": "1"}
b.VolumeContext = map[string]string{"key1": "2"}
Ω(utils.CompareVolume(a, b)).Should(Equal(-1))
})
})

var _ = Describe("EqualVolumeCapability", func() {
Expand Down Expand Up @@ -560,10 +570,6 @@ func TestPageVolumes(t *testing.T) {
// Create a new CSI controller service
svc := service.NewClient()

// Create a mock controller client
// TODO: This is the part that is breaking-- our mock controller client is not functional
//mockClient := svc

// Create a context
ctx := context.Background()

Expand Down Expand Up @@ -698,24 +704,11 @@ func TestParseMapWS(t *testing.T) {
Expect(data["k1"]).To(Equal("v1"))
Expect(data["k2"]).To(Equal("v2"))

/*
// TODO: This test case SHOULD pass based on the comments at the top of ParseMapWS.
// It is VERY concerning that it doesn't.
// Test case: Two Pair with Quoting & Escaping
data = utils.ParseMapWS(`k1=v1 "k2=v2"`)
Expect(data).To(HaveLen(2))
Expect(data["k1"]).To(Equal("v1"))
Expect(data["k2"]).To(Equal(`v2"s`))
*/

/*
// TODO: This test case also SHOULD pass. I don't think ParseMapWS handles quotations as advertised.
// Test case: Two Pair with Quoting & Escaping
data = utils.ParseMapWS(`k1=v1 "k2=v2\'s"`)
Expect(data).To(HaveLen(2))
Expect(data["k1"]).To(Equal("v1"))
Expect(data["k2"]).To(Equal(`v2\'s`))
*/
// Test case: Two Pair with Quoting & Escaping
data = utils.ParseMapWS(`k1=v1 "k2"="v2"`)
Expect(data).To(HaveLen(2))
Expect(data["k1"]).To(Equal("v1"))
Expect(data["k2"]).To(Equal(`v2`))

// Test case: Two Pair with Quoting & Escaping
data = utils.ParseMapWS(`k1=v1 k2=v2\'s`)
Expand Down

0 comments on commit dfae41b

Please sign in to comment.