-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- move the sanity test to the top for the compiler to see first - add a basic identity test that ensures the identities were created Signed-off-by: Erik Hollensbe <[email protected]>
- Loading branch information
Erik Hollensbe
committed
Feb 4, 2021
1 parent
34c9592
commit 8a1c98d
Showing
4 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
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 |
---|---|---|
@@ -1,6 +1,64 @@ | ||
package main | ||
|
||
import "testing" | ||
import ( | ||
"testing" | ||
|
||
"github.com/erikh/tftest" | ||
) | ||
|
||
// these are deliberately named to keep the code small. they do not add | ||
// anything else. Hopefully we won't need this soon. | ||
func h(m interface{}) map[string]interface{} { | ||
return m.(map[string]interface{}) | ||
} | ||
|
||
func a(m interface{}) []interface{} { | ||
return m.([]interface{}) | ||
} | ||
|
||
func s(m interface{}) string { | ||
return m.(string) | ||
} | ||
|
||
func TestIdentity(t *testing.T) { | ||
type identity struct { | ||
name string | ||
pubkey string | ||
privkey string | ||
} | ||
|
||
tf := tftest.New(t) | ||
tf.Apply("testdata/plans/basic-identity.tf") | ||
resources := a(tf.State()["resources"]) | ||
|
||
ids := map[string]identity{} | ||
|
||
for _, resource := range resources { | ||
res := h(resource) | ||
name := s(res["name"]) | ||
|
||
ids[name] = identity{ | ||
name: name, | ||
pubkey: s(h(h(a(res["instances"])[0])["attributes"])["public_key"]), | ||
privkey: s(h(h(a(res["instances"])[0])["attributes"])["private_key"]), | ||
} | ||
} | ||
|
||
if len(ids) != 2 { | ||
t.Fatalf("invalid count of identities created") | ||
} | ||
|
||
for _, name := range []string{"alice", "bob"} { | ||
if _, ok := ids[name]; !ok { | ||
t.Fatalf("%q was not present in state", name) | ||
} | ||
|
||
if ids[name].pubkey == "" { | ||
t.Fatalf("%q: pubkey empty", name) | ||
} | ||
|
||
if ids[name].privkey == "" { | ||
t.Fatalf("%q: pubkey empty", name) | ||
} | ||
} | ||
} |
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,2 @@ | ||
resource "zerotier_identity" "alice" {} | ||
resource "zerotier_identity" "bob" {} |