[lxc-devel] [lxd/master] lxd/project: Adds Parts() function for separating project prefixed string

tomponline on Github lxc-bot at linuxcontainers.org
Fri Feb 7 09:43:51 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 447 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200207/5e35f7ea/attachment.bin>
-------------- next part --------------
From f8688c2b816813484965927804ddb5d89ead503f Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Fri, 7 Feb 2020 09:42:21 +0000
Subject: [PATCH] lxd/project: Adds Parts() function for separating project
 prefixed string

And tests.

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/project/project_test.go | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 lxd/project/project_test.go

diff --git a/lxd/project/project_test.go b/lxd/project/project_test.go
new file mode 100644
index 0000000000..7382757263
--- /dev/null
+++ b/lxd/project/project_test.go
@@ -0,0 +1,36 @@
+package project_test
+
+import (
+	"fmt"
+
+	"github.com/lxc/lxd/lxd/project"
+)
+
+func ExamplePrefix() {
+	prefixed := project.Prefix(project.Default, "test")
+	fmt.Println(prefixed)
+
+	prefixed = project.Prefix("proj", "test_1")
+	fmt.Println(prefixed)
+	// Output: test
+	// proj_test_1
+}
+
+func ExampleParts() {
+	projectName, name := project.Parts("unprefixed")
+	fmt.Println(projectName, name)
+
+	projectName, name = project.Parts(project.Prefix(project.Default, "test"))
+	fmt.Println(projectName, name)
+
+	projectName, name = project.Parts("proj_test")
+	fmt.Println(projectName, name)
+
+	projectName, name = project.Parts(project.Prefix("proj", "test_1"))
+	fmt.Println(projectName, name)
+
+	// Output: default unprefixed
+	// default test
+	// proj test
+	// proj test_1
+}


More information about the lxc-devel mailing list