forked from emicklei/gmig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_iam_test.go
48 lines (42 loc) · 1.08 KB
/
export_iam_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"io/ioutil"
"os"
"testing"
"time"
)
func TestExportProjectsIAMPolicy(t *testing.T) {
// simulate effect of GS download old state
ioutil.WriteFile("state", []byte("010_one.yaml"), os.ModePerm)
defer os.Remove("state")
// simulate now
timeNow = func() time.Time { return time.Time{} }
// cleanup generated migration
generated := "010_exported_project_iam_policy.yaml"
defer os.Remove(generated)
// capture GC command
cc := new(commandCapturer)
cc.output = []byte(`{
"bindings": [{
"members": [
"member"
],
"role": "role"
}]
}`)
runCommand = cc.runCommand
if err := newApp().Run([]string{"gmig", "export", "project-iam-policy", "test/demo"}); err != nil {
wd, _ := os.Getwd()
t.Fatal("unexpected error", err, wd)
}
if m, err := LoadMigration(generated); err != nil {
t.Fatal("unable to load generated migration", err)
} else {
if got, want := len(m.DoSection), 1; got != want {
t.Logf("got [%v] want [%v]", got, want)
}
if got, want := len(m.DoSection), 2; got != want {
t.Logf("got [%v] want [%v]", got, want)
}
}
}