Skip to content

Commit

Permalink
test: add test for getTags
Browse files Browse the repository at this point in the history
  • Loading branch information
shivjm committed Nov 7, 2021
1 parent f56d501 commit 26acbc4
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -5,4 +5,5 @@ go 1.16
require (
github.com/asottile/dockerfile v3.1.0+incompatible
github.com/moby/buildkit v0.9.2 // indirect
github.com/stretchr/testify v1.7.0
)
3 changes: 3 additions & 0 deletions go.sum
Expand Up @@ -698,6 +698,7 @@ github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
Expand Down Expand Up @@ -784,6 +785,7 @@ github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+
github.com/nakabonne/nestif v0.3.0/go.mod h1:dI314BppzXjJ4HsCnbo7XzrJHPszZsjnk5wEBSYHI2c=
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96djdrsSGy3AWPyBgZMAGfxZNfgntdJG+11KU4QvbU=
github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
Expand Down Expand Up @@ -1491,6 +1493,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20141024133853-64131543e789/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
Expand Down
29 changes: 29 additions & 0 deletions main_test.go
@@ -0,0 +1,29 @@
package main

import (
"testing"

"github.com/asottile/dockerfile"
"github.com/stretchr/testify/assert"
)

func TestParsing(t *testing.T) {
expected := []Image{
{Name: "golang", Tag: "1.17.0-alpine"},
{Name: "common", Tag: "?"},
{Name: "common", Tag: "?"},
{Name: "common", Tag: "?"},
{Name: "viaductoss/ksops", Tag: "v3.0.0"},
{Name: "quay.io/argoproj/argocd", Tag: "$ARGOCD_VERSION"},
}

commands, err := dockerfile.ParseFile("tests/Dockerfile.1")

if err != nil {
t.Errorf("Could not open Dockerfile.1: %s", err)
}

tags := getTags(commands)

assert.Equal(t, expected, tags)
}
67 changes: 67 additions & 0 deletions tests/Dockerfile.1
@@ -0,0 +1,67 @@
ARG ARGOCD_VERSION

FROM golang:1.17.0-alpine AS common

LABEL go.version="1.17.0"

RUN apk add -q --no-cache git=2.32.0-r0 musl-dev=1.2.2-r3 gcc=10.3.1_git20210424-r2

FROM common AS jb-builder

ARG JSONNET_BUNDLER_COMMIT

WORKDIR /jsonnet-bundler

RUN git init --quiet && \
git remote add origin https://github.com/jsonnet-bundler/jsonnet-bundler.git && \
git fetch -n --depth 1 origin $JSONNET_BUNDLER_COMMIT && \
git reset --hard FETCH_HEAD && \
go build -ldflags='-extldflags=-static -linkmode=external' -o jb /jsonnet-bundler/cmd/jb

FROM common AS go-jsonnet-builder

ARG GOJSONNET_VERSION

RUN go install -ldflags='-extldflags=-static -linkmode=external' github.com/google/go-jsonnet/cmd/jsonnet@$GOJSONNET_VERSION

FROM common AS go-jsontoyaml-builder

ARG GOJSONTOYAML_VERSION

RUN go install -ldflags='-extldflags=-static -linkmode=external' github.com/brancz/gojsontoyaml@$GOJSONTOYAML_VERSION

FROM viaductoss/ksops:v3.0.0 AS ksops-builder

LABEL tools.ksops.version="v3.0.0"

FROM quay.io/argoproj/argocd:$ARGOCD_VERSION

ARG HELM_SECRETS_VERSION

# Switch to root for the ability to perform install
USER root

# Set the kustomize home directory
ENV XDG_CONFIG_HOME=$HOME/.config
ENV KUSTOMIZE_PLUGIN_PATH=$XDG_CONFIG_HOME/kustomize/plugin/

ARG PKG_NAME=ksops

COPY --from=jb-builder /jsonnet-bundler/jb /usr/local/bin/jb

COPY --from=go-jsonnet-builder /go/bin/jsonnet /usr/local/bin/jsonnet

COPY --from=go-jsontoyaml-builder /go/bin/gojsontoyaml /usr/local/bin/gojsontoyaml

# Override the default kustomize executable with the Go built version
COPY --from=ksops-builder /go/bin/kustomize /usr/local/bin/kustomize

# Switch back to non-root user
USER 999

# Copy the plugin to kustomize plugin path
COPY --from=ksops-builder /go/src/github.com/viaduct-ai/kustomize-sops/* $KUSTOMIZE_PLUGIN_PATH/viaduct.ai/v1/${PKG_NAME}/

ENV HELM_SECRETS_SOPS_PATH=$KUSTOMIZE_PLUGIN_PATH/viaduct.ai/v1/${PKG_NAME}/sops

RUN helm plugin install https://github.com/jkroepke/helm-secrets --version $HELM_SECRETS_VERSION

0 comments on commit 26acbc4

Please sign in to comment.