/* NAME meta_test.go DESCRIPTION See Readme.md AUTHOR Saxon Nelson-Milton LICENSE meta_test.go is Copyright (C) 2017-2019 the Australian Ocean Lab (AusOcean) It is free software: you can redistribute it and/or modify them under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with revid in gpl.txt. If not, see http://www.gnu.org/licenses. */ package mts import ( "reflect" "testing" ) // TODO: test add when key doesn't exist func TestAddAndGet(t *testing.T) { meta := NewMeta() meta.Add("loc", "a,b,c") meta.Add("ts", "12345678") if data, err := meta.Get("loc"); err != nil { t.Errorf("Could not get data for key: loc: %v", err.Error()) if data != "a,b,c" { t.Errorf("Did not get expected data") } } if data, err := meta.Get("ts"); err != nil { t.Errorf("Could not get data for key: ts: %v", err.Error()) if data != "12345678" { t.Errorf("Did not get expected data") } } } // TODO: test add when key does exist func TestUpdate(t *testing.T) { meta := NewMeta() meta.Add("loc", "a,b,c") meta.Add("loc", "d,e,f") if data, err := meta.Get("loc"); err != nil { t.Errorf("Did not expect err: %v", err.Error()) if data != "d,e,f" { t.Errorf("Data did not correctly update for key \"loc\"") } } } func TestAll(t *testing.T) { meta := NewMeta() tstMap := map[string]string{ "loc": "a,b,c", "ts": "12345678", } meta.Add("loc", "a,b,c") meta.Add("ts", "12345678") metaMap := meta.All() if !reflect.DeepEqual(metaMap, tstMap) { t.Errorf("Map not correct. Got: %v, want: %v", metaMap, tstMap) } } // TODO: test get when key doesn't exist func TestGetAbsentKey(t *testing.T) { meta := NewMeta() if _, err := meta.Get("loc"); err != errKeyAbsent { t.Errorf("Expected error: %v", errKeyAbsent.Error()) } } // TODO: test delete when key exists // TODO: test delete when key doesn't exist