...

Source file src/github.com/go-kivik/kivik/v4/driver/driver_test.go

Documentation: github.com/go-kivik/kivik/v4/driver

     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 driver
    14  
    15  import (
    16  	"encoding/json"
    17  	"testing"
    18  )
    19  
    20  func TestSecurityMarshalJSON(t *testing.T) {
    21  	t.Run("empty", func(t *testing.T) {
    22  		sec := Security{}
    23  		want := "{}"
    24  		got, _ := json.Marshal(sec)
    25  		if string(got) != want {
    26  			t.Errorf("Unexpected output: %s", string(got))
    27  		}
    28  	})
    29  	t.Run("pointer", func(t *testing.T) {
    30  		sec := &Security{}
    31  		want := "{}"
    32  		got, _ := json.Marshal(sec)
    33  		if string(got) != want {
    34  			t.Errorf("Unexpected output: %s", string(got))
    35  		}
    36  	})
    37  	t.Run("admin name, one member role", func(t *testing.T) {
    38  		sec := Security{
    39  			Admins: Members{
    40  				Names: []string{"bob"},
    41  			},
    42  			Members: Members{
    43  				Roles: []string{"users"},
    44  			},
    45  		}
    46  		want := `{"admins":{"names":["bob"]},"members":{"roles":["users"]}}`
    47  		got, _ := json.Marshal(sec)
    48  		if string(got) != want {
    49  			t.Errorf("Unexpected output: %s", string(got))
    50  		}
    51  	})
    52  }
    53  

View as plain text