-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Nico Braun <rainbowstack@gmail.com>
- Loading branch information
Showing
7 changed files
with
165 additions
and
3 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
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,2 +1,3 @@ | ||
def main(input): | ||
return input.split("\n") | ||
return [x for x in input.split("\n") if x != ""] | ||
|
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,95 @@ | ||
package plugin | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/bluebrown/kobold/krm" | ||
"github.com/bluebrown/kobold/plugin/builtin" | ||
) | ||
|
||
func TestDecoder(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
decoder string | ||
giveFile string | ||
wantName string | ||
wantTag string | ||
wantDigest string | ||
}{ | ||
{ | ||
name: "lines", | ||
decoder: "decoder.lines@v1", | ||
giveFile: "testdata/lines.txt", | ||
wantName: "index.docker.io/bluebrown/busybox", | ||
wantTag: "v1.1", | ||
wantDigest: "sha256:3b3128d9df6bbbcc92e2358e596c9fbd722a437a62bafbc51607970e9e3b8869", | ||
}, | ||
{ | ||
name: "distribution", | ||
decoder: "decoder.distribution@v1", | ||
giveFile: "testdata/distribution.json", | ||
wantName: "test.azurecr.io/busybox", | ||
wantTag: "v1", | ||
wantDigest: "sha256:xxxxd5c8786bb9e621a45ece0dbxxxx1cdc624ad20da9fe62e9d25490f33xxxx", | ||
}, | ||
{ | ||
name: "dockerhub", | ||
decoder: "decoder.dockerhub@v1", | ||
giveFile: "testdata/dockerhub.json", | ||
wantName: "index.docker.io/svendowideit/testhook", | ||
wantTag: "stable", | ||
wantDigest: "sha256:3b3128d9df6bbbcc92e2358e596c9fbd722a437a62bafbc51607970e9e3b8869", | ||
}, | ||
{ | ||
name: "harbor", | ||
decoder: "decoder.harbor@v1", | ||
giveFile: "testdata/harbor.json", | ||
wantName: "ghcr.io/bluebrown/busybox", | ||
wantTag: "v1.4", | ||
wantDigest: "sha256:3b3128d9df6bbbcc92e2358e596c9fbd722a437a62bafbc51607970e9e3b8869", | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
|
||
dec := NewDecoderRunner() | ||
|
||
sb, err := builtin.StarlarkScripts.ReadFile("starlark/" + tc.decoder + ".star") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
fb, err := os.ReadFile(tc.giveFile) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
refs, err := dec.Decode(tc.decoder, sb, fb) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if len(refs) != 1 { | ||
t.Errorf("ref mismatch, got %v, want %v", len(refs), 1) | ||
} | ||
|
||
tag, digest, err := krm.ParseImageRefWithDigest(refs[0]) | ||
if err != nil { | ||
t.Fatalf("failed to parse image ref: %v", err) | ||
} | ||
|
||
if tag.Context().String() != tc.wantName { | ||
t.Errorf("got %v, want %v", tag.Context().String(), tc.wantName) | ||
} | ||
|
||
if tag.Identifier() != tc.wantTag { | ||
t.Errorf("got %v, want %v", tag.Identifier(), tc.wantTag) | ||
} | ||
|
||
if digest != tc.wantDigest { | ||
t.Errorf("got %v, want %v", digest, tc.wantDigest) | ||
} | ||
}) | ||
} | ||
} |
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,19 @@ | ||
{ | ||
"action": "push", | ||
"id": "9a5f8995-dbab-4c2b-b06c-0c29c23e759e", | ||
"request": { | ||
"host": "test.azurecr.io", | ||
"id": "ae93b7e8-7e96-4e21-8487-917d74224d92", | ||
"method": "PUT", | ||
"useragent": "docker/24.0.6 go/go1.20.7 git-commit/1a79695 kernel/5.10.0-25-amd64 os/linux arch/amd64 UpstreamClient(Docker-Client/24.0.6 \\(linux\\))" | ||
}, | ||
"target": { | ||
"digest": "sha256:xxxxd5c8786bb9e621a45ece0dbxxxx1cdc624ad20da9fe62e9d25490f33xxxx", | ||
"length": 524, | ||
"mediaType": "application/vnd.docker.distribution.manifest.v2+json", | ||
"repository": "busybox", | ||
"size": 524, | ||
"tag": "v1" | ||
}, | ||
"timestamp": "2023-10-11T14:45:59.730519823Z" | ||
} |
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,25 @@ | ||
{ | ||
"callback_url": "https://registry.hub.docker.com/u/svendowideit/testhook/hook/2141b5bi5i5b02bec211i4eeih0242eg11000a/", | ||
"push_data": { | ||
"pushed_at": 1417566161, | ||
"pusher": "trustedbuilder", | ||
"tag": "stable" | ||
}, | ||
"repository": { | ||
"comment_count": 0, | ||
"date_created": 1417494799, | ||
"description": "", | ||
"dockerfile": "#\n# BUILD\u0009\u0009docker build -t svendowideit/apt-cacher .\n# RUN\u0009\u0009docker run -d -p 3142:3142 -name apt-cacher-run apt-cacher\n#\n# and then you can run containers with:\n# \u0009\u0009docker run -t -i -rm -e http_proxy http://192.168.1.2:3142/ debian bash\n#\nFROM\u0009\u0009ubuntu\n\n\nVOLUME\u0009\u0009[/var/cache/apt-cacher-ng]\nRUN\u0009\u0009apt-get update ; apt-get install -yq apt-cacher-ng\n\nEXPOSE \u0009\u00093142\nCMD\u0009\u0009chmod 777 /var/cache/apt-cacher-ng ; /etc/init.d/apt-cacher-ng start ; tail -f /var/log/apt-cacher-ng/*\n", | ||
"full_description": "Docker Hub based automated build from a GitHub repo", | ||
"is_official": false, | ||
"is_private": true, | ||
"is_trusted": true, | ||
"name": "testhook", | ||
"namespace": "svendowideit", | ||
"owner": "svendowideit", | ||
"repo_name": "svendowideit/testhook", | ||
"repo_url": "https://registry.hub.docker.com/u/svendowideit/testhook/", | ||
"star_count": 0, | ||
"status": "Active" | ||
} | ||
} |
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,21 @@ | ||
{ | ||
"type": "PUSH_ARTIFACT", | ||
"occur_at": 1680501893, | ||
"operator": "harbor-jobservice", | ||
"event_data": { | ||
"resources": [ | ||
{ | ||
"digest": "sha256:954b378c375d852eb3c63ab88978f640b4348b01c1b3456a024a81536dafbbf4", | ||
"tag": "sha256:954b378c375d852eb3c63ab88978f640b4348b01c1b3456a024a81536dafbbf4", | ||
"resource_url": "localhost/harbor/alpine@sha256:954b378c375d852eb3c63ab88978f640b4348b01c1b3456a024a81536dafbbf4" | ||
} | ||
], | ||
"repository": { | ||
"date_created": 1680501893, | ||
"name": "alpine", | ||
"namespace": "harbor", | ||
"repo_full_name": "harbor/alpine", | ||
"repo_type": "private" | ||
} | ||
} | ||
} |
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 @@ | ||
docker.io/bluebrown/busybox:v1.1@sha256:3b3128d9df6bbbcc92e2358e596c9fbd722a437a62bafbc51607970e9e3b8869 |