|
| 1 | +package llb |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/moby/buildkit/solver/pb" |
| 8 | + "github.com/stretchr/testify/require" |
| 9 | +) |
| 10 | + |
| 11 | +func TestGit(t *testing.T) { |
| 12 | + t.Parallel() |
| 13 | + |
| 14 | + type tcase struct { |
| 15 | + name string |
| 16 | + st State |
| 17 | + identifier string |
| 18 | + attrs map[string]string |
| 19 | + } |
| 20 | + |
| 21 | + tcases := []tcase{ |
| 22 | + { |
| 23 | + name: "refarg", |
| 24 | + st: Git("github.com/foo/bar.git", "ref"), |
| 25 | + identifier: "git://github.com/foo/bar.git#ref", |
| 26 | + attrs: map[string]string{ |
| 27 | + "git.authheadersecret": "GIT_AUTH_HEADER", |
| 28 | + "git.authtokensecret": "GIT_AUTH_TOKEN", |
| 29 | + "git.fullurl": "https://github.com/foo/bar.git", |
| 30 | + }, |
| 31 | + }, |
| 32 | + { |
| 33 | + name: "refarg with subdir", |
| 34 | + st: Git("github.com/foo/bar.git", "ref:subdir"), |
| 35 | + identifier: "git://github.com/foo/bar.git#ref:subdir", |
| 36 | + attrs: map[string]string{ |
| 37 | + "git.authheadersecret": "GIT_AUTH_HEADER", |
| 38 | + "git.authtokensecret": "GIT_AUTH_TOKEN", |
| 39 | + "git.fullurl": "https://github.com/foo/bar.git", |
| 40 | + }, |
| 41 | + }, |
| 42 | + { |
| 43 | + name: "refarg with subdir func", |
| 44 | + st: Git("github.com/foo/bar.git", "ref", GitSubDir("subdir")), |
| 45 | + identifier: "git://github.com/foo/bar.git#ref:subdir", |
| 46 | + attrs: map[string]string{ |
| 47 | + "git.authheadersecret": "GIT_AUTH_HEADER", |
| 48 | + "git.authtokensecret": "GIT_AUTH_TOKEN", |
| 49 | + "git.fullurl": "https://github.com/foo/bar.git", |
| 50 | + }, |
| 51 | + }, |
| 52 | + { |
| 53 | + name: "refarg with override", |
| 54 | + st: Git("github.com/foo/bar.git", "ref:dir", GitRef("v1.0")), |
| 55 | + identifier: "git://github.com/foo/bar.git#v1.0:dir", |
| 56 | + attrs: map[string]string{ |
| 57 | + "git.authheadersecret": "GIT_AUTH_HEADER", |
| 58 | + "git.authtokensecret": "GIT_AUTH_TOKEN", |
| 59 | + "git.fullurl": "https://github.com/foo/bar.git", |
| 60 | + }, |
| 61 | + }, |
| 62 | + { |
| 63 | + name: "funcs only", |
| 64 | + st: Git("github.com/foo/bar.git", "", GitRef("v1.0"), GitSubDir("dir")), |
| 65 | + identifier: "git://github.com/foo/bar.git#v1.0:dir", |
| 66 | + attrs: map[string]string{ |
| 67 | + "git.authheadersecret": "GIT_AUTH_HEADER", |
| 68 | + "git.authtokensecret": "GIT_AUTH_TOKEN", |
| 69 | + "git.fullurl": "https://github.com/foo/bar.git", |
| 70 | + }, |
| 71 | + }, |
| 72 | + } |
| 73 | + |
| 74 | + for _, tc := range tcases { |
| 75 | + t.Run(tc.name, func(t *testing.T) { |
| 76 | + st := tc.st |
| 77 | + def, err := st.Marshal(context.TODO()) |
| 78 | + |
| 79 | + require.NoError(t, err) |
| 80 | + |
| 81 | + m, arr := parseDef(t, def.Def) |
| 82 | + require.Equal(t, 2, len(arr)) |
| 83 | + |
| 84 | + dgst, idx := last(t, arr) |
| 85 | + require.Equal(t, 0, idx) |
| 86 | + require.Equal(t, m[dgst], arr[0]) |
| 87 | + |
| 88 | + g := arr[0].Op.(*pb.Op_Source).Source |
| 89 | + |
| 90 | + require.Equal(t, tc.identifier, g.Identifier) |
| 91 | + require.Equal(t, tc.attrs, g.Attrs) |
| 92 | + }) |
| 93 | + } |
| 94 | +} |
0 commit comments