diff --git a/changelog/unreleased/delete-sdk-tests.md b/changelog/unreleased/delete-sdk-tests.md new file mode 100644 index 0000000000..0388e79fe3 --- /dev/null +++ b/changelog/unreleased/delete-sdk-tests.md @@ -0,0 +1,6 @@ +Bugfix: Delete sdk unit tests + +These depend on a remote server running reva and thus fail in case of version +mismatches. + +https://github.com/cs3org/reva/pull/1333 diff --git a/pkg/sdk/common/common_test.go b/pkg/sdk/common/common_test.go deleted file mode 100644 index 7736be5332..0000000000 --- a/pkg/sdk/common/common_test.go +++ /dev/null @@ -1,182 +0,0 @@ -// Copyright 2018-2020 CERN -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// In applying this license, CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -package common_test - -import ( - "fmt" - "testing" - "time" - - types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" - - "github.com/cs3org/reva/pkg/sdk/common" - testintl "github.com/cs3org/reva/pkg/sdk/common/testing" -) - -func TestDataDescriptor(t *testing.T) { - const name = "DATA_DESC" - const size = 42 - - dataDesc := common.CreateDataDescriptor(name, size) - now := time.Now().Round(time.Millisecond) - if v := dataDesc.Name(); v != name { - t.Errorf(testintl.FormatTestResult("DataDescriptor.Name", name, v)) - } - if v := dataDesc.Size(); v != size { - t.Errorf(testintl.FormatTestResult("DataDescriptor.Size", size, v)) - } - if v := dataDesc.Mode(); v != 0700 { - t.Errorf(testintl.FormatTestResult("DataDescriptor.Mode", 0700, v)) - } - if v := dataDesc.IsDir(); v != false { - t.Errorf(testintl.FormatTestResult("DataDescriptor.IsDir", false, v)) - } - if v := dataDesc.ModTime(); !v.Round(time.Millisecond).Equal(now) { - // Since there's always a slight chance that the rounded times won't match, just log this mismatch - t.Logf(testintl.FormatTestResult("DataDescriptor.ModTime", now, v)) - } - if v := dataDesc.Sys(); v != nil { - t.Errorf(testintl.FormatTestResult("DataDescriptor.Sys", nil, v)) - } -} - -func TestFindString(t *testing.T) { - tests := []struct { - input []string - needle string - wants int - }{ - {[]string{}, "so empty", -1}, - {[]string{"12345", "hello", "goodbye"}, "hello", 1}, - {[]string{"Rudimentär", "Ich bin du", "Wüste", "SANDIGER GRUND"}, "Wüste", 2}, - {[]string{"Rudimentär", "Ich bin du", "Wüste", "SANDIGER GRUND", "Sandiger Grund"}, "Sandiger Grund", 4}, - {[]string{"Nachahmer", "Roger", "k thx bye"}, "thx", -1}, - {[]string{"Six Feet Under", "Rock&Roll", "k thx bye"}, "Six Feet Under", 0}, - {[]string{"Six Feet Under", "Rock&Roll", "k thx bye"}, "Six Feet UNDER", -1}, - } - - for _, test := range tests { - found := common.FindString(test.input, test.needle) - if found != test.wants { - t.Errorf(testintl.FormatTestResult("FindString", test.wants, found, test.input, test.needle)) - } - } -} - -func TestFindStringNoCase(t *testing.T) { - tests := []struct { - input []string - needle string - wants int - }{ - {[]string{}, "so empty", -1}, - {[]string{"12345", "hello", "goodbye"}, "hello", 1}, - {[]string{"Rudimentär", "Ich bin du", "Wüste", "SANDIGER GRUND"}, "Wüste", 2}, - {[]string{"Rudimentär", "Ich bin du", "Wüste", "SANDIGER GRUND", "Sandiger Grund"}, "Sandiger Grund", 3}, - {[]string{"Nachahmer", "Roger", "k thx bye"}, "thx", -1}, - {[]string{"Six Feet Under", "Rock&Roll", "k thx bye"}, "Six Feet Under", 0}, - {[]string{"Six Feet Under", "Rock&Roll", "k thx bye"}, "Six Feet UNDER", 0}, - } - - for _, test := range tests { - found := common.FindStringNoCase(test.input, test.needle) - if found != test.wants { - t.Errorf(testintl.FormatTestResult("FindString", test.wants, found, test.input, test.needle)) - } - } -} - -func TestDecodeOpaqueMap(t *testing.T) { - opaque := types.Opaque{ - Map: map[string]*types.OpaqueEntry{ - "magic": { - Decoder: "plain", - Value: []byte("42"), - }, - "json": { - Decoder: "json", - Value: []byte("[]"), - }, - }, - } - - tests := []struct { - key string - wants string - shouldSucceed bool - }{ - {"magic", "42", true}, - {"json", "[]", false}, - {"somekey", "", false}, - } - - decodedMap := common.DecodeOpaqueMap(&opaque) - for _, test := range tests { - value, ok := decodedMap[test.key] - if ok == test.shouldSucceed { - if ok { - if value != test.wants { - t.Errorf(testintl.FormatTestResult("DecodeOpaqueMap", test.wants, value, opaque)) - } - } - } else { - t.Errorf(testintl.FormatTestResult("DecodeOpaqueMap", test.shouldSucceed, ok, opaque)) - } - } -} - -func TestGetValuesFromOpaque(t *testing.T) { - opaque := types.Opaque{ - Map: map[string]*types.OpaqueEntry{ - "magic": { - Decoder: "plain", - Value: []byte("42"), - }, - "stuff": { - Decoder: "plain", - Value: []byte("Some stuff"), - }, - "json": { - Decoder: "json", - Value: []byte("[]"), - }, - }, - } - - tests := []struct { - keys []string - mandatory bool - shouldSucceed bool - }{ - {[]string{"magic", "stuff"}, true, true}, - {[]string{"magic", "stuff", "json"}, false, true}, - {[]string{"magic", "stuff", "json"}, true, false}, - {[]string{"notfound"}, false, true}, - {[]string{"notfound"}, true, false}, - } - - for _, test := range tests { - _, err := common.GetValuesFromOpaque(&opaque, test.keys, test.mandatory) - if err != nil && test.shouldSucceed { - t.Errorf(testintl.FormatTestError("GetValuesFromOpaque", err, opaque, test.keys, test.mandatory)) - } else if err == nil && !test.shouldSucceed { - t.Errorf(testintl.FormatTestError("GetValuesFromOpaque", fmt.Errorf("getting values from an invalid opaque succeeded"), opaque, test.keys, test.mandatory)) - } - } -} diff --git a/pkg/sdk/common/crypto/crypto_test.go b/pkg/sdk/common/crypto/crypto_test.go deleted file mode 100644 index e5f3c5d91b..0000000000 --- a/pkg/sdk/common/crypto/crypto_test.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2018-2020 CERN -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// In applying this license, CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -package crypto_test - -import ( - "fmt" - "strings" - "testing" - - provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" - - "github.com/cs3org/reva/pkg/sdk/common/crypto" - testintl "github.com/cs3org/reva/pkg/sdk/common/testing" -) - -func TestComputeChecksum(t *testing.T) { - tests := map[string]struct { - checksumType provider.ResourceChecksumType - input string - wants string - }{ - "Unset": {provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_UNSET, "Hello World!", ""}, - "Adler32": {provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_ADLER32, "Hello World!", "1c49043e"}, - "SHA1": {provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_SHA1, "Hello World!", "2ef7bde608ce5404e97d5f042f95f89f1c232871"}, - "MD5": {provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_MD5, "Hello World!", "ed076287532e86365e841e92bfc50d8c"}, - } - - for name, test := range tests { - t.Run(name, func(t *testing.T) { - if checksum, err := crypto.ComputeChecksum(test.checksumType, strings.NewReader(test.input)); err == nil { - if checksum != test.wants { - t.Errorf(testintl.FormatTestResult("ComputeChecksum", test.wants, checksum, test.checksumType, test.input)) - } - } else { - t.Errorf(testintl.FormatTestError("ComputeChecksum", err)) - } - }) - } - - // Check how ComputeChecksum reacts to an invalid checksum type - if _, err := crypto.ComputeChecksum(provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_INVALID, nil); err == nil { - t.Errorf(testintl.FormatTestError("ComputeChecksum", fmt.Errorf("accepted an invalid checksum type w/o erring"), provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_INVALID, nil)) - } -} - -func TestGetChecksumTypeName(t *testing.T) { - tests := map[provider.ResourceChecksumType]string{ - provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_UNSET: "unset", - provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_SHA1: "sha1", - provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_ADLER32: "adler32", - provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_MD5: "md5", - provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_INVALID: "invalid", - } - - for input, wants := range tests { - if got := crypto.GetChecksumTypeName(input); got != wants { - t.Errorf(testintl.FormatTestResult("GetChecksumTypeName", wants, got, input)) - } - } -} diff --git a/pkg/sdk/common/net/net_test.go b/pkg/sdk/common/net/net_test.go deleted file mode 100644 index 989a1f093e..0000000000 --- a/pkg/sdk/common/net/net_test.go +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright 2018-2020 CERN -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// In applying this license, CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -package net_test - -import ( - "fmt" - "strings" - "testing" - - rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" - provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" - - "github.com/cs3org/reva/pkg/sdk/common" - "github.com/cs3org/reva/pkg/sdk/common/crypto" - "github.com/cs3org/reva/pkg/sdk/common/net" - testintl "github.com/cs3org/reva/pkg/sdk/common/testing" -) - -type rpcStatusTest struct { - status rpc.Code -} - -func (r *rpcStatusTest) GetStatus() *rpc.Status { - return &rpc.Status{ - Code: r.status, - } -} - -func TestCheckRPCInvocation(t *testing.T) { - tests := []struct { - operation string - status rpcStatusTest - shouldSucceed bool - callError error - }{ - {"ok-check", rpcStatusTest{rpc.Code_CODE_OK}, true, nil}, - {"fail-status", rpcStatusTest{rpc.Code_CODE_NOT_FOUND}, false, nil}, - {"fail-err", rpcStatusTest{rpc.Code_CODE_OK}, false, fmt.Errorf("failed")}, - } - - for _, test := range tests { - err := net.CheckRPCInvocation(test.operation, &test.status, test.callError) - if err != nil && test.shouldSucceed { - t.Errorf(testintl.FormatTestError("CheckRPCInvocation", err, test.operation, test.status, test.callError)) - } else if err == nil && !test.shouldSucceed { - t.Errorf(testintl.FormatTestError("CheckRPCInvocation", fmt.Errorf("accepted an invalid RPC invocation"), test.operation, test.status, test.callError)) - } - } -} - -func TestTUSClient(t *testing.T) { - tests := []struct { - endpoint string - shouldSucceed bool - }{ - {"https://tusd.tusdemo.net/files/", true}, - {"https://google.de", false}, - } - - for _, test := range tests { - t.Run(test.endpoint, func(t *testing.T) { - if client, err := net.NewTUSClient(test.endpoint, "", ""); err == nil { - data := strings.NewReader("This is a simple TUS test") - dataDesc := common.CreateDataDescriptor("tus-test.txt", data.Size()) - checksumTypeName := crypto.GetChecksumTypeName(provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_MD5) - - if err := client.Write(data, dataDesc.Name(), &dataDesc, checksumTypeName, ""); err != nil && test.shouldSucceed { - t.Errorf(testintl.FormatTestError("TUSClient.Write", err, data, dataDesc.Name(), &dataDesc, checksumTypeName, "")) - } else if err == nil && !test.shouldSucceed { - t.Errorf(testintl.FormatTestError("TUSClient.Write", fmt.Errorf("writing to a non-TUS host succeeded"), data, dataDesc.Name(), &dataDesc, checksumTypeName, "")) - } - } else { - t.Errorf(testintl.FormatTestError("NewTUSClient", err, test.endpoint, "", "")) - } - }) - } -} - -func TestWebDAVClient(t *testing.T) { - tests := []struct { - endpoint string - shouldSucceed bool - }{ - {"https://zivowncloud2.uni-muenster.de/owncloud/remote.php/dav/files/testUser/", true}, - {"https://google.de", false}, - } - - for _, test := range tests { - t.Run(test.endpoint, func(t *testing.T) { - if client, err := net.NewWebDAVClient(test.endpoint, "testUser", "test12345"); err == nil { - const fileName = "webdav-test.txt" - - data := strings.NewReader("This is a simple WebDAV test") - if err := client.Write(fileName, data, data.Size()); err == nil { - if test.shouldSucceed { - if _, err := client.Read(fileName); err != nil { - t.Errorf(testintl.FormatTestError("WebDAVClient.Read", err)) - } - - if err := client.Remove(fileName); err != nil { - t.Errorf(testintl.FormatTestError("WebDAVClient.Remove", err)) - } - } else { - t.Errorf(testintl.FormatTestError("WebDAVClient.Write", fmt.Errorf("writing to a non-WebDAV host succeeded"), fileName, data, data.Size())) - } - } else if test.shouldSucceed { - t.Errorf(testintl.FormatTestError("WebDAVClient.Write", err, fileName, data, data.Size())) - } - } else { - t.Errorf(testintl.FormatTestError("NewWebDavClient", err, test.endpoint, "testUser", "test12345")) - } - }) - } -} - -func TestHTTPRequest(t *testing.T) { - tests := []struct { - url string - shouldSucceed bool - }{ - {"https://google.de", true}, - {"https://ujhwrgobniwoeo.de", false}, - } - - // Prepare the session - if session, err := testintl.CreateTestSession("sciencemesh-test.uni-muenster.de:9600", "test", "testpass"); err == nil { - for _, test := range tests { - t.Run(test.url, func(t *testing.T) { - if request, err := session.NewHTTPRequest(test.url, "GET", "", nil); err == nil { - if _, err := request.Do(true); err != nil && test.shouldSucceed { - t.Errorf(testintl.FormatTestError("HTTPRequest.Do", err)) - } else if err == nil && !test.shouldSucceed { - t.Errorf(testintl.FormatTestError("HTTPRequest.Do", fmt.Errorf("send request to an invalid host succeeded"))) - } - } else { - t.Errorf(testintl.FormatTestError("Session.NewHTTPRequest", err, test.url, "GET", "", nil)) - } - }) - } - } else { - t.Errorf(testintl.FormatTestError("CreateTestSession", err)) - } -} diff --git a/pkg/sdk/common/testing/testing.go b/pkg/sdk/common/testing/testing.go deleted file mode 100644 index 5a83c45c31..0000000000 --- a/pkg/sdk/common/testing/testing.go +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2018-2020 CERN -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// In applying this license, CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -package testing - -import ( - "fmt" - "strings" - - "github.com/cs3org/reva/pkg/sdk" -) - -func formatTestMessage(funcName string, msg string, params ...interface{}) string { - // Format parameter list - paramList := make([]string, 0, len(params)) - for _, param := range params { - paramList = append(paramList, fmt.Sprintf("%#v", param)) - } - - return fmt.Sprintf("%s(%s) -> %s", funcName, strings.Join(paramList, ", "), msg) -} - -// FormatTestResult pretty-formats a function call along with its parameters, result and expected result. -func FormatTestResult(funcName string, wants interface{}, got interface{}, params ...interface{}) string { - msg := fmt.Sprintf("Got: %#v; Wants: %#v", got, wants) - return formatTestMessage(funcName, msg, params...) -} - -// FormatTestError pretty-formats a function error. -func FormatTestError(funcName string, err error, params ...interface{}) string { - msg := fmt.Sprintf("Error: %v", err) - return formatTestMessage(funcName, msg, params...) -} - -// CreateTestSession creates a Reva session for testing. -// For this, it performs a basic login using the specified credentials. -func CreateTestSession(host string, username string, password string) (*sdk.Session, error) { - if session, err := sdk.NewSession(); err == nil { - if err := session.Initiate(host, false); err == nil { - if err := session.BasicLogin(username, password); err == nil { - return session, nil - } - } - } - - return nil, fmt.Errorf("unable to create the test session") -}