Skip to content

Commit

Permalink
Try to remove dependency on GCR creds (#793)
Browse files Browse the repository at this point in the history
  • Loading branch information
imjasonh committed Oct 22, 2020
1 parent 8a28419 commit e4f0bba
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 18 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/knative-go-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright 2020 The Knative Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This file is automagically synced here from github.com/knative-sandbox/.github
# repo by knobots: https://github.com/mattmoor/knobots and will be overwritten.

name: Test

on:

push:
branches: [ 'master' ]

pull_request:
branches: [ 'master', 'release-*' ]

jobs:

test:
name: Unit Tests
strategy:
matrix:
go-version: [1.15.x]
platform: [ubuntu-latest]

runs-on: ${{ matrix.platform }}

steps:

- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
id: go

- name: Check out code
uses: actions/checkout@v2

- name: Check for .codecov.yaml
id: codecov-enabled
uses: andstor/file-existence-action@v1
with:
files: .codecov.yaml

- if: steps.codecov-enabled.outputs.files_exists == 'true'
name: Produce Go Coverage
run: echo 'COVER_OPTS=-coverprofile=coverage.txt -covermode=atomic' >> $GITHUB_ENV

- name: Test
run: go test -race $COVER_OPTS ./...

- if: steps.codecov-enabled.outputs.files_exists == 'true'
name: Codecov
uses: codecov/codecov-action@v1
36 changes: 18 additions & 18 deletions pkg/gcrane/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,28 @@ func mustRepo(s string) name.Repository {
return repo
}

type fakeGCR struct {
type fakeXCR struct {
h http.Handler
repos map[string]google.Tags
t *testing.T
}

func (gcr *fakeGCR) ServeHTTP(w http.ResponseWriter, r *http.Request) {
gcr.t.Logf("%s %s", r.Method, r.URL)
func (xcr *fakeXCR) ServeHTTP(w http.ResponseWriter, r *http.Request) {
xcr.t.Logf("%s %s", r.Method, r.URL)
if strings.HasPrefix(r.URL.Path, "/v2/") && strings.HasSuffix(r.URL.Path, "/tags/list") {
repo := strings.TrimSuffix(strings.TrimPrefix(r.URL.Path, "/v2/"), "/tags/list")
if tags, ok := gcr.repos[repo]; !ok {
if tags, ok := xcr.repos[repo]; !ok {
w.WriteHeader(http.StatusNotFound)
} else {
gcr.t.Logf("%+v", tags)
xcr.t.Logf("%+v", tags)
json.NewEncoder(w).Encode(tags)
}
} else {
gcr.h.ServeHTTP(w, r)
xcr.h.ServeHTTP(w, r)
}
}

func newFakeGCR(stuff map[name.Reference]partial.Describable, t *testing.T) (*fakeGCR, error) {
func newFakeXCR(stuff map[name.Reference]partial.Describable, t *testing.T) (*fakeXCR, error) {
h := registry.New()

repos := make(map[string]google.Tags)
Expand Down Expand Up @@ -129,13 +129,13 @@ func newFakeGCR(stuff map[name.Reference]partial.Describable, t *testing.T) (*fa
repos[repo] = tags
}

return &fakeGCR{h: h, t: t, repos: repos}, nil
return &fakeXCR{h: h, t: t, repos: repos}, nil
}

func TestCopy(t *testing.T) {
logs.Warn.SetOutput(os.Stderr)
src := "gcr.io/test/gcrane"
dst := "gcr.io/test/gcrane/copy"
src := "xcr.io/test/gcrane"
dst := "xcr.io/test/gcrane/copy"

oneTag, err := random.Image(1024, 5)
if err != nil {
Expand Down Expand Up @@ -163,8 +163,8 @@ func TestCopy(t *testing.T) {
noTagsRef := latestRef.Context().Digest(d.String())
fooRef := latestRef.Context().Tag("foo")

// Set up a fake GCR.
h, err := newFakeGCR(map[name.Reference]partial.Describable{
// Set up a fake registry.
h, err := newFakeXCR(map[name.Reference]partial.Describable{
oneTagRef: oneTag,
latestRef: twoTags,
fooRef: twoTags,
Expand All @@ -173,13 +173,13 @@ func TestCopy(t *testing.T) {
if err != nil {
t.Fatal(err)
}
s, err := ggcrtest.NewTLSServer("gcr.io", h)
s, err := ggcrtest.NewTLSServer("xcr.io", h)
if err != nil {
t.Fatal(err)
}
defer s.Close()

// Make sure we don't actually talk to GCR.
// Make sure we don't actually talk to XCR.
http.DefaultTransport = s.Client().Transport

if err := remote.Write(latestRef, twoTags); err != nil {
Expand All @@ -206,15 +206,15 @@ func TestCopy(t *testing.T) {

func TestRename(t *testing.T) {
c := copier{
srcRepo: mustRepo("gcr.io/foo"),
dstRepo: mustRepo("gcr.io/bar"),
srcRepo: mustRepo("xcr.io/foo"),
dstRepo: mustRepo("xcr.io/bar"),
}

got, err := c.rename(mustRepo("gcr.io/foo/sub/repo"))
got, err := c.rename(mustRepo("xcr.io/foo/sub/repo"))
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
want := mustRepo("gcr.io/bar/sub/repo")
want := mustRepo("xcr.io/bar/sub/repo")

if want.String() != got.String() {
t.Errorf("%s != %s", want, got)
Expand Down

0 comments on commit e4f0bba

Please sign in to comment.