-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a2226d
commit cb4e750
Showing
10 changed files
with
413 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,7 @@ | |
"secrets", | ||
"--infra-path", | ||
"/home/larsonsh/src/forj/src/forj-oss-infra/", | ||
"--show", | ||
] | ||
}, | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package forjfile | ||
|
||
type UsersStruct map[string]*UserStruct | ||
|
||
func (u UsersStruct) mergeFrom(source string, from UsersStruct) { | ||
for k, userFrom := range from { | ||
if user, found := u[k]; found { | ||
user.mergeFrom(source, userFrom) | ||
} else { | ||
u[k] = userFrom | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
package: forjj | ||
import: | ||
- package: github.com/alecthomas/kingpin | ||
repo: https://github.com/clarsonneur/kingpin | ||
version: get-commands-from-context | ||
repo: https://github.com/clarsonneur/kingpin | ||
- package: github.com/kvz/logstreamer | ||
- package: github.com/forj-oss/goforjj | ||
- package: github.com/forj-oss/forjj-modules | ||
- package: golang.org/x/net | ||
subpackages: | ||
- proxy | ||
- package: gopkg.in/yaml.v2 | ||
- package: golang.org/x/crypto | ||
subpackages: | ||
- ssh/terminal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
type secretInfo struct { | ||
keyPath string | ||
value string | ||
source string | ||
found bool | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package sourcesinfo | ||
|
||
type Sources struct { | ||
keys map[string]string | ||
} | ||
|
||
func newSources() (ret *Sources) { | ||
ret = new(Sources) | ||
ret.keys = make(map[string]string) | ||
return | ||
} | ||
|
||
func (s *Sources)Set(source, key, value string) (ret *Sources) { | ||
if s == nil { | ||
ret = newSources() | ||
} else { | ||
ret = s | ||
} | ||
|
||
if value == "" { | ||
delete(ret.keys, key) | ||
} else { | ||
ret.keys[key] = source | ||
} | ||
return | ||
} | ||
|
||
func (s *Sources)Get(key string) (source string) { | ||
if s == nil { | ||
return | ||
} | ||
if v, found := s.keys[key] ; found { | ||
return v | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package sourcesinfo | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestSet(t *testing.T) { | ||
t.Log("Expect set to initialize the sources struct.") | ||
|
||
var sources *Sources | ||
|
||
const ( | ||
src1 = "src1" | ||
src2 = "src2" | ||
key1 = "key1" | ||
key2 = "key2" | ||
value1 = "value1" | ||
value2 = "" | ||
) | ||
// ------------ Run function to test | ||
// sources is nil | ||
sources = sources.Set(src1, key1, value1) | ||
|
||
// ------------ Test result | ||
if sources == nil { | ||
t.Error("Expect set to return a new object") | ||
} else if v1, f1 := sources.keys[key1]; !f1 { | ||
t.Error("Expect set to set a source key. Not found") | ||
} else if v1 != src1 { | ||
t.Errorf("Expect set to set a source value = '%s'. got '%s'", src1, v1) | ||
} | ||
|
||
// ------------ update context | ||
// Change source information | ||
sources = sources.Set(src2, key1, value1) | ||
// ------------ Test result | ||
if sources == nil { | ||
t.Error("Expect set to return a new object") | ||
} else if v1, f1 := sources.keys[key1]; !f1 { | ||
t.Error("Expect set to set a source key. Not found") | ||
} else if v1 != src2 { | ||
t.Errorf("Expect set to set a source value = '%s'. got '%s'", src2, v1) | ||
} | ||
|
||
// ------------ update context | ||
// add a new key, with a different source | ||
sources = sources.Set(src1, key2, value1) | ||
// ------------ Test result | ||
if sources == nil { | ||
t.Error("Expect set to return a new object") | ||
} else if v1, f1 := sources.keys[key1]; !f1 { | ||
t.Errorf("Expect set to set a source key '%s'. Not found", key1) | ||
} else if v1 != src2 { | ||
t.Errorf("Expect set to set a source value = '%s'. got '%s'", src2, v1) | ||
} else if v2, f2 := sources.keys[key2]; !f2 { | ||
t.Errorf("Expect set to set a source key '%s'. Not found", key2) | ||
} else if v2 != src1 { | ||
t.Errorf("Expect set to set a source value = '%s'. got '%s'", src2, v1) | ||
} | ||
// ------------ update context | ||
// add a new key wth value empty | ||
sources = sources.Set(src1, key2, value2) | ||
// ------------ Test result | ||
if sources == nil { | ||
t.Error("Expect set to return a new object") | ||
} else if v1, f1 := sources.keys[key1]; !f1 { | ||
t.Errorf("Expect set to set a source key '%s'. Not found", key1) | ||
} else if v1 != src2 { | ||
t.Errorf("Expect set to set a source value = '%s'. got '%s'", src2, v1) | ||
} else if _, f2 := sources.keys[key2]; f2 { | ||
t.Errorf("Expect set to unset a source key '%s'. found it", key2) | ||
} | ||
} | ||
|
||
func TestGet(t *testing.T) { | ||
t.Log("Expect get to retrun the source information.") | ||
|
||
var sources *Sources | ||
|
||
const ( | ||
src1 = "src1" | ||
src2 = "src2" | ||
key1 = "key1" | ||
key2 = "key2" | ||
key3 = "key3" | ||
value1 = "value1" | ||
value2 = "" | ||
) | ||
// ------------ Run function to test | ||
// sources is nil | ||
ret := sources.Get(key1) | ||
|
||
// ------------ Test result | ||
|
||
if ret != "" { | ||
t.Errorf("Expect get to return an empty string. Got '%s'", ret) | ||
} | ||
|
||
// ------------ update context | ||
sources = sources.Set(src1, key1, value1) | ||
sources = sources.Set(src2, key2, value1) | ||
|
||
// ------------ Run function to test | ||
// check source information returned | ||
ret = sources.Get(key1) | ||
ret2 := sources.Get(key2) | ||
ret3 := sources.Get(key3) | ||
|
||
// ------------ Test result | ||
if ret != src1 { | ||
t.Errorf("Expect get to return '%s'. Got '%s'", src1, ret) | ||
} else if ret2 != src2 { | ||
t.Errorf("Expect get to return '%s'. Got '%s'", src1, ret2) | ||
} else if ret3 == src2 { | ||
t.Errorf("Expect get to return ''. Got '%s'", ret3) | ||
} | ||
} |
Oops, something went wrong.