github.com/vchain-us/vcn@v0.9.11-0.20210921212052-a2484d23c0b3/pkg/api/metadata_test.go (about) 1 /* 2 * Copyright (c) 2018-2020 vChain, Inc. All Rights Reserved. 3 * This software is released under GPL3. 4 * The full license information can be found under: 5 * https://www.gnu.org/licenses/gpl-3.0.en.html 6 * 7 */ 8 9 package api 10 11 import ( 12 "testing" 13 14 "github.com/stretchr/testify/assert" 15 ) 16 17 func TestMetadata(t *testing.T) { 18 m := Metadata{} 19 20 // Set/Get 21 m.Set("key", "value") 22 assert.Equal(t, "value", m.Get("key", nil)) 23 assert.Equal(t, "default", m.Get("nonExistingKey", "default")) 24 25 // Multiple values 26 m.SetValues(map[string]interface{}{"key": "newValue", "a": "one", "b": 2}) 27 assert.Equal(t, "newValue", m.Get("key", nil)) 28 assert.Equal(t, "one", m.Get("a", nil)) 29 assert.Equal(t, 2, m.Get("b", nil)) 30 31 // Swipe 32 v := m.swipeString("key") 33 assert.Equal(t, "newValue", v) 34 assert.Nil(t, m.Get("key", nil)) 35 }