Skip to content

Commit

Permalink
Remove travis tests in favor of github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
rafibarash committed Sep 2, 2021
1 parent cf50795 commit 8879891
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 292 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Expand Up @@ -15,8 +15,9 @@ jobs:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Build
run: go build
run: |
go build
go build -o $(go env GOPATH)/bin/docker-credential-gcr main.go
- name: Vet
run: go vet ./...
- name: Test mac/ubuntu
Expand Down
70 changes: 0 additions & 70 deletions .travis.yml

This file was deleted.

16 changes: 6 additions & 10 deletions CONTRIBUTING.md
Expand Up @@ -23,7 +23,8 @@ Before you submit your pull request consider the following guidelines:
* Run the full test suite.

```shell
make test
go build
go test -timeout 10s -v ./...
```
* Commit your changes using a descriptive commit message.

Expand All @@ -32,12 +33,6 @@ Before you submit your pull request consider the following guidelines:
```
Note: the optional commit `-a` command line option will automatically "add" and "rm" edited files.

* Build your changes locally to ensure all the tests pass:

```shell
make test
```

* Push your branch to GitHub:

```shell
Expand Down Expand Up @@ -96,10 +91,11 @@ After your pull request is merged, you can safely delete your branch and pull th
* Source files must be formatted with `gofmt` and updated with `go fix` before submission.

```shell
make pretty
go fmt
go fix
```
* Source files should be inspected by `go vet` and `golint`. Since there may be false positives with both, ignored warnings require justification but won't necessarily block changes.
* Source files should be inspected by `go vet`. Since there may be false positives with both, ignored warnings require justification but won't necessarily block changes.

```shell
make criticism
go vet
```
66 changes: 0 additions & 66 deletions Makefile

This file was deleted.

10 changes: 5 additions & 5 deletions README.md
@@ -1,6 +1,6 @@
<a href="https://gcr.io"><img src="https://avatars2.githubusercontent.com/u/21046548?s=400&v=4" height="120"/></a>

# docker-credential-gcr [![Build Status](https://travis-ci.org/GoogleCloudPlatform/docker-credential-gcr.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/docker-credential-gcr) [![Go Report Card](https://goreportcard.com/badge/GoogleCloudPlatform/docker-credential-gcr)](https://goreportcard.com/report/GoogleCloudPlatform/docker-credential-gcr)
# docker-credential-gcr [![Build Status](https://github.com/GoogleCloudPlatform/docker-credential-gcr/actions/workflows/test.yml/badge.svg)](https://travis-ci.org/GoogleCloudPlatform/docker-credential-gcr) [![Go Report Card](https://goreportcard.com/badge/GoogleCloudPlatform/docker-credential-gcr)](https://goreportcard.com/report/GoogleCloudPlatform/docker-credential-gcr)

## Introduction

Expand Down Expand Up @@ -52,7 +52,7 @@ As of the 2.0 release, `docker-credential-gcr` no longer supports generalized [`

### Building from Source

The program in this repository is written with the Go programming language and built with `make`. These instructions assume that [**Go 1.11+**](https://golang.org/) and `make` are installed on a \*nix system.
The program in this repository is written with the Go programming language and can be built with `go build`. These instructions assume you are using [**Go 1.13+**](https://golang.org/) or higher.

You can download the source code, compile the binary, and put it in your `$GOPATH` with `go get`.

Expand All @@ -62,17 +62,17 @@ go get -u github.com/GoogleCloudPlatform/docker-credential-gcr

If `$GOPATH/bin` is in your system `$PATH`, this will also automatically install the compiled binary. You can confirm using `which docker-credential-gcr` and continue to the [section on Configuration and Usage](#configuration-and-usage).

Alternatively, you can use `make` to build the program. The executable will be output to the `bin` directory inside the repository.
Alternatively, you can use `go build` to build the program. This creates a `docker-credential-gcr` executable.

```shell
cd $GOPATH/src/github.com/GoogleCloudPlatform/docker-credential-gcr
make
go build
```

Then, you can put that binary in your `$PATH` to make it visible to `docker`. For example, if `/usr/bin` is present in your system path:

```shell
sudo mv ./bin/docker-credential-gcr /usr/bin/docker-credential-gcr
sudo mv ./docker-credential-gcr /usr/bin/docker-credential-gcr
```

## Configuration and Usage
Expand Down
120 changes: 120 additions & 0 deletions test/config_test.go
@@ -1,3 +1,4 @@
//go:build !unit && !gazelle
// +build !unit,!gazelle

// Copyright 2016 Google, Inc.
Expand All @@ -17,10 +18,17 @@
package test

import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"

"github.com/GoogleCloudPlatform/docker-credential-gcr/config"
cliconfig "github.com/docker/cli/cli/config"
"github.com/docker/cli/cli/config/configfile"
)

func TestConfig(t *testing.T) {
Expand Down Expand Up @@ -58,3 +66,115 @@ func TestConfig(t *testing.T) {
t.Fatal("Config file still present.")
}
}

// getDockerConfig returns the docker config.
func getDockerConfig() (*configfile.ConfigFile, error) {
dockerConfig, err := cliconfig.Load(cliconfig.Dir())
if err != nil {
return nil, fmt.Errorf("unable to load docker config: %v", err)
}
return dockerConfig, nil
}

// deleteDockerConfig deletes the docker config.
func deleteDockerConfig() error {
filename := filepath.Join(cliconfig.Dir(), cliconfig.ConfigFileName)

_, err := os.Stat(filename)
if err != nil {
if os.IsNotExist(err) {
return nil
}
return err
}

return os.Remove(filename)
}

func TestConfigureDocker(t *testing.T) {
if err := deleteDockerConfig(); err != nil {
if err != nil {
t.Fatalf("Failed to delete the pre-existing docker config: %v", err)
}
}
dockerConfig, err := getDockerConfig()
if err != nil {
t.Fatalf("Failed to get the docker config: %#v", err)
}

if len(dockerConfig.CredentialHelpers) > 0 {
t.Fatal("Failed to clean the docker config.")
}

// Configure docker.
helper := helperCmd([]string{"configure-docker", "--overwrite"})
var out bytes.Buffer
helper.Stdout = &out
helper.Stderr = os.Stderr
if err = helper.Run(); err != nil {
t.Fatalf("Failed to execute `configure-docker --overwrite`: %v Stdout: %s", err, string(out.Bytes()))
}

dockerConfig, err = getDockerConfig()
if err != nil {
t.Fatalf("Failed to get the docker config: %v", err)
}

if len(dockerConfig.CredentialHelpers) == 0 {
t.Fatal("CredentialHelpers was empty.")
}

for _, registryHostname := range config.DefaultGCRRegistries {
if helperSuffix, ok := dockerConfig.CredentialHelpers[registryHostname]; ok {
if helperSuffix != "gcr" {
t.Errorf("Wanted value for %s in dockerConfig.CredentialHelpers to be %s, got %s", registryHostname, "gcr", helperSuffix)
}
} else {
t.Errorf("Expected %s to be present in dockerConfig.CredentialHelpers: %v", helperSuffix, dockerConfig.CredentialHelpers)
}
}
}

func TestConfigureDocker_NonDefault(t *testing.T) {
if err := deleteDockerConfig(); err != nil {
if err != nil {
t.Fatalf("Failed to delete the pre-existing docker config: %v", err)
}
}
dockerConfig, err := getDockerConfig()
if err != nil {
t.Fatalf("Failed to get the docker config: %#v", err)
}

if len(dockerConfig.CredentialHelpers) > 0 {
t.Fatal("Failed to clean the docker config.")
}

// Configure docker.
helper := helperCmd([]string{"configure-docker", "--overwrite", "--registries=foo.gcr.io, bar.gcr.io, baz.gcr.io"})
var out bytes.Buffer
helper.Stdout = &out
helper.Stderr = os.Stderr
if err = helper.Run(); err != nil {
t.Fatalf("Failed to execute `configure-docker --overwrite`: %v Stdout: %s", err, string(out.Bytes()))
}

dockerConfig, err = getDockerConfig()
if err != nil {
t.Fatalf("Failed to get the docker config: %v", err)
}

if len(dockerConfig.CredentialHelpers) == 0 {
t.Fatal("CredentialHelpers was empty.")
}

for _, registryHostname := range []string{"foo.gcr.io", "bar.gcr.io", "baz.gcr.io"} {
if helperSuffix, ok := dockerConfig.CredentialHelpers[registryHostname]; ok {
if helperSuffix != "gcr" {
t.Errorf("Wanted value for %s in dockerConfig.CredentialHelpers to be %s, got %s", registryHostname, "gcr", helperSuffix)
}
} else {
t.Errorf("Expected %s to be present in dockerConfig.CredentialHelpers: %v", helperSuffix, dockerConfig.CredentialHelpers)
}
}
}

0 comments on commit 8879891

Please sign in to comment.