cmd/gio: generate appID if not specified

Use the Go import path to create an appID based on the domain name
plus the last directory location in the import path.

Signed-off-by: Greg Pomerantz <gmp.gio@wow.st>
This commit is contained in:
Greg Pomerantz
2019-09-10 18:28:43 -04:00
committed by Elias Naur
parent 86b231ca28
commit a68d97f947
3 changed files with 74 additions and 9 deletions
+32
View File
@@ -0,0 +1,32 @@
package main
import (
"testing"
)
type expval struct {
in, out string
}
func TestAppID(t *testing.T) {
tests := []expval{
{"example", "localhost.example"},
{"example.com", "com.example"},
{"www.example.com", "com.example.www"},
{"examplecom/app", "examplecom.app"},
{"example.com/app", "com.example.app"},
{"www.example.com/app", "com.example.www.app"},
{"www.en.example.com/app", "com.example.en.www.app"},
{"example.com/dir/app", "com.example.app"},
{"example.com/dir.ext/app", "com.example.app"},
{"example.com/dir/app.ext", "com.example.app.ext"},
{"example-com.net/dir/app", "net.example_com.app"},
}
for i, test := range tests {
got := appIDFromPackage(test.in)
if exp := test.out; got != exp {
t.Errorf("(%d): expected '%s', got '%s'", i, exp, got)
}
}
}