mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-24 06:28:13 +01:00
Fix Dockerfile parser (#459)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
74
pkg/dockerfile/client_test.go
Normal file
74
pkg/dockerfile/client_test.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package dockerfile_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/crazy-max/diun/v4/pkg/dockerfile"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var (
|
||||
dc *dockerfile.Client
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
var err error
|
||||
|
||||
dc, err = dockerfile.New(dockerfile.Options{
|
||||
Filename: "./fixtures/valid.Dockerfile",
|
||||
})
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
assert.NotNil(t, dc)
|
||||
}
|
||||
|
||||
func TestLoadFile(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
dfile string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "Failed on non-existing file",
|
||||
dfile: "",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "Fail on empty file",
|
||||
dfile: "./fixtures/empty.Dockerfile",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "Fail on wrong file format",
|
||||
dfile: "./fixtures/invalid.Dockerfile",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "Valid",
|
||||
dfile: "./fixtures/valid.Dockerfile",
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
c, err := dockerfile.New(dockerfile.Options{
|
||||
Filename: tt.dfile,
|
||||
})
|
||||
if tt.wantErr {
|
||||
fmt.Println(err)
|
||||
require.Error(t, err)
|
||||
return
|
||||
}
|
||||
assert.NotNil(t, c)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user