|
| 1 | +/* |
| 2 | +Copyright 2020 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package smb |
| 18 | + |
| 19 | +import ( |
| 20 | + "bytes" |
| 21 | + "context" |
| 22 | + "flag" |
| 23 | + "github.com/container-storage-interface/spec/lib/go/csi" |
| 24 | + "github.com/stretchr/testify/assert" |
| 25 | + "k8s.io/klog" |
| 26 | + "testing" |
| 27 | +) |
| 28 | + |
| 29 | +func TestNodeStageVolume(t *testing.T) { |
| 30 | + |
| 31 | + klog.InitFlags(nil) |
| 32 | + if e := flag.Set("logtostderr", "false"); e != nil { |
| 33 | + t.Error(e) |
| 34 | + } |
| 35 | + if e := flag.Set("alsologtostderr", "false"); e != nil { |
| 36 | + t.Error(e) |
| 37 | + } |
| 38 | + if e := flag.Set("v", "100"); e != nil { |
| 39 | + t.Error(e) |
| 40 | + } |
| 41 | + flag.Parse() |
| 42 | + |
| 43 | + buf := new(bytes.Buffer) |
| 44 | + klog.SetOutput(buf) |
| 45 | + |
| 46 | + d := NewFakeDriver() |
| 47 | + |
| 48 | + tests := []struct { |
| 49 | + name string |
| 50 | + req *csi.NodeStageVolumeRequest |
| 51 | + expStr string |
| 52 | + }{ |
| 53 | + { |
| 54 | + "with secrets", |
| 55 | + &csi.NodeStageVolumeRequest{ |
| 56 | + VolumeId: "vol_1", |
| 57 | + Secrets: map[string]string{ |
| 58 | + "password": "testpassword", |
| 59 | + "username": "testuser", |
| 60 | + }, |
| 61 | + VolumeCapability: &csi.VolumeCapability{}, |
| 62 | + XXX_sizecache: 100, |
| 63 | + }, |
| 64 | + `NodeStageVolume called with request {vol_1 map[] map[password:**** username:testuser] map[] {} [] 100}`, |
| 65 | + }, |
| 66 | + } |
| 67 | + |
| 68 | + for _, test := range tests { |
| 69 | + t.Run(test.name, func(t *testing.T) { |
| 70 | + // EXECUTE |
| 71 | + _, _ = d.NodeStageVolume(context.Background(), test.req) |
| 72 | + klog.Flush() |
| 73 | + |
| 74 | + //ASSERT |
| 75 | + assert.Contains(t, buf.String(), test.expStr) |
| 76 | + |
| 77 | + // CLEANUP |
| 78 | + buf.Reset() |
| 79 | + }) |
| 80 | + } |
| 81 | + |
| 82 | +} |
0 commit comments