Skip to content

Commit

Permalink
protosanitizer: remove package dependency on CSI
Browse files Browse the repository at this point in the history
The test code must be conceptually in a different package, otherwise
the "protosanitizer" package depends on the CSI 1.0 package and cannot
be vendored into a client relying on an older version of the spec, not
even when stripping of go test code is enabled - at least "dep" checks
package dependencies before stripping.

The downside of moving the tests is that a manual "go test
./protosanitizer" no longer runs the test. They are still run by "make
test":

$ make test
go test `go list ./... | grep -v ^vendor`
?   	github.com/kubernetes-csi/csi-lib-utils/protosanitizer	[no test files]
ok  	github.com/kubernetes-csi/csi-lib-utils/protosanitizer/test	0.051s
?   	github.com/kubernetes-csi/csi-lib-utils/protosanitizer/test/csi03	[no test files]
?   	github.com/kubernetes-csi/csi-lib-utils/protosanitizer/test/csitest	[no test files]
  • Loading branch information
pohly committed Dec 6, 2018
1 parent 67f76c8 commit 58ee530
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package protosanitizer
package protosanitizer_test

import (
"fmt"
"testing"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/protobuf/proto"
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer"
csi03 "github.com/kubernetes-csi/csi-lib-utils/protosanitizer/test/csi03"
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer/test/csitest"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -205,9 +206,9 @@ func TestStripSecrets(t *testing.T) {
before := fmt.Sprint(c.original)
var stripped fmt.Stringer
if _, ok := c.original.(*csi03.CreateVolumeRequest); ok {
stripped = StripSecretsCSI03(c.original)
stripped = protosanitizer.StripSecretsCSI03(c.original)
} else {
stripped = StripSecrets(c.original)
stripped = protosanitizer.StripSecrets(c.original)
}
if assert.Equal(t, c.stripped, fmt.Sprintf("%s", stripped), "unexpected result for fmt s of %s", c.original) {
assert.Equal(t, c.stripped, fmt.Sprintf("%v", stripped), "unexpected result for fmt v of %s", c.original)
Expand All @@ -216,7 +217,7 @@ func TestStripSecrets(t *testing.T) {
}

// The secret is hidden because StripSecrets is a struct referencing it.
dump := fmt.Sprintf("%#v", StripSecrets(createVolume))
dump := fmt.Sprintf("%#v", protosanitizer.StripSecrets(createVolume))
assert.NotContains(t, dump, secretName)
assert.NotContains(t, dump, secretValue)
}

0 comments on commit 58ee530

Please sign in to comment.