zabio3/godolint

View on GitHub
linter/rules/dl3003_test.go

Summary

Maintainability
A
0 mins
Test Coverage
package rules

import (
    "testing"
)

func TestValidateDL3003(t *testing.T) {
    cases := []struct {
        dockerfileStr string
        expectedRst   []ValidateResult
        expectedErr   error
    }{
        {
            dockerfileStr: `FROM golang:latest

WORKDIR /go
ADD . /go

RUN cd /usr/src/app && git clone git@github.com:zabio3/godolint.git /usr/src/app

CMD ["go", "run", "main.go"]
`,
            expectedRst: []ValidateResult{
                {line: 6},
            },
            expectedErr: nil,
        },
    }

    for i, tc := range cases {
        rst, err := parseDockerfile(tc.dockerfileStr)
        if err != nil {
            t.Errorf("#%d parse error %s", i, tc.dockerfileStr)
        }

        gotRst, gotErr := validateDL3003(rst.AST)
        if !isValidateResultEq(gotRst, tc.expectedRst) {
            t.Errorf("#%d results deep equal has returned: want %v, got %v", i, tc.expectedRst, gotRst)
        }

        if gotErr != tc.expectedErr {
            t.Errorf("#%d error has returned: want %s, got %s", i, tc.expectedErr, gotErr)
        }
        cleanup(t)
    }
}