...

Source file src/github.com/go-kivik/kivik/v4/x/fsdb/security_test.go

Documentation: github.com/go-kivik/kivik/v4/x/fsdb

     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 fs
    14  
    15  import (
    16  	"context"
    17  	"testing"
    18  
    19  	"gitlab.com/flimzy/testy"
    20  
    21  	internal "github.com/go-kivik/kivik/v4/int/errors"
    22  	"github.com/go-kivik/kivik/v4/x/fsdb/filesystem"
    23  )
    24  
    25  func TestSecurity(t *testing.T) {
    26  	type tt struct {
    27  		fs           filesystem.Filesystem
    28  		path, dbname string
    29  		status       int
    30  		err          string
    31  	}
    32  	tests := testy.NewTable()
    33  	tests.Add("no security object", tt{
    34  		dbname: "foo",
    35  	})
    36  	tests.Add("json security obj", tt{
    37  		path:   "testdata",
    38  		dbname: "db_foo",
    39  	})
    40  	tests.Add("yaml security obj", tt{
    41  		path:   "testdata",
    42  		dbname: "db_bar",
    43  	})
    44  
    45  	tests.Run(t, func(t *testing.T, tt tt) {
    46  		dir := tt.path
    47  		if dir == "" {
    48  			dir = tempDir(t)
    49  			t.Cleanup(func() {
    50  				rmdir(t, dir)
    51  			})
    52  		}
    53  		fs := tt.fs
    54  		if fs == nil {
    55  			fs = filesystem.Default()
    56  		}
    57  		c := &client{root: dir, fs: fs}
    58  		db, err := c.newDB(tt.dbname)
    59  		if err != nil {
    60  			t.Fatal(err)
    61  		}
    62  		sec, err := db.Security(context.Background())
    63  		if d := internal.StatusErrorDiffRE(tt.err, tt.status, err); d != "" {
    64  			t.Error(d)
    65  		}
    66  		if d := testy.DiffAsJSON(testy.Snapshot(t), sec); d != nil {
    67  			t.Error(d)
    68  		}
    69  	})
    70  }
    71  

View as plain text