...

Source file src/github.com/go-kivik/kivik/v4/x/memorydb/test/test.go

Documentation: github.com/go-kivik/kivik/v4/x/memorydb/test

     1  // Licensed under the Apache License, Version 2.0 (the "License"); you may not
     2  // use this file except in compliance with the License. You may obtain a copy of
     3  // the License at
     4  //
     5  //  http://www.apache.org/licenses/LICENSE-2.0
     6  //
     7  // Unless required by applicable law or agreed to in writing, software
     8  // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     9  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    10  // License for the specific language governing permissions and limitations under
    11  // the License.
    12  
    13  package test
    14  
    15  import (
    16  	"context"
    17  	"net/http"
    18  	"testing"
    19  
    20  	"github.com/go-kivik/kivik/v4"
    21  	"github.com/go-kivik/kivik/v4/kiviktest"
    22  	"github.com/go-kivik/kivik/v4/kiviktest/kt"
    23  )
    24  
    25  // RegisterMemoryDBSuite registers the MemoryDB integration test suite.
    26  func RegisterMemoryDBSuite() {
    27  	kiviktest.RegisterSuite(kiviktest.SuiteKivikMemory, kt.SuiteConfig{
    28  		// Unsupported features
    29  		"Flush.skip": true,
    30  
    31  		"AllDBs.expected": []string{"_users"},
    32  
    33  		"CreateDB/RW/NoAuth.status":         http.StatusUnauthorized,
    34  		"CreateDB/RW/Admin/Recreate.status": http.StatusPreconditionFailed,
    35  
    36  		"AllDocs.skip": true, // FIXME: Unimplemented
    37  
    38  		"DBExists/Admin.databases":       []string{"chicken"},
    39  		"DBExists/Admin/chicken.exists":  false,
    40  		"DBExists/RW/group/Admin.exists": true,
    41  
    42  		"AllDBsStats.expected": []*kivik.DBStats{
    43  			{
    44  				Name: "_users",
    45  			},
    46  		},
    47  
    48  		"DestroyDB/RW/Admin/NonExistantDB.status": http.StatusNotFound,
    49  
    50  		"Log.status":          http.StatusNotImplemented,
    51  		"Log/Admin/HTTP.skip": true,
    52  
    53  		"Version.version":        `^0\.0\.1$`,
    54  		"Version.vendor":         `^Kivik Memory Adaptor$`,
    55  		"Version.vendor_version": `^0\.0\.1$`,
    56  
    57  		// Replications not to be implemented
    58  		"GetReplications.skip": true,
    59  		"Replicate.skip":       true,
    60  
    61  		"Get/RW/group/Admin/bogus.status": http.StatusNotFound,
    62  
    63  		"GetRev/RW/group/Admin/bogus.status": http.StatusNotFound,
    64  
    65  		"Put/RW/Admin/group/LeadingUnderscoreInID.status": http.StatusBadRequest,
    66  		"Put/RW/Admin/group/Conflict.status":              http.StatusConflict,
    67  
    68  		"Delete/RW/Admin/group/MissingDoc.status":       http.StatusNotFound,
    69  		"Delete/RW/Admin/group/InvalidRevFormat.status": http.StatusBadRequest,
    70  		"Delete/RW/Admin/group/WrongRev.status":         http.StatusConflict,
    71  
    72  		"Security.databases":            []string{"_users", "chicken", "_duck"},
    73  		"Security/Admin/chicken.status": http.StatusNotFound,
    74  		"Security/Admin/_duck.status":   http.StatusNotFound,
    75  
    76  		"SetSecurity/RW/Admin/NotExists.status": http.StatusNotFound,
    77  
    78  		"BulkDocs/RW/NoAuth/group/Mix/Conflict.status": http.StatusConflict,
    79  		"BulkDocs/RW/Admin/group/Mix/Conflict.status":  http.StatusConflict,
    80  
    81  		"Find.databases":                       []string{"chicken", "_duck"},
    82  		"Find/Admin/chicken.status":            http.StatusNotFound,
    83  		"Find/Admin/_duck.status":              http.StatusNotFound,
    84  		"Find/NoAuth/chicken.status":           http.StatusNotFound,
    85  		"Find/NoAuth/_duck.status":             http.StatusUnauthorized,
    86  		"Find/RW/group/Admin/Warning.warning":  "no matching index found, create an index to optimize query time",
    87  		"Find/RW/group/NoAuth/Warning.warning": "no matching index found, create an index to optimize query time",
    88  
    89  		"Explain.skip":           true,                      // FIXME: Unimplemented
    90  		"Stats.skip":             true,                      // FIXME: Unimplemented
    91  		"Compact.skip":           true,                      // FIXME: Unimplemented
    92  		"DBUpdates.status":       http.StatusNotImplemented, // FIXME: Unimplemented
    93  		"Changes.skip":           true,                      // FIXME: Unimplemented
    94  		"Copy.skip":              true,                      // FIXME: Unimplemented, depends on Get/Put or Copy
    95  		"GetAttachment.skip":     true,                      // FIXME: Unimplemented
    96  		"GetAttachmentMeta.skip": true,                      // FIXME: Unimplemented
    97  		"PutAttachment.skip":     true,                      // FIXME: Unimplemented
    98  		"DeleteAttachment.skip":  true,                      // FIXME: Unimplemented
    99  		"Query.skip":             true,                      // FIXME: Unimplemented
   100  		"CreateIndex.skip":       true,                      // FIXME: Unimplemented
   101  		"GetIndexes.skip":        true,                      // FIXME: Unimplemented
   102  		"DeleteIndex.skip":       true,                      // FIXME: Unimplemented
   103  		"SetSecurity.skip":       true,                      // FIXME: Unimplemented
   104  		"ViewCleanup.skip":       true,                      // FIXME: Unimplemented
   105  	})
   106  }
   107  
   108  // MemoryTest runs the integration tests for the Memory driver.
   109  func MemoryTest(t *testing.T) {
   110  	t.Helper()
   111  	client, err := kivik.New("memory", "")
   112  	if err != nil {
   113  		t.Fatalf("Failed to connect to memory driver: %s\n", err)
   114  	}
   115  	clients := &kt.Context{
   116  		RW:    true,
   117  		Admin: client,
   118  		T:     t,
   119  	}
   120  	if err := client.CreateDB(context.Background(), "_users"); err != nil {
   121  		t.Fatal(err)
   122  	}
   123  	kiviktest.RunTestsInternal(clients, kiviktest.SuiteKivikMemory)
   124  }
   125  

View as plain text