From b90c98a034012f868892093058d0a18da7264296 Mon Sep 17 00:00:00 2001 From: Timo Tietavainen Date: Thu, 13 Jan 2022 10:41:59 +0200 Subject: [PATCH] Move SDL usage code example Move SDL usage code example from sdlgo repo's root to example sub-directory and change it to be a runnable application. Earlier example was belonging to the Golang test package what caused it to be ran when 'go test ./...' -command was executed and execution of the example was failing if DBAAS connection was missing. Execution failure is also visible in the sdlgo coverage test of the sonarcloud.io. Issue-Id: RIC-875 Signed-off-by: Timo Tietavainen Change-Id: I6d980e0730d4a6f768448134bc7efece050a6d89 --- example_test.go => example/example.go | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) rename example_test.go => example/example.go (68%) diff --git a/example_test.go b/example/example.go similarity index 68% rename from example_test.go rename to example/example.go index d3be2f7..aee1c19 100644 --- a/example_test.go +++ b/example/example.go @@ -1,6 +1,6 @@ /* Copyright (c) 2019 AT&T Intellectual Property. - Copyright (c) 2018-2019 Nokia. + Copyright (c) 2018-2022 Nokia. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ * platform project (RICP). */ -package sdlgo_test +package main import ( "fmt" @@ -34,21 +34,33 @@ func init() { sdl = sdlgo.NewSyncStorage() } -func ExampleSdlInstance_Set() { - err := sdl.Set("namespace", "stringdata", "data", "intdata", 42) +func exampleSet() { + err := sdl.Set("my-namespace", "somestringdata", "data", "someintdata", 42) if err != nil { panic(err) } else { fmt.Println("Data written successfully") } - // Output: Data written successfully } -func ExampleSdlInstance_Get() { - retMap, err := sdl.Get("namespace", []string{"stringdata", "intdata"}) +func exampleGet() { + retMap, err := sdl.Get("my-namespace", []string{"somestringdata", "someintdata"}) if err != nil { panic(err) } else { - fmt.Println(retMap) + fmt.Println("Data read successfully") + for k, v := range retMap { + fmt.Println("\t", k, "key value is", v) + } } } + +func exampleClose() { + sdl.Close() +} + +func main() { + exampleSet() + exampleGet() + exampleClose() +} -- 2.16.6